A controlled transaction solution for Joe's Pizza, your friendly neighborhood pizza shop. Joe only make $200 worth of pizza everyday. Modify your program so that if the running total will exceed $200, print a warning and DO NOT add this value to running total. Instead, go to the beginning of loop statement block and wait for next transaction. can you please write it in import java.util.Scanner; and can you make it so i can copy and past it. thank you in advance the code from before /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package personal;import java.util.Scanner;/** * * @author Mabda */public class Personal { /** * @param args the command line arguments */ public static void main(String[] args) { int num, sum = 0; char choice; Scanner key = new Scanner(System.in); while (true) { System.out.print("\nEnter sale amount: "); num = key.nextInt(); sum += num; if(sum>100) { System.out.print("\nTotal sum exceeds more than 100.\n"); } System.out.print("Do you want to continue..: "); choice = key.next().charAt(0); if (choice == 'n') { System.out.print("\nToday's sum of all sales: " + sum + "\n\n"); break; } } } }
A controlled transaction solution for Joe's Pizza, your friendly neighborhood pizza shop.
Joe only make $200 worth of pizza everyday. Modify your program so that if the running total will exceed $200, print a warning and DO NOT add this value to running total. Instead, go to the beginning of loop statement block and wait for next transaction.
can you please write it in import java.util.Scanner;
and can you make it so i can copy and past it. thank you in advance
the code from before
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package personal;import java.util.Scanner;/** * * @author Mabda */public class Personal {
/** * @param args the command line arguments */ public static void main(String[] args) { int num, sum = 0; char choice; Scanner key = new Scanner(System.in); while (true) { System.out.print("\nEnter sale amount: "); num = key.nextInt(); sum += num; if(sum>100) { System.out.print("\nTotal sum exceeds more than 100.\n"); } System.out.print("Do you want to continue..: "); choice = key.next().charAt(0); if (choice == 'n') { System.out.print("\nToday's sum of all sales: " + sum + "\n\n"); break; } } } }
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int sum=0,num;
char choice;
Scanner key=new Scanner(System.in);
while(true)
{
System.out.println("Enter sales amount:");
num = key.nextInt(); //to read sales amount
sum+=num;//to store sales amount
//condition for checking total sales more than 200 or not
if(sum>200)
{
System.out.println("Total sales exceeds more than 200");
sum-=num;// if total sales exceeds 200 for the transaction to minus present transaction
}
System.out.println("Do you want to continue(y/n):");
choice = key.next().charAt(0);//to read character to continue or stop program
if(choice=='n')
{
System.out.println("Today total sum of sales is:"+sum);
break;//to break the loop if user enters n
}
else
{
continue;//to continue to next transaction if user enters y
}
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images