Question

Please help me code the following in JAVA!

(1) Debug the two programs (DebugMe.java and Box.java) by following the comments and fixing the errors. Note that there are both syntax and logic errors. (2) Well use the graphical debugger built into Eclipse a. Set a breakpoint on the first line in main i. Do this by clicking in the gutter area for Eclipse and Bluel. ii. These appear as blue circles in Eclipse and red stop signs in Blue. b. Click on the Bug rather than the Play button i. This begins your debug session -say yes to change to debug view in eclipse C. Hover over variables to see their values. Working with Debug Flags Using visual debuggers is one methodology used to trace and evaluate execution; next well consider using boolean flags to indicate our software should produce additional reporting output or alter the way in which the program proceeds. For example, consider the code that will only print to the console if the boolean variable DEBUG is set to true.

Box class:

Debugme class:

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

Below is the solution:

Box2.java:

package HomeworkLib;

public class Box2 {
   private static int width;
   private static int depth;
   private static int height, grade,volume;
  
   //class constructor
  
  
   public Box2(int width, int height, int depth, int grade) {
       this.width = width;
       this.height = height;
       this.depth = depth;
       this.grade = grade;
   }
  
   public boolean equals(Box2 b){
       return this.getVolume()==b.getVolume() && this.getGrade() ==b.getGrade();
   }
  
   public Box2 larger(Box2 b){
       if(b.getVolume() > this.getVolume())
           return this;
       return b;
   }

   public static int getGrade() {
       return grade;
   }
   public static int getVolume() {
       return width * height * depth * grade;
   }

   public int getWidth() {
       return width;
   }

   public int getDepth() {
       return depth;
   }

   public static int getHeight() {
       return height;
   }
}

DebugMe.java:

package HomeworkLib;

public class DebugMe {

       public static void main(String args[]){

           printSums(args);
           compareBoxes();
       }

       //This function is designed to print the sums of all numbers between 1 and the
       //first number entered as an argument to DebugMe
       //For example, if you enter: DebugMe 3
       //You should get:
       //   The sum of the first 1 numbers is 1.
       // The sum of the first 2 numbers is 3.
       // The sum of the first 3 numbers is 6.

       public static void printSums(String[] args){
           int count;
           count = Integer.parseInt(args[0]);
           int sum = 0;
           int i;
           for (i = 1 ; i <= count ; i++)
           {
               sum += i;
               System.out.println("The sum of the first " + i + " numbers is " + sum + ".");
           }
       }


       //This function demonstrates the use of the Box class
       //DO NOT change anything in this function
       //use it to test your corrections to the Box class

       //The following is what your output should look like when your
       //Box class is correct.

       //Box 0 is larger than Box 1.
       //Box 0 is equivalent to 2.
       //Box 0 is smaller than Box 3.
       //Box 0 is larger than Box 4.
       //Box 1 is smaller than Box 2.
       //Box 1 is smaller than Box 3.
       //Box 1 is smaller than Box 4.
       //Box 2 is smaller than Box 3.
       //Box 2 is larger than Box 4.
       //Box 3 is larger than Box 4.


       public static void compareBoxes(){

           Box2[] array = new Box2[5];
           array[0] = new Box2(4,5,3,2);
           array[1] = new Box2(2,3,3,1);
           array[2] = new Box2(3,10,2,2);
           array[3] = new Box2(4,4,4,1);
           array[4] = new Box2(5,7,1,1);

           for(int i = 0; i< array.length;i++){
               for(int j=i+1; j< array.length;j++){
                   if(array[i].equals(array[j])){
                       System.out.println("Box " + i + " is equivalent to " + j + ".");
                   }
                   else
                   {
                       //compare box sizes
                       if(array[i].equals(array[i].larger(array[j])))
                       {
                           System.out.println("Box " + i + " is larger than Box " + j + ".");
                       }
                       else
                       {
                           System.out.println("Box " + i + " is smaller than Box " + j + ".");
                       }

                   }

               }
           }
       }
}

Before running the program pass the first argument to 10 and run the program

sample output of the program:

The sum of the first 1 numbers is 1.
The sum of the first 2 numbers is 3.
The sum of the first 3 numbers is 6.
The sum of the first 4 numbers is 10.
The sum of the first 5 numbers is 15.
The sum of the first 6 numbers is 21.
The sum of the first 7 numbers is 28.
The sum of the first 8 numbers is 36.
The sum of the first 9 numbers is 45.
The sum of the first 10 numbers is 55.
Box 0 is equivalent to 1.
Box 0 is equivalent to 2.
Box 0 is equivalent to 3.
Box 0 is equivalent to 4.
Box 1 is equivalent to 2.
Box 1 is equivalent to 3.
Box 1 is equivalent to 4.
Box 2 is equivalent to 3.
Box 2 is equivalent to 4.
Box 3 is equivalent to 4.

Add a comment
Know the answer?
Add Answer to:
Please help me code the following in JAVA! Box class: Debugme class: (1) Debug the two...
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
  • No matter which editor you’re using, there are debugging tools that can help simplify the process...

    No matter which editor you’re using, there are debugging tools that can help simplify the process of hunting down logic errors. In Eclipse and BlueJ, you just need to toggle a breakpoint in the gutter of the text area; this should place a blue circle next to the line of code your debugger will execute up to. Then to debug, instead of play, click on the “little bug” icon next to play. Say yes to the perspective change dialog, and...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • please help me add on this java code to run public class CarHwMain public static void...

    please help me add on this java code to run public class CarHwMain public static void main(String args 1/ Construct two new cars and one used car for the simulation Cari carl = new Car W"My New Mazda", 24.5, 16.0); Car car2 = new Cart My New Ford" 20.5, 15.0) Cari car) - new Cari ("My Used Caddie", 15.5, 16.5, 5.5, 1/ ADD CODE to completely fill the tanks in the new cars and off the used cars ton //...

  • I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...

    I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • IN JAVA PLEASE HELP! ALSO PLEASE ADD COMMENTS Summary Build two classes (Fraction and Fraction Counter)...

    IN JAVA PLEASE HELP! ALSO PLEASE ADD COMMENTS Summary Build two classes (Fraction and Fraction Counter) and a Driver for use in counting the number of unique fractions read from a text file. We'll use the ArrayList class to store our list of unique Fraction Counters. Rather than designing a monolithic chunk of code in main like we did in the previous homework, we'll practice distributing our code into containers (called classes) that you will design specifically to tackle this...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • I need help with the following Java code Consider a class Fraction of fractions. Each fraction...

    I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...

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