Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is the question. here is my code: import javax.swing.*; class Box{ // data of length, width, and height private float length; private float width;

this is the question.

image text in transcribed

here is my code:

import javax.swing.*;

class Box{

// data of length, width, and height private float length; private float width; private float height;

public Box() {

}

public Box(float dim){ length = dim; width = dim; height = dim; }

public Box(float length, float width, float height) { this.length = length; this.width = width; this.height = height; }

// Formula to get the volume public float calcVolume(){ return length * width * height; }

// Formula use to count the surface of the area public float calcSurfaceArea(){ return 2 * (length * width + width * height + height * length); }

// To count the multiplier public void makeLarger(float multiplier){ length *= multiplier; width *= multiplier; height *= multiplier; }

// to get the larger area public void makeLarger(float lengthOffset, float widthOffset, float heightOffset){ length += lengthOffset; width += widthOffset; height += heightOffset; }

// To show the output of the dimensions public void outputDimensions(){ JOptionPane.showMessageDialog(null, "Dimensions Are: Length : " + String.format("%.2f", length) + " width : " + String.format("%.2f", width) + " Height : " + String.format("%.2f", height)); }

// Prompt user to typr the lenght, width, and the height of the box. public static void main(String[] args){ float length = Float.parseFloat(JOptionPane.showInputDialog("Enter Length")); float width = Float.parseFloat(JOptionPane.showInputDialog("Enter width")); float height = Float.parseFloat(JOptionPane.showInputDialog("Enter Height"));

Box box = new Box(length, width, height); box.outputDimensions(); // Show output of volume of the box. JOptionPane.showMessageDialog(null, "Volume of the box is: " + String.format("%.2f", box.calcVolume())); // Show output of the surface of the area. JOptionPane.showMessageDialog(null, "Surface Area of the box is: " + String.format("%.2f", box.calcSurfaceArea())); } }

PROBLEM:

i need the default constructor and need to have more in the demo program to show everything works.

PLEASE HELP.

The program should be able to create (instantiate) three types of boxes. The first box would use the default constructor. The second box would be a cube and only need one parameter. The third box would be a rectangular solid and you will send in three parameters to the constructor You should be able to perform the following calculations on your box: surface area of the entire box and volume. Furthermore, you should be able to make your box larger and smaller in the following two different ways: .Specify by how much larger (multiplier) you would like to enlarge each dimension of the object. For example, makeLarger(2) would multiply the length, width, and height of the box by 2. Specify the specific amount you would like to add to each dimension of the box. For example, makeLargerl1, 3, 5) would add 1 to the length, 3 to the width, and 5 to the height of the box Be sure to include methods for the following tasks 1. 2. 3. 4. 5. 6. Constructors (three) Calculate and return the volume Calculate and return the surface area Enlarge the box by multiplying each side by a number Enlarge the box by adding a number to each side Output the dimensions Demonstrate that your program works properly. You will need to test all of the constructors and all of the methods in your class. Display all results to two decimal places. Input and output should be done with Dialog and Message baxes. Your program should be well documented internally and externally

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago