Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS CODE BELOW IS THE WORKING POINT, RECTANGLE, AND BOX CLASS REQUIRED TO BE ABLE TO ANSWER THIS QUESTION: class Point { // instance variables

THIS CODE BELOW IS THE WORKING POINT, RECTANGLE, AND BOX CLASS REQUIRED TO BE ABLE TO ANSWER THIS QUESTION:

class Point { // instance variables private int x; private int y; private int z;

// default constructor to set (x,y,z) to (3,4,5) public Point() { setX(3); setY(4); setZ(5); }

// parameterized constructor to set (x,y,z) to specified values public Point(int x, int y, int z) { setX(x); setY(y); setZ(z); }

// setters // method to set the value of x public void setX(int x) { this.x = x; }

// method to set the value of y public void setY(int y) { this.y = y; }

// method to set the value of z public void setZ(int z) { this.z = z; }

// getters // method to return the value of x public int getX() { return x; }

// method to return the value of y public int geY() { return y; }

// method to return the value of z public int getZ() { return z; }

// method to return String representation of Point object public String toString() { return "("+x+", "+y+", "+z+")"; } }

//=>Rectangle.java

/** * The Class Rectangle. */ Public class Rectangle extends Point{ /** * The Width. */ protected int width; /** * The Height. */ protected int height; /** * The Color. */ protected Color color;

/** * Instantiates a new Rectangle. */ 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; }

/** * Instantiates a new Rectangle. * * @param width the width * @param height the height * @param length the length * @param color the color */ 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; }

/** * Gets width. * * @return the width */ public int getWidth() { return width; }

/** * Sets width. * * @param width the width */ public void setWidth(int width) { this.width = width; }

/** * Gets height. * * @return the height */ public int getHeight() { return height; }

/** * Sets height. * * @param height the height */ public void setHeight(int height) { this.height = height; }

/** * Gets color. * * @return the color */ public Color getColor() { return color; }

/** * Sets color. * * @param color the color */ public void setColor(Color color) { this.color = color; }

/** * Area int. * * @return the int */ public int area(){ return width*height; }

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

//=>Box.java

/** * The Class Box. */ Public class Box extends Rectangle{ private int length;

/** * Instantiates a new Box. */ public Box() { this.width = 3; this.height = 5; this.length = 4; this.color = Color.Blue; }

/** * Instantiates a new Box. * * @param width the width * @param height the height * @param length the length * @param color the color */ public Box(int width, int height, int length, Color color) { super(width, height, length, color); this.length = length; }

/** * Instantiates a new Box. * * @param length the length */ public Box(int length) { super(); this.length = length; }

/** * Gets length. * * @return the length */ public int getLength() { return length; }

/** * Sets length. * * @param length the length */ public void setLength(int length) { this.length = length; }

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

/** * Volume int. * * @return the int */ public int volume(){ return height*width*length; }

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

image text in transcribedimage text in transcribedimage text in transcribed

Instructions: Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. NOTE: YOU NEED YOUR POINT, RECTANGLE, AND BOX CLASS FOR THIS ASSIGNMENT 1. Start with a working Point class. Refer to the Point program created for Lab #1 a. Make Point an abstract class b. Add an abstract method called calcArea c. 2. Write a new Circle class, a subclass of the Rectangle class. a. Add a radius variable to the new class. b. Add constructors i. a default Circle where: 1. call super constructor with a width of 6. length of 0, and height of 6, color is cyan 2. radius = 3 ii. a 1 argument constructor Circle(radius) 1. call super with a width of 2 times radius, length of 0. height of 2 times radius and a color of yellow. c. Override the calcArea method i. Calculates the area of a Circle object: area= 3.14 * radius * radius ii. returns the area of a Circle object 111. Do not store the area in a member instance) variable. d. Override the toString method to display (and label) all of the characteristics (instance variables) of a Circle object. Do not forget to include the super instance variables by using the super.toString(. Do not include area in the toString output...only instance varliables are part of the toString Lab 3 - Advanced Java Inheritance, Polymorphism, abstract Types 3. Write a new Cylinder class, a subclass of the Circle class. a. Add length as a new variable b. Add 1 constructor: Cylinder(int radius int length. Color color) i. Call the super sending the radius, length and color ii. Initial length 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 * length ii. returns the area of a Cylinder object 111. Do not store the area in a member variable. e. Add a method called volume that: i. Calculates the volume of a Cylinder object: volume = 3.14 * radius * radius * length. ii. returns the volume of a Cylinder object 111. 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. Once again, use the super.toStringO. 4. Write an executable client class called ShapesAbstractTester - a separate program - that uses the Point, Rectangle, Box, Circle, Cylinder classes. a. Create an array of the Point class Point[] myShapes = new Point[4]: b. Populate the array with a new Rectangle(6,9, 0, blue) in myShapes[0]; C. Populate the array with a new Circle(12) in myShapes[1]; d. Populate the array with a new Box(25, 15, 20, pink) in myShapes[2]; e. Populate the array with a new Cylinder(5, 36, lightgray) in myShapes[3]; f. 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 object's toStringo 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 v. Print the area for all objects vi. Print the volume for box and cylinder vii. NOTE: You must use a for loop and the instanceof method to recieve full credit for this lab. Sample Output ++ LAB 3 SAMPLE OUTPUT ++ Programer OHRiley Lab3 Rectangle Box Circle Cylinder 9 January 2014 30 January 2021 Object is a Rectangle. width = 6 height = 9 Colorjava.awt.Color[r 8,8-0,6-255] center (3, 5, 0) Object 2 is a Box. length = 20 width = 25 height = 15 Colorjava.awt.Color[r=255,8=175,b=175]|| center (13, 8, 10) The area of the object - 2,350.000 square units. The volume of the object = 7,500.000 cube units The area of the object - 54.880 square units. Object 1 is a Circle. radius - 12 width = 24 height = 24 Colorjava.awt.Color[r=255,g=255, be] center (12, 12, 0) Object 3 is a Cylinder. length36 radius = 5 width = 10 height = 10 Colorjava.awt.Color[r=192,8=192,b=192] center (5, 5, 18) The area of the object 452.160 square units. The area the object = 1,287.400 square units. The volume the object = 2,826.000 cube units

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions