java创建客户业务类_java-第十二章-人机猜拳-分析业务,抽象出类,类的属性和方法,创建用户类...

package 上机练习;

import java.util.Scanner;

public class A01class {

String name1;

String name2;

String A = "", B = "";

int count1 = 0, count2 = 0, count3 = 0;

public String A() {

return "\t**************************"

+ "\n\t****    猜拳  , 开始          ****"

+ "\n\t**************************";

}

public void B() {

System.out.println("ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ");

Scanner input = new Scanner(System.in);

System.out.println("出拳规则:1.剪刀 2.石头 3.布");

System.out.print("请选择对方角色(1.刘备 2.孙权 3.曹操):");

int choice = input.nextInt();

System.out.println("请输入您的名字:");

name2 = input.next();

switch (choice) {

case 1:

name1 = "刘备";

break;

case 2:

name1 = "孙权";

break;

case 3:

name1 = "曹操";

break;

default:

System.out.println("输入错误!请重新选择:");

B();

break;

}

}

public void C() {

Scanner input = new Scanner(System.in);

System.out.print("\n要开始吗?(y/n):");

char choice = input.next().charAt(0);

switch (choice) {

case 'y':

D();

break;

case 'n':

System.out.println("欢迎下次使用!");

break;

default:

System.out.println("输入错误!请重新选择:");

A01 TestA01 = new A01();

TestA01.main(null);

break;

}

}

public void D() {

System.out.println("ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ");

Scanner input = new Scanner(System.in);

int random = (int) (Math.random() * 10) % 3 + 1;

System.out.println("请出拳:1.剪刀 2.石头 3.布 (输入相应的数字:)");

int choice = input.nextInt();

switch (choice) {

case 1:

A = "剪刀";

break;

case 2:

A = "石头";

break;

case 3:

A = "布";

break;

default:

System.out.println("输入有误!\n");

D();

break;

}

switch (random) {

case 1:

B = "剪刀";

break;

case 2:

B = "石头";

break;

case 3:

B = "布";

break;

default:

System.out.println("输入有误!\n");

D();

break;

}

System.out.println("您出拳:" + A);

System.out.println(name1 + "出拳:" + B);

if (random == 1 && choice == 1 || random == 2 && choice == 2

|| random == 3 && choice == 3) {

System.out.println("结果:→_←和局,真衰!");

} else if (random == 1 && choice == 2 || random == 2 && choice == 3

|| random == 3 && choice == 1) {

System.out.println("结果:△_△,您赢了,有点不服,再来啊 !");

count1++;

} else {

System.out.println("结果:^_^,你输了,真笨!呵呵!");

count2++;

}

count3++;

System.out.print("是否进入下一轮(y/n):");

char choice1 = input.next().charAt(0);

switch (choice1) {

case 'y':

D();

break;

case 'n':

E();

break;

default:

System.out.println("输入错误!");

break;

}

System.out.println("ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ");

}

public void E() {

System.out.println("ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ");

System.out.println(name2 + "  vs  " + name1 + " 对战");

System.out.println("对战次数:" + count3);

System.out.println("\n姓名\t得分");

System.out.println(name2 + "\t" + count1 + "\n" + name1 + "\t" + count2);

if (count1 

System.out.println("\n结果:^_^呵呵,笨笨,下次加油哦");

} else if (count1 > count2) {

System.out.println("结果:→_←,您赢了,有点不服,再来啊 !");

} else {

System.out.println("打成平手,下次在分搞下!");

}

}

}

package 上机练习;

import java.util.Scanner;

public class A01 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner (System.in);

A01class A01 = new A01class();

System.out.println(A01.A());

A01.B();

System.out.println(A01.name2+"  vs  "+A01.name1+" 对战");

A01.C();

}

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值