Question

Question 6: Identify errors and correct them of the following Java program: 1.           import java.swing.*; 2.          ...

Question 6: Identify errors and correct them of the following Java program:

1.           import java.swing.*;

2.           import java.awt.;

3.           public class ToppingPanel extends Panel

4.           {

5.           public final double CREAM_CHEESE = 0.50;

6.           public final double BUTTER = 0.25;

7.           public final double PEACH_JELLY = 0.75;

8.           public final double BLUEBERRY_JAM = 0.75;

9.           private JCheckBox creamCheese;

10.     private JCheckBox butter;     

11.     private JCheckBox peachJelly;

12.     private JCheckBox blueberryJam;

13.       public ToppingPanel()

14.       {

15.       setLayout new GridLayout(4, 1));

16.       creamCheese = new JCheckBox("Cream cheese");

17.       butter = new JCheckBox("Butter");

18.       peachJelly = new JCheckBox("Peach jelly");

19.       blueberryJam = new JCheckBox("Blueberry jam");

20.       setBorder(BorderFactory.createTitledBorder("Toppings"));

21.       add(creamCheese);

22.       add(butter);

23.       add(peachJelly);

24.       add(blueberryJam);

25.       }

26.       public double getToppingCost()

27.       {

28.       double toppingCost = 0;

29.       if (creamCheese.isSelected())

30.       toppingCost += CREAM_CHEESE;

31.       if (butter.isSelected())

32.       toppingCost += BUTTER;

33.       if (peachJelly.isSelected())

34.       toppingCost += PEACH_JELLY;

35.       if (blueberryJam.isSelected())

36.       toppingCost += BLUEBERRY_JAM;

37.       return toppingCost;

38.      

39.     }

One error is already identified for you as shown below:

Line Number: 2

Error description: Missing *

Statement after correction: import java.awt.*;

Identify 5 other errors and give their Line Number, Error description and Statement after correction.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

There are 4 more errors in the code, not 5. Total including the one you listed is 5. These are listed below in the order of line numbers.

Line Number: 1

Error description: incorrect import (java instead of javax)

Statement after correction: import javax.swing.*;

Line Number: 2

Error description: Missing *

Statement after correction: import java.awt.*;

Line Number: 3

Error description: incorrect super class name (Panel instead of JPanel)

Statement after correction: public class ToppingPanel extends JPanel

Note: Though there is a super class named Panel exist, it is from awt package, so we cannot use some swing utilities like setting border (line 20). There is no setBorder() method defined in Panel, but it’s there in JPanel.

Line Number: 15

Error description: Missing ( after setLayout

Statement after correction: setLayout(new GridLayout(4, 1));

Line Number: 38

Error description: Missing }

Statement after correction: }

After fixing all these 5 errors, the code will compile successfully with no syntax errors. Though there’s more code to be added in order to implement full functionality of the program, it cannot be called errors. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Add a comment
Know the answer?
Add Answer to:
Question 6: Identify errors and correct them of the following Java program: 1.           import java.swing.*; 2.          ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • Convert the following GUI application into an Applet. Do not delete any part of the GUI...

    Convert the following GUI application into an Applet. Do not delete any part of the GUI program, just comment out the part of the program not required. Another Java code is required // Java code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PizzaShopping extends JFrame { JCheckBox ckb[]; JLabel jlb1; JRadioButton radio[], radio1[]; static String[] pizzaToppings = "Tomato,Green peppper,Black olives,Mushrooms,Extra cheese,Pepproni,Sausage" .split(","); static String[] pizzaSizes = "Small: $6.50, Medium: $8.50, Large: $10".split(","); static String[] pizzatypes = "Thin Crust, Mediam...

  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo {    public static void main (String args[])    {       Scanner kb = new Scanner(System.in);       int num1, num2;             System.out.print("Enter an integer >> ");       num1 = kb.nextInt();       System.out.print("Enter another integer >> ");       num2 = kb.nextDouble();       displayTwiceTheNumber(num1);       displayNumberPlusFive(num1);       displayNumberSquared(num1)       displayTwiceTheNumber(num2);       displayNumberPlusFive(num2);       displayNumberSquared(num2);    }   ...

  • /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate...

    /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate * a course average and a letter grade. In order to calculate * the average and the letter grade, a GradeCalculator must store * two essential pieces of data: the number of grades and the sum * of the grades. Therefore these are declared as object properties * (instance variables). * Each time calcAverage (grade) is called, a new grade is added to *...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** *...

    JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** * Write a description of class UniversityTester here. * * @author (your name) * @version (a version number or a date) */ public class ClassroomTester { public static void main(String[] args) { ArrayList<Double> grades1 = new ArrayList<>(); grades1.add(82.0); grades1.add(91.5); grades1.add(85.0); Student student1 = new Student("Srivani", grades1); ArrayList<Double> grades2 = new ArrayList<>(); grades2.add(95.0); grades2.add(87.0); grades2.add(99.0); grades2.add(100.0); Student student2 = new Student("Carlos", grades2); ArrayList<Double> grades3 = new...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • Growing Plant program following guidelines Drawing Canvas Code: import java.awt.Canvas; import java.awt.*; import java.awt.geom.*; /** *...

    Growing Plant program following guidelines Drawing Canvas Code: import java.awt.Canvas; import java.awt.*; import java.awt.geom.*; /** * */ /** */ public class DrawingCanvas extends Canvas { protected String drawString; protected double angleIncrement; DrawingCanvas() { this.setPreferredSize(new Dimension(400, 400)); } public void setDrawString(String s) { drawString = s; } public void setAngleIncrement(double d) { angleIncrement = Math.PI * d/ 180.0; } /** * Paint routine for our canvas. The upper Left hand corner * is 0, 0 and the lower right hand corner...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • Taking this program how can the requirements under it be added in java? import java.util.Scanner; public...

    Taking this program how can the requirements under it be added in java? import java.util.Scanner; public class RetirementSavings {    private static final int MAX_SALARY = 300000;    private static final double MAX_SAVING_RATE = 0.3;    private static final double MAX_INTEREST_RATE = 0.2;    private static final int MAX_YEAR_EMPLOYED = 40;    public static void main(String[] args) {        double savings_rate, interest_rate;        int salary, years_employed;        String name = ""; // name is initialized with an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT