Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start with a working Point class. Refer to the Point program created for Lab #1 a. Make Point an abstract class 2. Write a new

Start with a working Point class. Refer to the Point program created for Lab #1 a. Make Point an abstract class 2. Write a new Circle class, a subclass of the Point class. a. Add a radius variable to the new class. b. Add constructors i. a default Circle()where radius = 15 ii. a 1 argument constructor Circle(radius) iii. use the Super() default constructor for the x, y values (This is the center point of the circle) c. Calculates the area of a Circle object: Area= 3.15 * radius * radius d. returns the Area of a Circle object e. Do not store the area in a member variable. f. Override the toString method found in class Point to display (and label) all of the characteristics (instance variables) of a Circle object. Do not forget to include the original point instance variables by using the super.toString(). 3. Write a new Cylinder class, a subclass of the Circle class. a. Add height as a new variable in this class b. Add constructors i. a default Cylinder() where height = 15 ii. a 1 argument constructor Circle(height) iii. use the Super() default constructor for the x, y, radius values c. Add get ( ) and set ( ) methods as needed. d. Override the area method inherited from the Circle class to calculate the outside face area of a Cylinder object. i. Calculates: Area= 2 * 3.14 * radius * radius + 2 * 3.14 * radius * height ii. returns the area of a Cylinder object iii. Do not store the area in a member variable.Lab 3 - Advanced Java Inheritance, Polymorphism, Abstract Types Rev. 1/28/2023 3:27 PM e. Add a method called volume that: i. Calculates the volume of a Cylinder object: Volume = 3.14 * radius * radius * height. ii. returns the volume of a Cylinder object iii. Do not store the volume in a member variable. f. Override the toString method inherited from class Circle class to display (and label) all of the characteristics (instance variables) of a Cylinder object. Do not forget to include the original point and radius instance variables by using the super.toString(). 4. Write an executable client class called ShapesABSTester a separate program - that uses the Point, Rectangle, Box, Circle, Cylinder classes. a. Print your name, Lab number, and date as the first three lines of output. Hard-code the date...do not use the system date. b. Create an array of the Point class Point[] myShapes = new Point[4]; c. Populate the array with a new Rectangle(10,20) in myShapes[0]; d. Populate the array with a new Box(30) in myShapes[1]; e. Populate the array with a new Circle(40) in myShapes[2]; f. Populate the array with a new Cylinder(50) in myShapes[3]; g. Using a for loop examine each item in the array with the instanceOf method to determine if the object is a cylinder, circle, box, or rectangle i. Print out the type of object and the objects toString() ii. Only type an object once iii. If an object is a cylinder then do not call it a circle as well iv. If an object is a box then do not call it a rectangle as well

BELOW IS CODE:

public class Point { private int x; private int y; private int z;

public Point() { setX(3); setY(4); setZ(5); } public Point(int x, int y, int z) { setX(x); setY(y); setZ(z); } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void setZ(int z) { this.z = z; } public int getX() { return x; } public int geY() { return y; } public int getZ() { return z; } public String toString() { return "("+x+", "+y+", "+z+")"; } }

RECTANGLE

public class Rectangle extends Point{

protected int width;

protected int height;

protected Color color;

public Rectangle() { super((int)Math.ceil(3/2), (int)Math.ceil(5/2),(int)Math.ceil(5/2)); this.width = 3; this.height = 5; this.color = Color.Orange; } public Rectangle(int width, int height,int length, Color color) { super((int)Math.ceil((double) width/2), (int)Math.ceil((double) height/2),(int)Math.ceil((double) length/2)); this.width = width; this.height = height; this.color = color; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public int area(){ return width*height; }

@Override public String toString() { return "width=" + width + ", height=" + height + ", color=" + color + " point: "+super.toString(); } }

BOX

public class Box extends Rectangle{ private int length;

public Box() { this.width = 3; this.height = 5; this.length = 4; this.color = Color.Blue; }

public Box(int width, int height, int length, Color color) { super(width, height, length, color); this.length = length; }

public Box(int length) { super(); this.length = length; }

public int getLength() { return length; }

public void setLength(int length) { this.length = length; }

@Override public int area() { return height*width*2 + width*length*2 + length*height*2; }

public int volume(){ return height*width*length; }

@Override public String toString() { return "length=" + length + " "+super.toString(); } }

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

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions