Please help me code the following in JAVA! (1) Debug the two programs (DebugMe.j
ID: 3714078 • Letter: P
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) We'll 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 we'll 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.Explanation / Answer
Below is the solution:
Box2.java:
package chegg;
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 chegg;
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.