Earn Higher Grades With Instant Assignment Help.Ask Question!

Java Programming
(5/5)

The GeometricObject, Circle and Rectangle classes are given for this question. You may need to make necessary changes to the classes other

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Java :

The GeometricObject, Circle and Rectangle classes are given for this question. You may need to make necessary changes to the classes other than what is mentioned below. As a summary, the files in your submission for this question should at least include: GeometricObject.java,

 

Circle.java, Rectangle.java, Triangle.java, TestTriangleWithException.java, and TestLarger.java. Please bundle the above files and your class files in a folder named

 

Assignment3Question3.

 

PART I:    Declare the getPerimeter() and getArea() methods in the GeometricObject class. These two methods should be declared as abstract because they cannot be implemented in the GeometricObject class. Override and implement getPerimeter() and getArea() in the subclasses Circle and Rectangle. Override and implement toString() method in Circle class as:  return "Circle: radius = " + radius;  and in Rectangle class as:  return "Rectangle: width = " + width + ", height = " + height;

 

Use @Override annotation for all overridden methods.

 

PART II: Design and implement a class named Triangle that extends GeometricObject. The  class contains:

 

  • Three double data fields named side1, side2, and side3 with default values  1.0 to denote three sides of a triangle.

 

  • A no-arg constructor that creates a default triangle.

 

  • A constructor that creates a triangle with the specified side1, side2, and side3.
  • Override and implement the abstract methods getPerimeter() and getArea()

 

in GeometricObject class.

 

(Hint: The area of a triangle is given by   sqrt ( p( p- side1)(p-side2)(p-side3))

 

       where p is half the perimeter, that is, p = (side1+side2+side3 ) /2

 

  • Override and implement the toString() method as:

 

return "Triangle: side1 = " + side1 + ", side2 = " + side2 + "side3 = " + side3;

 

Use @Override annotation for all overridden methods.

 

In a triangle, the sum of any two sides is greater than the other side. The Triangle  class must adhere to this rule. Create the IllegalTriangleException class and modify the constructor of the Triangle class to throw an IllegalTriangleException object if a triangle is created with sides that violate the rule. The constructor of  IllegalTriangleException must encapsulate all three sides of the triangle and a  string message, as follows:

 

public IllegalTriangleException(double side1, double side2, double side3, String message)

 

Write a test program TestTriangleWithException to test your Triangle class  and IllegalTriangleException by creating two objects of Triangle with one of  them violating the rule. Print the perimeter and area of the legal triangle. Print the  sides and string message of the illegal triangle from the IllegalTriangleException caught. You may need additional methods in IllegalTriangleException other than  what is mentioned above. Format your output to two decimal places. A sample run is as follows:

 

Legal triangle :

 

Perimeter : 6.50

 

Area : 10.25

 

Illegal triangle :

 

Side1 = 1.00

 

Side2 = 2.00

 

Side3 = 3.00

 

The sum of any two sides is greater than other side.

 

PART III:

 

Implement a static method called larger that takes two geometric objects of the same  type as arguments and returns the object with larger area. If the two objects have the  same area, the method returns null. If the two geometric objects are not of the same

 

type, the method throws DifferentTypeException. DifferentTypeException is a  user-defined exception. Define it for your larger method. The method signature or  larger is as follows:

 

static GeometricObject larger(GeometricObject g1, GeometricObject g2)

Write a test program called TestLarger. Implement larger method in TestLarger  and test if your larger method works properly. Create different types of geometric objects to invoke the larger method. You should test your larger method with two  circles, two rectangles, two triangles, and two different object types which should throw

 

DifferentTypeException. Print out appropriate details about the object returned  by larger method such as radius, width, height, sides, perimeter, and area. Format  your output to two decimal places. A sample output is as follows:

 

Testing two circles of same radius :  Two objects have equal area  Testing two circles of different radius:

 

The returned larger object is : Circle : radius = 3.0

 

The area is 28.27

 

The perimeter is 18.85

 

Testing two rectangles of different sizes :

 

The returned larger object is : rectangle : width = 3.0, height = 3.0

 

The area is 9.00

 

The perimeter is 12.00

 

Testing two triangles of different sizes :

 

The returned larger object is : Triangle, side1= 2.0, side2=3.0, side3=2.3

 

The area is 17.59

 

The perimeter is 7.30

 

Testing two different object types:

 

Two objects are of different type.

 

Please note that you are not allowed to overload larger method to accommodate  Circle, Rectangle and Triangle. You must test whether the two geometric objects  are of the same type in your larger method and throw DifferentTypeException in the case of different types.

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
792 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
886 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
817 Answers Hire Me