-2

as soon as I press enter after typing the expression,it displays result which is calculate grossProfit, Studio and Theater. And now I want that it should wait for me to type "=" and then show the result? can some one help me how to type "=" and then show the result? Thanks

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));
    }
}
ArnonZ
  • 3,822
  • 4
  • 32
  • 42

1 Answers1

0

Just ask user a line before printline like:

do {
    //message for user to add line?
    String nextLine = scan.nextLine();
while (!nextLine.equals("="));
SMA
  • 36,381
  • 8
  • 49
  • 73