logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Liam PattersonEnglish
(5/5)

588 Answers

Hire Me
expert
Radhika GargData mining
(/5)

607 Answers

Hire Me
expert
Elis PanaseykoEnglish
(5/5)

664 Answers

Hire Me
expert
Kate DugganNursing
(4/5)

570 Answers

Hire Me
Java Programming

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme