Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, we are dealing with packaging boxes. You will need to create three classes (all in the same file please, for ease

image text in transcribedimage text in transcribed

In this problem, we are dealing with packaging boxes. You will need to create three classes (all in the same file please, for ease of grading): 1. A RegularBox class (do not declare as public) 2. A SquareBox class (do not declare as public) 3. A Package Test class (this class is public and contains main()) The RegularBox class Four fields: length, width, height of the box (doubles), and the material for the box (paper, plastic, or wood). A full constructor ( you can assume there will be no silly inputs, e.g., length < 0) All the get methods (no need for set methods) A toString() method A getPackageVolume() method A getPackageCost() method. The cost is: O O O O $0.045 per cubic inch of volume for a carton box $0.0775 per cubic inch of volume for a plastic box $0.135 per cubic inch of volume for a wooden box The method returns -1 for any other material The SquareBox class This class inherits from the RegularBox class. It contains no fields and only one two methods: 1. A constructor: public SquareBox(double side, String material) 2. A getPackage Cost() method. Because of the square shape, the cost of such a box is 10% less than the cost of a regular box, given the same material. This method a. Must override its parent class method b. Must leverage the parent's class method code (NO code duplication!) The PackageTest class This is the public class containing the main() method to test the other two classes. Sample Run: // These two boxes have the same volume but one is square, the other is not! RegularBox regBox1 = new RegularBox(4, 8, 2, "carton"); SquareBox sqBox1 = new SquareBox(4, "carton"); RegularBox regBox2= new RegularBox(4, 8, 2, "plastic"); RegularBox regBox3 = new RegularBox(4, 8, 2, "wood"); SquareBox sqBox2= new SquareBox(3, "concrete"); // Your print statements here (see the desired output below: // All values to 2 decimal places. Output: The volume of regBox1 is 64.00 cubic inches The cost of regBox1 is $2.88 The cost of regBox2 is $4.96 The cost of regBox3 is $8.64 The cost of sqBox1 is $2.59 The cost of sqBox2 is $-1.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

class RegularBox private double length width height private String material public RegularBoxdouble ... 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

Calculus

Authors: Dale Varberg, Edwin J. Purcell, Steven E. Rigdon

9th edition

131429248, 978-0131429246

More Books

Students also viewed these Programming questions

Question

What research interests does the faculty member have?

Answered: 1 week ago