输入表达式后按Enter键,显示计算grossProfit,Studio和Theater的结果。现在我想它应该等我输入“=”然后显示结果?有人可以帮我如何键入“=”然后显示结果?谢谢
package ticket;
import java.util.Scanner;
import java.text.NumberFormat;
public class Ticket {
public static void main(String[] args) {
//----------------------------------------------
//calculate grossProfit, Studio and Theater.
//------------------------------------------------
final double TICKETPRICE=8, PROFITERATE=.25;
int numberofticket;
double grossProfit,theater,studio;
String replace;
String name = "name";
NumberFormat fmtCur = NumberFormat.getCurrencyInstance();
NumberFormat fmtPct = NumberFormat.getPercentInstance();
Scanner scan = new Scanner(System.in);
System.out.print("Enter movie name:");
name = scan.nextLine();
System.out.print("Enter tickets....");
numberofticket= scan.nextInt();
replace = name.replace ('a', 'A');
grossProfit = TICKETPRICE * numberofticket;
theater = grossProfit * PROFITERATE;
studio = grossProfit - theater;
System.out.println("Box Office Report");
System.out.println("Movie Name =" + replace);
System.out.println("Tickets =" + numberofticket);
System.out.println("TICKETPRICE =" +fmtCur.format(TICKETPRICE));
System.out.println ("grossProfit= " + fmtCur.format(grossProfit));
System.out.println ("theater = " + fmtCur.format(theater) + " at " + fmtPct.format(PROFITERATE));
System.out.println ("studio = " + fmtCur.format(studio));
}
}
答案 0 :(得分:0)
只需在打印行之前询问用户一行:
do {
//message for user to add line?
String nextLine = scan.nextLine();
while (!nextLine.equals("="));