Part 1: Abstract Classes   1. Copy the source files of Circle, Rectangle and GeometricObject classes (located in  LabFiles folder) and paste them in the default package (You may need to fix any  problems related to package declaration).   2. Open Circle, Rectangle and GeometricObject classes using NetBeans editor and go  through the classes’ implementation.    3. In the GeometricObject class add two methods called respectively getArea() and  getPerimeter().   Discuss:   1. Is the area formula of a circle similar to area formula of a rectangle?   Since:    GeometricObject is the superclass of Circle and Rectangle, and getArea() method is a

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Part 1: Abstract Classes  
1. Copy the source files of Circle, Rectangle and GeometricObject classes (located in 
LabFiles folder) and paste them in the default package (You may need to fix any 
problems related to package declaration).  
2. Open Circle, Rectangle and GeometricObject classes using NetBeans editor and go 
through the classes’ implementation.   
3. In the GeometricObject class add two methods called respectively getArea() and 
getPerimeter().  
Discuss:  
1. Is the area formula of a circle similar to area formula of a rectangle?  
Since:  
 GeometricObject is the superclass of Circle and Rectangle, and getArea() method is a 
common method in both Circle and Rectangle classes.  
Then:  
2. Should you define the getArea() method in the superclass GeometricObject? Or in 
the subclasses Circle and Rectangle?   
3. If yes, Should the getArea() method be declared as abstract method in the 
superclass GeometricObject? Or as instant method?   
4. Is declaring getArea() as abstract, would solve the problem of having two different 
area formulas for Circle and Rectangle?  
5. If getArea() is declared as abstract in GeometricObject, should GeometricObject 
class be declared as abstract class?  
Now apply the same discussion to getPerimeter() method.  
  
4. Modify the class GeometricObject to be abstract class as well as the methods getArea() 
and getPerimeter(). Apply the required changes in the class’s header and methods’ 
header. See the UML class diagrams in next page.  

GremetrieObject
-color: String
-filled: boolean
dateCreated: java.util.Date
GeonetricobjectO
Geonetricobject(celor: string,
filled: boolean)
*getcolor(): String
setcolor(coler: String): void
isFilled0: boolean
setrilled(filled: boolean): votd
getbateCreatedO: java.util.Date
tostringO: string
getAreaO: double
peterineter): double
Cede
Rectangle
-radius: double
width: double
-height: double
+Circle
+Circlecradius: double)
Circle(radius: double, color: string.
filled: boolean)
*getkadius0: double
+setkadius(radius: double): void
+Rectangle)
+Rectangle(width: double, hefght: double)
+Rectangle(width: double, height: double,
color: string, filled: boolean)
getwidthO: double
getDiametero: double
+setwidth(width: double): void
getHeight ): double
+setheight(height: double): void
Figure 13.1, Liang, Introduction to sova Programming, Tenth Edition, 2015, Pearson Educotion
5. In both Circle and Rectangle classes, override the two methods getArea() and
getPerimeter().
6. In both Circle and Rectangle classes modify the toString() method to include the area
and perimeter values.
7. Create a Test class. Then complete the following tasks:
a. In the main method, create an Arraylist of type Geometricobject.
b. Add to it the following objects:
• Two Circle objects: circlel and circle2.
• Two Rectangle objects: rectanglel and rectangle2.
c. Print out the ArrayList's elements (use for-each loop).
Transcribed Image Text:GremetrieObject -color: String -filled: boolean dateCreated: java.util.Date GeonetricobjectO Geonetricobject(celor: string, filled: boolean) *getcolor(): String setcolor(coler: String): void isFilled0: boolean setrilled(filled: boolean): votd getbateCreatedO: java.util.Date tostringO: string getAreaO: double peterineter): double Cede Rectangle -radius: double width: double -height: double +Circle +Circlecradius: double) Circle(radius: double, color: string. filled: boolean) *getkadius0: double +setkadius(radius: double): void +Rectangle) +Rectangle(width: double, hefght: double) +Rectangle(width: double, height: double, color: string, filled: boolean) getwidthO: double getDiametero: double +setwidth(width: double): void getHeight ): double +setheight(height: double): void Figure 13.1, Liang, Introduction to sova Programming, Tenth Edition, 2015, Pearson Educotion 5. In both Circle and Rectangle classes, override the two methods getArea() and getPerimeter(). 6. In both Circle and Rectangle classes modify the toString() method to include the area and perimeter values. 7. Create a Test class. Then complete the following tasks: a. In the main method, create an Arraylist of type Geometricobject. b. Add to it the following objects: • Two Circle objects: circlel and circle2. • Two Rectangle objects: rectanglel and rectangle2. c. Print out the ArrayList's elements (use for-each loop).
8. Run the test class.
Part 2: Interfaces
1. Modify the class Rectangle to implement the Comparable interface, as shown in the
following UML class diagrams. Apply the required changes in the class's header.
For more details about the Comparable interface see textbook section 13.6
interface-
java.lang Comparabeckectangle
Geometricobject
+compareTo(o: Rectangle): int
Rectangle
Modified from Figure 13.5, Liong, Introduction to Java Progromming, Tenth Edition, 2015, Pearson Education
2. Then, in the Rectangle class override the method compareTo(), so if this object's area is
greater than the specified (given through the parameter) object's area return 1, if it is less
than return -1, and 0 otherwise.
3. Create a test class named Test2. Then complete the following tasks:
a. Create an Arraylist and add to it 4 Rectangle objects with different width and height
values.
b. Print out the elements of the ArrayList.
c. Sort the elements of the ArrayList using the static method sort of the class
java.long.Collections. This would be possible only, if you implemented the method
compareTo() correctly in the Rectangle class.
d. After sorting the elements of the ArrayList, print the elements again.
4. Run the Test class.
Transcribed Image Text:8. Run the test class. Part 2: Interfaces 1. Modify the class Rectangle to implement the Comparable interface, as shown in the following UML class diagrams. Apply the required changes in the class's header. For more details about the Comparable interface see textbook section 13.6 interface- java.lang Comparabeckectangle Geometricobject +compareTo(o: Rectangle): int Rectangle Modified from Figure 13.5, Liong, Introduction to Java Progromming, Tenth Edition, 2015, Pearson Education 2. Then, in the Rectangle class override the method compareTo(), so if this object's area is greater than the specified (given through the parameter) object's area return 1, if it is less than return -1, and 0 otherwise. 3. Create a test class named Test2. Then complete the following tasks: a. Create an Arraylist and add to it 4 Rectangle objects with different width and height values. b. Print out the elements of the ArrayList. c. Sort the elements of the ArrayList using the static method sort of the class java.long.Collections. This would be possible only, if you implemented the method compareTo() correctly in the Rectangle class. d. After sorting the elements of the ArrayList, print the elements again. 4. Run the Test class.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY