Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

instructions for point class here: Lab 1 - Advanced Java The Point Lab - Abstract Data Types and Objects Goals and Objectives: 1. Write a

instructions for point class here:image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Lab 1 - Advanced Java The Point Lab - Abstract Data Types and Objects Goals and Objectives: 1. Write a Java program which can be used as an abstract data type (ADT) (Also known as a well formed class 2. Correctly use access modifiers in conjunction with instance variables and instance methods 3. Write overloaded constructors 4. Write programs containing no-argument constructors and constructors with arguments 5. Create get and set methods belonging to abstract data types 6. Demonstrate an understanding of the toString method by using it in a Java program 7. Create objects of your ADT and use these objects to execute the ADT's methods Instructions: Refer to the Time1 class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Write a Point class. The Point class should be written as an abstract data type. 2. Include the following instance variables: a. an integer representing the x coordinate b. an integer representing the y coordinate C. an integer representing the z coordinate d. The instance variables in your program should only be directly accessible inside of the Point class. 3. Have 2 constructors for the Point class. a. a no-argument constructor (default) set the instance variables to 3, 4, 5 (x, y, z). b. a constructor having three arguments, one for each of the instance variables, C. set all instance variables to the values by invoking the set method for each variable. 4. Include get and set methods for each of the instance variables identified in step 2. 5. Include a toString method in your Point class. The toString method should be accessible to any program and should return the values of the three instance variables as a String. The String returned should look like this "(x, y, z)" where x, y, and z are replaced the actual values. DO NOT print from within the toString method...return a String. 6. Write a client program (also known as a driver, tester). See the Time1Test program in Figure 8.2 of your Deitel book. Use this program as a model to write your program. Your program will have the same intent but will follow the procedure as outlined below. Name your program PointTest. 7. In the PointTest class, a. Create an object of type Point using the no-arguments constructor. Call this point1 b. Create a second object of type Point using the two-argument constructor. Call this point2. Use the values of x = 4, y = 0, z = 5. C. Display point 1 instance variables after a call to point 1.toString() C. Display point 1 instance variables after a call to point1.toString d. Display point 2 instance variables after a call to point2.toString() e. Change the x value of point1 to 4 using the set method for the x value of point1 f. Display point 1 instance variables after a call to point1.toString g. Display point 2 instance variables after a call to point2.toString /2021 11:49 AM - Advanced Java The Point Lab - Abstract Data Types and Objects h. Change the y value of point2 to 5 using the set method for the y value of point2 i. Display point 1 instance variables after a call to point1.toString j. Display point 2 instance variables after a call to point2.toString() k Change the z value of point2 to 6 using the set method for the y value of point2 1. Display point 1 instance variables after a call to point1.toString() m. Display point 2 instance variables after a call to point2.toString() Instructions: Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Start with a working Point class. Refer to the Point program created for Lab01 2. Write a new Rectangle class, a subclass of the Point class. NOTE: for this system you want to think of the point that is created via the super constructor call as the center of the object. The point should be referred to as the "center" ... see sample output. a. Add instance variables to the new class. i. int: width ii. int: height iii. Color color b. Add constructors i a default Rectangle() where: 1. width = 3, 2. height = 5.1 3. color is orange ii. a multi-arg constructor: Rectangle(int width, int height, int length, Color color) 1. use width, height and color to set the instance variables...there is no instance variable length in our Rectangle so you don't need it yet 111. in both constructors use the super(int, int, int) constructor to set your Point 1. the first int is equal to: width/2 2. the first int is equal to: height/2 3. the first int is equal to: length/2 4. Each value should be rounded-up to the next whole number e.g. if width = 7 then 12 * 7 = 3 42. The x value should be 4 not 3. Hint: I used the Math.ceil method after I cast my integer division to a double...but there are other ways of achieving this. c. Add get() and set () methods as needed to support your new instance variables. d. Add a method called area that: i. Calculates the area of a Rectangle object: area = height * width ii. returns the area of a Rectangle as an integer Rev. 1/29/2021 1:00 PM Lab 2 - Advanced Java Inheritance 111. Do not store the area in a member variable. e. Override the toString method found in class Point to display and label) all of the characteristics (instance variables) of a Rectangle object. Do not forget to include the original point instance variables by using the super.toString( 3. Write a new Box class, a subclass of the Rectangle class. NOTE: for this system you want to think of the point that is created via the super constructor call as the center of the object. The point should be referred to as the "center" ... see sample output. a. Add a length instance variable. b. Add constructors i. a default Box where: 1. width = 3, 2. height = 5, 3. length = 4, 4. color = blue ii. an argument constructor Box(width, height, length, color) 1. invoke Rectangle(int width, int height, int length, Color color) using the super command 2. use length set the instance variable iii. An argument constructor Box(height) 1. Invoke Rectangle() to create a default Rectangle for the c. Add set() methods as needed. i. When you change any dimension, you must also adjust the center point by mutating the x, y, or z value using the rule: dimension/2 taken up to the next integer, if not a whole number. Remember x relates to width, y to height, and z to length. ii. Adjust the point inside the respective mutator, i.e. invoke setX from setWidth, sety from setLength, setZ from setHeight. If this is not done then the center of the object will not be correctly calculated or displayed if a dimension is changed. d. Add get() methods as needed e. Override the area method inherited from the Rectangle class to calculate the outside face area (6 sides) of a Box object i. Calculates: area= height * width * 2 + width * length * 2 + length * height * 2 ii. returns the area of a Rectangle object iii. Do not store the area in a member variable. f. Add a method called volume that: i. Calculates the volume of a Box object: Volume = height * width * length. ii. returns the volume of a Box object 111. Do not store the volume in a member variable. Rev. 1/29/2021 1:00 PM Lab 2 - Advanced Java Inheritance g. Override the toString method inherited from class Rectangle to display (and label) all of the characteristics instance variables) of a Box object. Do not forget to include the original point and rectangle instance variables by using the super.toStringo. 4. Write an executable client class called Shapes Tester - a separate program - that uses the Point, Rectangle and Box 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 two objects of type Point, i. point1 = Point ii. point2 = Point(9, 12, 15) c. Create two objects of type Rectangle i rectangle1 = Rectangle ii. rectangle2 = Rectangle(24, 30, 0, Color.Black) d. Create two objects of type Box. i. box1 = Box ii. box2 = Box(18, 24, 30, Color Orange) e. Execute the toString method for all objects. f Execute the area () methods for all objects of type Rectangle. The area should be printed from the ShapesTester class. Remember the area is being returned to the client. g. Execute the volume () and area() methods for all objects of type Box. The volume should be printed from the Shapes class. Remember the volume is being returned to the client. h. Change the width of box1 to 21 i. Execute the volume () and area() methods for boxl. The volume and area should be printed from the Shapes Tester class. Remember the volume is being returned to the client. j. Change the length of box2 to 222 k. Execute the volume () and area() methods for box2. The volume and area should be printed from the Shapes Tester class. Remember the volume is being returned to the client. 1. Change the height of rectanglel to 49 m. Execute the area() methods for rectanglel. The area should be printed from the Shapes Tester class. Remember the area is being returned to the client. n. Execute the toString method for all objects. Rev. 1/29/2021 1:00 PM Lab 2 - Advanced Java Inheritance 5. Sample Output ++++++++ ++ ++ ++ LAB 2 SAMPLE OUTPUT ++ ++ ++ Programmer OHRiley Lab2 Rectangle and Box 20 January 2021 ********* Printing the instance variables for each of the objects Pointi (3, 4, 5) Point2 (9, 12, 15) Rectangel width = 3 height = 5 Colorjava.awt.Color[r=255,g=200,b=0] center (2, 0, 3) Rectange2 width = 24 height = 30 Colorjava.awt.Color[r=0,g=0,b=0] center (12, 0, 15) Box1 length = 4 width = 3 height = 5 Colorjava.awt.Color[r=0,g=0,b=255] center (2, 2, 3) Box2 length = 30 width = 18 height = 24 Colorjava.awt.Color[r=255,8=200,b=0] center 15, 12 Rev. 1/29/2021 1:00 PM Lab 2 - Advanced Java Inheritance The area of rectangle 1 = 15 square units The area of rectangle 2 = 720 square units The area of box 1 = 94 square units The volume of box 1 = 60 cube units The area of box 2 = 3,384 square units The volume of box 2 = 12,960 cube units ******** ***** Changing box 1 width to 21 The area of box 1 = 418 square units The volume of box 1 = 420 cube units Changing box 2 length to 222 The area of box 1 = 25,416 square units The volume of box 1 = 159,840 cube units Changing rectangle 1 height to 49 The area of rectangle 1 = 147 square 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

Algorithmic Trading Navigating The Digital Frontier

Authors: Alex Thompson

1st Edition

B0CHXR6CXX, 979-8223284987

More Books

Students also viewed these Databases questions

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago