对于这个问题,我非常感谢一些帮助;我对 Java 也很陌生,所以请原谅任何滥用术语/任何其他可能明显的混淆迹象。这是我正在上的一门课。我对此进行了广泛的研究,但没有成功。我已经设计好了我的程序(我花了这么长时间),但我必须找到一种方法让整个事情重复自己,并且基本上允许用户重复程序而不退出无限次。由于我没有整数,我不确定如何使用 while 循环或执行 while 循环。
import java.util.Scanner;
public class Final
{
public static void main(String[] args)
{
System.out.println("Welcome to Class Reunions! This is a program specifically designed to help plan your future reunion party. Simply enter the following information, and we will calculate the cost of your party!");
{
Scanner user_input = new Scanner(System.in);
{
String numberofhours;
System.out.print("Please enter the number of hours for your party: ");
numberofhours = user_input.next();
String numberofguests;
System.out.print("Please enter the number of guests that plan to attend your party: ");
numberofguests = user_input.next();
System.out.println("Please confirm the purchase of our house band: (yes/no): ");
String bandpurchase = user_input.next();
if (bandpurchase.equals("yes"))
bandpurchase = String.valueOf(350);
System.out.println("Thank you!");
if (bandpurchase.equals("no"))
bandpurchase = String.valueOf(0);
int h = (Integer.valueOf(numberofhours) * 200);
int g = (Integer.valueOf(numberofguests) * 40);
int b = (Integer.valueOf(bandpurchase));
int answer = h + g + b;
String totalcost = String.valueOf(answer);
System.out.println("Your expected total cost for the party is: $ " + totalcost);
int p = Integer.valueOf(totalcost) / Integer.valueOf(numberofguests);
String costperson = String.valueOf(p);
System.out.println("The cost per person for the party will be: $ " + costperson);
}
}
}
}
我已经尝试了很多东西,但没有任何效果。我想让整个程序在不退出的情况下重复,并让哨兵值“完成”来停止它。非常感谢!