Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA question --- I am working on a Java project that looks at instantiated objects and will determine if the arguments within the parameter are

JAVA question --- I am working on a Java project that looks at instantiated objects and will determine if the arguments within the parameter are equal or not, and print out NOT equal, or ARE equal based upon pre-determined instantiated objects (see the BoxMainClass below).

I need to add to my existing program a method that tests if one object equals another (I started to create a Boolean method not sure if this would be Boolean?). They are equal if all arguments within each parameter in the object match.

In the driver class (BOXMAINCLASS), instantiate two 2D objects, display them, then test if they are equal. If yes, print These 2 papers are equal; if no, print These 2 papers are NOT equal.

Instantiate three 3D objects and display them. Test if box1 equals box2 and if yes, print Box1 equals Box2; test if box1 equals box3 and if yes, display Box1 equals Box3 ; test if box2 equals box3 and if yes, display Box2 equals Box3. If none of the boxes match, display These boxes are not equal.

I have most of the code completed and looking for a little guidance and thoughts as to completing the program. THANK YOU in advance for your guidance.

The outcome would look something like this;

image text in transcribed

HERE IS MY BOX CLASS;

public class BoxClass { //instance variables private int length; private int width; private int height;

//************************************************************************** //default constructor with variables set to 1 public BoxClass() { this.length = 1; this.width = 1; this.height = 1; }//end constructor Box

//overloaded constructor public BoxClass(int length, int width) { this.length = length; this.width = width; this.height = 0; }//end overloaded constructor

//overloaded constructor public BoxClass(int length, int width, int height) { this.length = length; this.width = width; this.height = height; }//end overloaded constructor

//************************************************************************** //accessor getArea method public int getArea() { return this.length * this.width; }//end getArea

//accessor getPerimeter method public int getPerimeter() { return 2 * (this.length + this.width); }//end getPerimeter accessor method

//accessor getPerimeter method public int getVolume() { return this.length * this.width * this.height; }//end getPerimeter accessor method

//************************************************************************** //Boolean method to determine if object is a cube public Boolean isCube() { return length == height && height == width; }//end Boolean isCube

//Boolean method to determine if object is a box public Boolean isBox() { return length > 0 && height > 0 && width > 0; }//end Boolean isBox

//Boolean method to determine if object is a square public boolean isFlatSquare() { return length == width; }//end isSquare boolean method //************************************************************************** //Method to test if one paper, or one box equals another. //Equal if all measurments match, and match against another of it's kind (e.g. paper to paper, //box to box). public boolean equals() { WOULD THIS METHOD BE A BOOLEAN to determine if the shapes areequal or not equal? }//end boolean method

//************************************************************************** //display method for output to BoxMainClass public void display() { //If isCube() returns true then it is a cube then this block will be executed

if (isCube()) { System.out.println("This box is a cube: 3 on all sides " + length + " x " + width + " x " + height + " Volume: " + getVolume());

} //If isCube returns false then isBox will be checked //If it returns true then this block will be executed else if (isBox()) { System.out.println("This is a square: " + length + " x " + width + " x " + height + " Volume: " + getVolume());

} //If isbox returns false then isSquare will be checked //If issquare returns true then this block will be executed else if (isFlatSquare()) { System.out.println("This is a flat Square: " + length + " x " + width + " Perimeter: " + getPerimeter() + " Area: " + getArea());

} //If isSquare returns false that means it's a rectangle and else block will be executed else { System.out.println("This is a rectangle: " + length + " x " + width + " Perimeter: " + getPerimeter() + " Area: " + getArea()); } }//end display method

}//end class Box

HERE IS MY BOXMAINCLASS;

public class BoxMainClass {

/** * @param args the command line arguments */ public static void main(String[] args) {

//Instantiate 2D objects using the constructor with 2 arguments

BoxClass paper1 = new BoxClass(31, 11); BoxClass paper2 = new BoxClass(5, 5);

//Instantiate 3D objects using the constructor with 3 arguments BoxClass box1 = new BoxClass(8, 4, 16); BoxClass box2 = new BoxClass(3, 3, 3); BoxClass box3 = new BoxClass(3, 3, 3);

//output System.out.println("Object Paper 1: "); paper1.display();

System.out.println(" Object Paper 2: "); paper2.display();

System.out.println(" These two papers are " + " equal"); //this will printout // if the Instantiate 2D objects are a match or not

System.out.println(" Object Box 1: "); box1.display();

System.out.println(" Object Box 2"); box2.display();

System.out.println(" Object Box 3"); box3.display();

System.out.println(" "); /ot sure how to code this output to determin //if the Instantiate 3D objects are a match or not

}//end main

}//end BoxMain Class

Object paperi This is a rectangle: 8 x 11 Perimeter: 38 Area: 88 Object paper2 This is a rectangle: 11 x 8 Perimeter: 38 Area: 88 These 2 papers are NOT equal Object box1 This box is 8 x 4 x 6 Volume: 192 Object box2 This box is a cube: 3 on all sides Volume: 27 Object box3 This box is 8 x 4 x 6 Volume 192 Boxl equals Box3 BUILD SUCCESSFUL (total time: 0 seconds)

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions