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,
- 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.
- 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
- This class has a method calculateVolume( ) which returns the volume (formula: L1*W1*H1) of the Box object as a double.
- This class has a method calculateDensity( ) which returns the density of the Box (formula: weight/volume) as a double, check for divide by 0.
- 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));
}
}
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 ShellStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started