Java prog... public static void main(String[] args) { int aLength = 0; int aWidt
ID: 3628457 • Letter: J
Question
Java prog...
public static void main(String[] args)
{
int aLength = 0;
int aWidth = 0;
int aHeight = 0;
int aVolume = 0;
Scanner aNumberInput = new Scanner(System.in);
System.out.println("-------------------------------------------");
System.out.println("Calculates volume of box and"
+"amount of material, peanuts.");
System.out.println("-------------------------------------------");
System.out.println("");
System.out.println("VOLUME OF MATERIAL IS IN CUBIC INCHES.");
System.out.println("ALL OTHER MEASUREMENTS ARE IN INCHES.");
System.out.println("-------------------------------------------");
// Measurements of box
System.out.print("Please enter the length of the box:");
aLength = aNumberInput.nextInt();
System.out.print("Please enter the width of the box:");
aWidth = aNumberInput.nextInt();
System.out.print("Please enter the height of the box:");
aHeight = aNumberInput.nextInt();
System.out.println("");
//Volume of material
System.out.print("Please enter the volume of the materials:");
aVolume = aNumberInput.nextInt();
System.out.println("");
double bMaterial = (2 * aLength * aWidth + 2 * aHeight * aWidth
+ 2 * aHeight * aLength);
double bVolume = (aLength * aWidth * aHeight);
double bPeanuts = (bVolume - bMaterial);
if (bVolume < bMaterial) {
System.out.print("The gift is too large for the box.");
}
else {
System.out.println("The amount of material needed for the box is "
+ bMaterial + " square inches.");
System.out.println("The volume of the box is "
+ bVolume + " cubic inches.");
System.out.println("The box will need "
+ bPeanuts + " cubic inches of "peanuts".");
}
}
}
Explanation / Answer
if (aVolume > bVolume) { System.out.print("The gift is too large for the box."); } else { System.out.println("The amount of material needed for the box is " + bMaterial + " square inches."); System.out.println("... }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.