「跳舞java」跳舞jam

博主:adminadmin 2023-01-04 00:27:07 1003

本篇文章给大家谈谈跳舞java,以及跳舞jam对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求一个Java小程序可运行,包含两种以上的设计模式,随便什么设计模式都行

public class ManFactory {

/* 以下是单例模式的使用,外部需要使用该类时只能实例化一个对象*/

private static ManFactory mf = new ManFactory();

private static ListMan allMan = new ArrayListManFactory.Man();

private ManFactory(){}

public static ManFactory instance(){

return mf;

}

/*这里是简单工厂模式的使用,当需要一个人的时候,直接调用工厂类的造人方法, 而不用去新建一个人*/

public Man makeMan(String name){

Man man = new Man();

man.setName(name);

allMan.add(man);//将造出来的人放入工厂的一个集合中,当以后需要这群人统一做事的时候,可以直接获取到

return man;

}

public static ListMan getAllMan() {

return allMan;

}

class Man{

private String name;

public void dancing(){

System.out.println(name +"正在跳舞");

}

public void setName(String name) {

this.name = name;

}

}

public static void main(String[] args) {

/*使用了单例模式,看上去是构建了两个工厂,其实用的还是一个*/

ManFactory fc = ManFactory.instance();

ManFactory fc2 = ManFactory.instance();

fc.makeMan("小明");

fc.makeMan("小红");

fc2.makeMan("小杨");

fc2.makeMan("小张");

for(Man man:ManFactory.getAllMan()){

man.dancing();

}

}

}

请用java语言设计程序实现:假设舞会上男女生各自一排,每次排头牵手跳舞

6 5 1 2 结果才是6;男排 女排 男序号 女序号

。。。。。。。。。。。。。。。。。。。。。。。。。

package net;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("请输入男排人数:");

int boyArray = sc.nextInt();

System.out.println("请输入女排人数:");

int girlArray = sc.nextInt();

System.out.println("请输入男生序号:");

int boy = sc.nextInt();

System.out.println("请输入女生序号:");

int girl = sc.nextInt();

int count=0;

for(int i=1;i=boyArray*girlArray;i++){

if(iboyArray||igirlArray){

if(i==boyi==girl){

count=i;

System.out.println("该对男女第一次牵手跳舞的序号是a:"+i);

break;

}

}

else if((i%boyArray==boy)(i%girlArray==girl)){

count=i;

System.out.println("该对男女第一次牵手跳舞的序号是:"+i);

break;

}

}

if(count==0){

System.out.println("该对男女不可能一起跳舞!");

}

}

}

数据结构中的舞伴问题。用JAVA实现

/**

假设在周末舞会上,男士们(m人)和女士们(n人)进入舞厅时,各自排成一队。跳舞开始时,依次从男队和女队的队头上各出一人配成舞伴。若两队初始人数不相同,则较长的那一队中未配对者等待下一轮舞曲。现要求写一算法模拟上述舞伴配对问题。并m和n存在什么条件时,第x个(1 =x =m)男生才有可能和他心仪的第y个(1 =x =n)女生跳舞,在第几首曲子时?

*/

import java.util.ArrayList;

import java.util.List;

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Dance{

private List String boy=new ArrayList String();

private List String girl=new ArrayList String();

public Dance(int m,int n){

init(m,n);

}

public void init(int m,int n){

for(int i=0;i m;i++){

boy.add("man"+i);

}

for(int i=0;i n;i++){

girl.add("girl"+i);

}

}

public int getMin(){

return Math.min(boy.size(),girl.size());

}

public void go(){

String b="man1";

String g="girl2";

int count=0;

int i=0;

boolean bool=true;

while(bool){

if(i%getMin()==0)

System.out.println("第"+(++count)+"次:");

boolean bGirl=girl.get(i%girl.size()).equals(g);

boolean bBoy=boy.get(i%boy.size()).equals(b);

bool=!(bGirlbBoy);

System.out.println((boy.get((i)%boy.size())).toString());

System.out.println((girl.get((i)%girl.size())).toString());

i++;

}

System.out.println(b+"要在"+count+"首歌中才可以和"+g+"一起Dancing");

}

public static void main(String [] args)throws Exception{

int m;

int n;

System.out.println("请输入男士人数:");

m=input();

System.out.println("请输入女士人数:");

n=input();

Dance dance=new Dance(m,n);

dance.go();

}

public static int input()throws Exception{

int returnNum=0;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String line=br.readLine();

while(!line.equalsIgnoreCase("exit")){

try{

returnNum=new Integer(line);

if(returnNum 0) throw new Exception();

break;

}catch(Exception e){

System.out.println("输入数据有误!请重新输入,退出请按exit");

line=br.readLine();

}

}

return returnNum;

}

}

