我如何编码以下文件 [英] How do I code the following file

查看:60
本文介绍了我如何编码以下文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。定义Rock,Paper,Scissor的常量。常量使用final关键字,它们的标识符都是大写字母。在main()方法之前定义常量(在方法之外 - 不能在方法中定义静态)。

final static int SISSOR = 0;



2.提示用户自行选择。

输入sissor (0),rock(1),paper(2)



3.为计算机生成随机选择(注意:如何对int进行类型转换?)

使用Math.random()* range



4.使用switch语句为计算机和用户选择生成字符串。 />
开关(compChoice){

案例PAPER:System.out.print(电脑是纸,);

break;

案例ROCK:System.out.print(计算机是摇滚,);

休息;

案例SISSOR:System.out.print( 电脑是傻瓜,);

休息;

}



switch(userChoice){/ / todo ...





5.使用选择(if - else if - else)语句来确定它是平局还是赢家。



6.显示结果。

计算机是纸,用户是sissor,你赢了。



7.测试你的结果。验证是否生成了用户和计算机的所有可能选项。





您的输出应如下所示(3次单独运行):

1. Define constants for Rock, Paper, Scissor. Constants use the final keyword and their identifiers are all captial letters. Define your constants before the main() method (outside of the method – cannot define static within a method).
final static int SISSOR = 0;

2. Prompt the User for their choice.
Enter sissor (0), rock (1), paper (2)

3. Generate a random choice for the computer (note: how do you typecast to int?)
Use Math.random() * range

4. Use switch statements to generate Strings for both the computer and the user’s choice.
switch (compChoice) {
case PAPER: System.out.print("The computer is paper,");
break;
case ROCK: System.out.print("The computer is rock,");
break;
case SISSOR: System.out.print("The computer is sissor,");
break;
}

switch (userChoice) { //todo…


5. Use selection (if – else if – else ) statements to determine it’s a draw or there is a winner.

6. Display the results.
The computer is paper,the user is sissor, You win.

7. Test your results. Verify all possible choices for the User and Computer are generated.


Your output should look like the following ( 3 separate runs ):

推荐答案

我们不做你的HomeWork。家庭工作是为了检查你是否理解你所教的内容。你是必须要做的人。



所以开始工作或告诉老师你不明白的事情。



如果您对已完成的工作有疑问,请回来。
We do not do your HomeWork. homeWork is done to check that you understand what you have been teach. You are the one that have to do it.

So start working or tell your teacher what you don't understand.

Comeback if you have a problem on the work you have done.


这篇关于我如何编码以下文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