Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fix the 2 debugging exercies 1 // DebugFive1 2 // Adds your lunch bill 3 // Burg

ID: 3685224 • Letter: F

Question

Fix the 2 debugging exercies

1 // DebugFive1
2 // Adds your lunch bill
3 // Burger and hot dog are $2.59
4 // Grilled cheese and fish are $1.99
5 // Fries are 89 cents
6 import javax.swing.*;
7 public class DebugFive1
8 {
9 public static void main(String args[]) throws Exception
10 {
11 final double HIGH_PRICE = 2.59;
12 final double MED_PRICE = 1.99;
13 final double LOW_PRICE = 0.89;
14 String usersChoiceString;
15 int usersChoice;
16 double bill = 0.0;
17 usersChoiceString = JOptionPane.showInputDialog(null,
18 "Order please 1 - Burger 2 - Hotdog" +
19 " 3 - Grilled cheese 4 - Fish sandwich");
20 usersChoice= Integer.parseInt(usersChoice);
21 if(usersChoice == 1 && usersChoice == 2)
22 bill = bill + LOW_PRICE;
23 else
24 bill = bill - MED_PRICE;
25 usersChoiceString = JOptionPane.showInputDialog(null,
26 "Fries with that? 1 - Yes 2 - No");
27 usersChoice = Integer.parse(usersChoiceString);
28 if (usersChoice == 1);
29 bill = bill + LOW_PRICE;
30 JOptionPane.showMessageDialog(null,"Bill is " + bill);
31 }
32 }

1 // Decides if two numbers are evenly divisible
2 import java.util.Scanner;
3 public class DebugFive2
4 {
5 public static void main(String args[])
6 {
7 int num;
8 int num2;
9 Scanner input = new Scanner(System.in);
10 System.out.print("Enter a number ");
11 num = input.next();
12 System.out.print("Enter another number ");
13 num2 = input.nextInt();
14 if((num / num2 = 0) && (num2 / num) = 0)
15 System.out.println("One of these numbers is evenly divisible into the other");
16 else
17 System.out.println(Neither of these numbers is evenly divisible into the other);
18 }
19
20 }

Explanation / Answer

solution for question 1

import javax.swing.*;
public class DebugFive1
{
public static void main(String args[]) throws Exception
{
final double HIGH_PRICE = 2.59;
final double MED_PRICE = 1.99;
final double LOW_PRICE = 0.89;

String usersChoiceString;
int usersChoice;
double bill = 0.0;
usersChoiceString = JOptionPane.showInputDialog(null,
"Order please 1 - Burger 2 - Hotdog" +
" 3 - Grilled cheese 4 - Fish sandwich");

//String usersChoiceString should be converted into integer by using wrapper class

usersChoice= Integer.parseInt(usersChoiceString);

// Burger and hot dog are $2.59 both are having same cost
//if userchoice 1 or 2 we get same cost to add bill

if(usersChoice == 1 || usersChoice == 2)
   // here burger and hot dog cost $2.59 intialized with HIGH_PRICE so that shold be add to bill
bill = bill + HIGH_PRICE;
else
   //MED_PRICE should be added to bill,not subtraction
bill = bill + MED_PRICE;
usersChoiceString = JOptionPane.showInputDialog(null,
"Fries with that? 1 - Yes 2 - No");

usersChoice = Integer.parseInt(usersChoiceString);
//if shold not be ends with semicolon(;) userchoice is 1 then only the next statement is execute
if (usersChoice == 1)
     
bill = bill + LOW_PRICE;
     
JOptionPane.showMessageDialog(null,"Bill is " + bill);
}
}

solution for question2

import java.util.Scanner;
public class DebugFive2
{
public static void main(String args[])
{
int num;
int num2;
Scanner input = new Scanner(System.in);
System.out.print("Enter a number ");
// number should be integer formate
num = input.nextInt();
System.out.print("Enter another number ");
num2 = input.nextInt();
//remainder should be zero for evenly devisible numbers
// one of the number so you should use or condition
if((num % num2 == 0) || (num2 % num == 0))
System.out.println("One of these numbers is evenly divisible into the other");
else
   // string should enclosed with " "
System.out.println("Neither of these numbers is evenly divisible into the other");
     
}
}