我被要求计算今天预计将参加比赛的高尔夫俱乐部会员总数(总计乘以小数百分比)并将该总数存储在球员变量中。我不知道怎么存储总数。任何帮助都会很棒。我尝试使用if语句然后键入players = input.nextDouble();
但这不起作用。我对java很新......
class golf
{
private int weather;
private double val1;
private double players;
public void calculations()
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of club members: ");
val1 = input.nextDouble();
System.out.println("Now select a number for the weather"); //weather atm
System.out.println("1: Sunny");
System.out.println("2: Overcast");
System.out.println("3: Rain");
System.out.print("Selection: ");
weather = input.nextInt();
System.out.println(" ");
}
public void output()
{
if (weather == 1) //calculates expected players when Sunny
System.out.println(val1*.25 + " " + "will play golf today!");
if (weather == 2) //calculates expected players when Overcast
System.out.println(val1*.12 + " " + "will play golf today!");
if (weather == 3) //calculates expected players when Rainy
System.out.println(val1*.03 + " " + "will play golf today!");
}
}
答案 0 :(得分:1)
这是你需要的吗?
README