Java数据结构跳舞配对问题(队列的应用)

代码如下,可以直接运行。

public static void main(String[] args) {

final int M = 6; // number of girls,可改动

final int N = 7; // number of boys,可改动

int x = 3;// some boy,可改动

int y = 5;// some girl,可改动

String result = "";// 记录结果,即第二个问题

// 初始化,假设队列存放男女生编号,从1开始

QueueInteger boys = new LinkedListInteger();

for (int i = 1; i = N; i++) {

boys.add(i);

}

QueueInteger girls = new LinkedListInteger();

for (int i = 1; i = M; i++) {

girls.add(i);

}

// 跳舞开始

int min = boys.size() girls.size() ? girls.size() : boys.size();

int k = 1;// songs

int count = 2; // 求出两个值,可改动

while (k 1000) {//为了不死循环,这里假设最多有999支舞蹈

System.out.println("***This is the " + k + "st dance:");

for (int i = 0; i min; i++) {

// 跳舞,第一个问题:输出每曲配对情况

System.out.println("Boy " + boys.peek() + " = Girl "

+ girls.peek());

// 跳过的排到对尾

int boy = boys.remove();

boys.add(boy);

int girl = girls.remove();

girls.add(girl);

// 判断 x和y跳舞了没有

if (boy == x girl == y) {

result += k + ",";

count--;

}

}

if (count == 0)

break;

// next dance

k++;

}

// 结果

if (count == 0)

System.out.println("\n***Boy " + x + " and Girl " + y

+ " dance together in : " + result);//第二个问题的解答,跳了哪几支舞

else

System.out.println("\n***Boy " + x + " and Girl " + y

+ " have no chance to dance!");//第二个问题的解答,两人没机会跳舞

}

java 关于子类怎么添加自己新的属性?

abstract class Person {

String name;

int age;

String professional;

Person(String name,int age,String professional) {

this.name= name;

this.age = age;

this.professional=professional;

}

public abstract void display();

}

class Students extends Person {

int year;

Students(String n,int a,String p,int year) {

super(n,a,p);

this.year=year;

}

public void display() {

System.out.println("我的姓名="+ name + " " + "我的年龄="+age +" " +"我的专业="+professional+"我的出生年为"+year);

}

}

public class Test5 {

public static void main(String[] args) {

Person p = new Students("男",19,"美术");

Person o = new Students("女",14,"跳舞");

p.display();

o.display();

}

}

Java编程 设计一个图形用户界面。界面包括三个单选按钮、两个复选框、一个列表、一个文本区和一个按

程序如下:

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JTextArea;

public class JFrameDemo extends JFrame implements ActionListener

{

private JPanel panel;

private JButton button;

private JTextArea textArea;

private JCheckBox musicBox;

private JCheckBox danceBox;

private JRadioButton hanButton;

private JRadioButton manButton;

private JRadioButton huiButton;

private ButtonGroup buttonGroup;

public JFrameDemo()

{

panel = new JPanel();

button = new JButton("确定");

textArea = new JTextArea(40,30);

musicBox = new JCheckBox("唱歌");

danceBox = new JCheckBox("跳舞");

huiButton = new JRadioButton("回族");

hanButton = new JRadioButton("汉族");

manButton = new JRadioButton("满族");

buttonGroup = new ButtonGroup();

buttonGroup.add(huiButton);

buttonGroup.add(hanButton);

buttonGroup.add(manButton);

panel.setLayout(new FlowLayout(3));

panel.add(huiButton);

panel.add(hanButton);

panel.add(manButton);

panel.add(musicBox);

panel.add(danceBox);

panel.add(button);

panel.add(textArea);

add(panel);

setTitle("选择兴趣爱好");

setBounds(100, 100, 400, 280);

setResizable(false);

setVisible(true);

this.button.addActionListener(this);

}

public static void main(String[] args)

{

new JFrameDemo();

}

@Override

public void actionPerformed(ActionEvent e)

{

if(e.getSource() == this.button)

{

String info = "";

if(this.huiButton.isSelected())

{

info += this.huiButton.getText() + "\n";

}

if(this.hanButton.isSelected())

{

info += this.hanButton.getText() + "\n";

}

if(this.manButton.isSelected())

{

info += this.manButton.getText() + "\n";

}

if(this.danceBox.isSelected())

{

info += this.danceBox.getText() + "\n";

}

if(this.musicBox.isSelected())

{

info += this.musicBox.getText() + "\n";

}

this.textArea.setText(info);

}

}

}

有问题欢迎提问,满意请采纳,谢谢!

关于跳舞java和跳舞jam的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。