Question: HI, I am writing a java code that gives the measurement of a box. I have some of the code written but I keep getting

HI, I am writing a java code that gives the measurement of a box. I have some of the code written but I keep getting errors and I am unsure how to finish it.

Some of the requirements for the code are,

  1. The class has four private numbers instance variables L1, W1, H1, and Weight to store the Length, Width, Height, and Weight of the Box. Measurements are in feet and pounds.
  2. This class has two constructors:
    • Constructor #1 - has no parameters and initializes the Box's instance variables to 0
    • Constructor #2 - has four integer parameters that initializes the Box object's L,W,H,Weight
  3. This class has a method calculateVolume( ) which returns the volume (formula: L1*W1*H1) of the Box object as a double.
  4. This class has a method calculateDensity( ) which returns the density of the Box (formula: weight/volume) as a double, check for divide by 0.
  5. This class contains a main( ) method which creates an instance of the Box object with L1=10, W1=5, H1=5, Weight=2600 and computes the Box's Volume and Density, then outputs the results to the user's screen.

Thanks for your help in advance :)

package edu.buffalostate.cis425.sp19.assignments.jeffers;

public class BoxClass { private int h1, l1, w1, weight,volume; public BoxClass() { h1=0; l1=0; w1=0; weight=0; } public BoxClass(int height, int length, int width, int weight) { this.h1= height; this.l1=length; this.w1=width; this.weight = 0; } /** * method to calculate the volume of box * @param args */

public int calculateVolume() { return l1*h1*w1; } /** * method to calculate the density * * * @param args */ public int calculateDensity() { if (volume == 0) { return 0; } return weight/volume; } public int calcualteDensity(int volume) { if (volume ==0) { return 0; } else { return weight / volume; } } public static void main(String[] args) { // TODO Auto-generated method stub int myheight = 5; int mylength = 10; int mywidth = 5; int myweight = 2600; Box2 BoxClass = new Box2(myheight, mylength, mywidth, myweight); System.out.print("A box with height=" + myheight); System.out.print(" and length =" + mylength); System.out.print(" and width =" + mywidth); int volume = mybox.calculateVolume(); System.out.print("Volume = " + volume ); System.out.println("Density = " + mybox.caluculateDensity(volume));

}

} HI, I am writing a java code that gives the measurement ofa box. I have some of the code written but I keep

3 public class BoxClass 4 private int h1, 11, w1, weight,volume; 6 public BoxClass) { h1-0 11-0; W1-0 weight-0 10 12 14 15 16 17 public BoxClass(int height, int length, int width, int weight) { 18 19 20 21 this . h1= height; this.11-length; this.w1-width; this.weight = 0; 23 * method to calculate the volume of box 25 26 27 28 29 public int calculateVolume() { 30 Oparam args return 11*h1*w1; 32 Console Problems Debug Shell BoxClass [Java Application] C:\Program Files Javajdk1.8.0_181\binjavaw.exe (Feb 21, 2019, 7:29:15 AM) Exception in thread "main" java.lang.Error: Unresolved compilation problems: Box2 cannot be resolved to a type Box2 cannot be resolved to a type mybox cannot be resolved mybox cannot be resolved 35 36 37 38 39 40 public int calculateDensity) Oparam args if (volume -- 0 ) { 42 43 return 0; return weight/volume; 45 469 public int calcualteDensity(int volume) { 47 48 49 50 51 52 53 public static void main (String[] args) { if (volume { return 0; else return weight / volume; // TODO Auto-generated method stub int myheight = 5; int mylength-10; int mywidth5; int myweight -2600; 56 57 58 59 60 61 62 63 64 65 Box2 BoxC lass = new Box2(myheight, mylength, mywidth, myweight); System.out.print("A box with height-" + myheight); System.out.print(" and lengthmylength); System.out.print(" and width mywidth); int volume mybox.calculateVolume () 67 68 69 70 71 72 73 74 75 76 System.out.print( "Volumevolume); System.out.println("Density mybox.caluculateDensity (volume))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!