Question: FOR JAVA (DEBUG) Please debug the following: ===================================================================== //a program using StringBuilder and a variety of string methods to order from a menu //contains 4

FOR JAVA (DEBUG)

Please debug the following:

===================================================================== //a program using StringBuilder and a variety of string methods to order from a menu //contains 4 bugs. import java.util.Scanner ; public class debug4 { public static void main ( String [ ] args ) { double hamburgerPrice = 2.95 ; double cheeseburgerPrice = 3.45 ; double friesPrice = 1.95 ; double sodaPrice = 1.25 ; double totalPrice ; String item ; int hamburgerQty = 0, cheeseburgerQty = 0, friesQty = 0, sodaQty = 0, qty ; boolean redoOrder = true ; Scanner input = new Scanner ( System. in ) ; System. out. println ( "Hi welcome to Java Burger. " ) ; System. out. println ( "Please type in the names and quantity of items " + "you would like to order followed by a ^ and then press enter. " ) ; System. out. println ( "(limit of 9 items of each type per order)" ) ; System. out. println ( "Example input: \"Cheeseburger4^Fries8^Soda3^\"" ) ; System. out. println ( " Menu" ) ; System. out. print ( "---------------------------" ) ; System. out. printf ( " Hamburger $%.2f",hamburgerPrice ) ; System. out. printf ( " Cheeseburger $%.2f",cheeseburgerPrice ) ; System. out. printf ( " Fries $%.2f",friesPrice ) ; System. out. printf ( " Soda $%.2f ",sodaPrice ) ; StringBuilder order = StringBuilder (nextLine ( ) ) ; while (redoOrder == true ) { //the following for loop is some messy code for parsing the String Builder //no intended bugs in the for loop or switch statement! int j = 0 ; for ( int i = 0 ; i 0 ) System. out. println ( "Hamburger " +hamburgerQty + " * " +hamburgerPrice ) ; if (cheeseburgerQty > 0 ) System. out. println ( "Cheeseburger " +cheeseburgerQty + " * " +cheeseburgerPrice ) ; if (friesQty > 0 ) System. out. println ( "Fries " +friesQty + " * " +friesPrice ) ; if (sodaQty > 0 ) System. out. println ( "Soda " +sodaQty + " * " +sodaPrice ) ; System. out. println ( "------------------------" ) ; totalPrice = hamburgerQty *hamburgerPrice + cheeseburgerQty *cheeseburgerPrice + friesQty *friesPrice + sodaQty *sodaPrice ; System. out. printf ( "Total: $%.2f",totalPrice ) ; System. out. println ( " Is your order correct?(y/n)" ) ; String confirm =input. nextLine ( ). charAt ( 0 ) ; if (confirm == 'n' ) { System. out. println ( "Please reenter your order: " ) ; order. replace ( 0, length ( ), input. nextLine ( ) ) ; hamburgerQty = 0 ; cheeseburgerQty = 0 ; friesQty = 0 ; sodaQty = 0 ; } else if (confirm == 'y' ) { redoOrder = false ; System. out. println ( "bye" ) ; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!