Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

2. Identify five movie characters who embody the renegade cop type.

Answered: 1 week ago