Fix the 4 debugging exercises. 1 // DebugFive1 2 // Adds your lunch bill 3 // Bu
ID: 3684933 • Letter: F
Question
Fix the 4 debugging exercises.
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 }
1 // DebugFive3.java
2 // Determines whether item number on order is valid
3 // Over 999 invalid
4 // Less than 111 Invalid
5 // Valid and less than 500 - Automotive Department
6 // Valid and 500 or higher Housewares Department
7 import java.util.Scanner;
8 public class DebugFive3
9 {
10 public static void main (String args[])
11 {
12 int item;
13 String output;
14 final int LOW = 11111;
15 final int HIGH = 999;
16 final int CUTOFF = 500;
17 Scanner input = new Scanner(System.in);
18 System.out.println("Please enter item number");
19 item = input.nextInt();
20 if(item <= LOW)
21 output = "Item number too low";
22 else
23 if(item => HIGH)
24 output = "Item number too low";
25 else
26 if(item =< HIGH)
27 output > "Valid - in Automotive Department";
28 else
29 output = "Valid - Item in Housewares Department"
30 System.out.println(output);
31 }
32 }
1 // DebugFive4.java
2 // Outputs highest of four numbers
3 import javax.swing.*;
4 public class DebugFive4
5 {
6 public static void main (String args[])
7 {
8 int one, two, three, four;
9 String str, output;
10 str = JOptionPane.showInputDialog(null,"Enter an integer");
11> 12 str = JOptionPane.showInputDialog(null,"Enter an integer");
13 two = Integer.parseInt();
14 str = JOptionPane.showInputDialog(null,"Enter an integer");
15 two = Integer.parseInt();
16 str = JOptionPane.showInputDialog(null,"Enter an integer");
17 four = Integer.parseInt();
18 if(one > two & one >= three && one < four)
19 output = "Highest is " + one;
20 else
21 if(two > one || two > three && two > four)
22 output = "Highest is " + two;
23 else
24 if(three > one && three > two || three == four)
25 output = "Highest is " + three;
26 else
27 output = "Highest is " + three;
28 JOptionPane.showMessageDialog(null, output);
29 }
30 }
Explanation / Answer
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(usersChoiceString);
21 if(usersChoice == 1 || usersChoice == 2)
22 bill = bill + LOW_PRICE;
23 else if(userChoice==3)
24 bill = bill + MED_PRICE;
else
bill = bill+LOW_PRICE;
25
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.nextInt();
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 }
1 // DebugFive3.java
2 // Determines whether item number on order is valid
3 // Over 999 invalid
4 // Less than 111 Invalid
5 // Valid and less than 500 - Automotive Department
6 // Valid and 500 or higher Housewares Department
7 import java.util.Scanner;
8 public class DebugFive3
9 {
10 public static void main (String args[])
11 {
12 int item;
13 String output;
14 final int LOW = 111;
15 final int HIGH = 999;
16 final int CUTOFF = 500;
17 Scanner input = new Scanner(System.in);
18 System.out.println("Please enter item number");
19 item = input.nextInt();
20 if(item <= LOW)
21 output = "Item number too low";
22 else
23 if(item >= HIGH)
24 output = "Item number too low";
25 else
26 if(item <= HIGH)
27 output = "Valid - in Automotive Department";
28 else
29 output = "Valid - Item in Housewares Department"
30 System.out.println(output);
31 }
32 }
1 // DebugFive4.java
2 // Outputs highest of four numbers
3 import javax.swing.*;
4 public class DebugFive4
5 {
6 public static void main (String args[])
7 {
8 int one, two, three, four;
9 String str, output;
10 str = JOptionPane.showInputDialog(null,"Enter an integer");
11> 12 str = JOptionPane.showInputDialog(null,"Enter an integer");
13 two = Integer.parseInt(str);
14 str = JOptionPane.showInputDialog(null,"Enter an integer");
15 two = Integer.parseInt(str);
16 str = JOptionPane.showInputDialog(null,"Enter an integer");
17 four = Integer.parseInt(str);
18 if(one > two & one > three && one > four)
19 output = "Highest is " + one;
20 else
21 if(two > one && two > three && two > four)
22 output = "Highest is " + two;
23 else
24 if(three > one && three > two && three > four)
25 output = "Highest is " + three;
26 else
27 output = "Highest is " + four;
28 JOptionPane.showMessageDialog(null, output);
29 }
30 }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.