Class Circle A Circle will have a radius. The class will be able to keep track of the number of Circle objects created. It will also hold the total of the circumferences of all the Circle objects created. It will allow a client to create a Circle, passing in a double value for the radius into the Circle constructor. If the value for the radius that is passed in is 0 or negative, then the radius will be set to a value of 999. The constructor should add 1 to the count of the number of Circles created. The constructor should call a method to calculate the circumference and then add the

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

PLEASE SEE ATTACHED IMAGES FOR CLASS TRIANGLE AND CLASS CIRCLE

CLASS SHAPESDEMO IS THE DRIVER 

PLEASE CODE IN JAVA AND SEE ALL SPECIFICATIONS

Problem Statement

Write a class called Triangle that can be used to represent a triangle. 

Write a class called Circle that can be used to represent a circle.

Write a class called TriangleDemo that will interface with the Triangle and Circle classes.

Be sure to specify proper visibility for all methods and properties

Note 1:

When given 3 triangle sides:

  • to determine if the triangle is right

1) Square all 3 sides.

2) Sum the squares of the 2 shortest sides.

3) Compare this sum to the square of the 3rd side.

4) If equal then we have a right triangle

Note 2:

All methods MUST be well documented including formalized pre-conditions and post-conditions.  Refer to document T-1_Design By Contract located in the testing folder in your Project 1 download for guidance.

Note 3:

Your Triangle and Circle classes MUST be written according to these specifications.  Do not vary from those specs.   

 

CLASS SHAPESDEMO

 

  • ShapesDemo will drive the application and manage the arrays which will store the Circle and Triangle objects.  In main you will declare your Circle and Triangle arrays.  You will need one array to store any Circle objects you create and another array to store any Triangle objects you create.  You will also need to instantiate any other objects necessary necessary for input and output and declare any variables used in main.
  • Review the Test Run to see how the application interfaces with the user.

 

  • Inside a loop in main
    • Prompt the user as shown below
    • Allow the user to create either a Circle or a Triangle
    • If the user selects Triangle then allow the user to type 3 integers on separate lines for each triangle. 
    • Instantiate each Triangle (refer to the sample dialog below for test data)
    • Store each Triangle object in an array of Triangle objects.
    • If the user selects Circle then allow the user to type in a double, representing the radius of the Circle.
    • Instantiate each Circle (refer to the sample dialog below for test data)
    • Store each Circle object in an array of Circle objects.

 

ï        Once you have entered you data, then inside a separate loop

  • Use an if statements to test each triangle for its properties and print appropriate output.
    • Print the values of the sides of each triangle.
    • Print the properties that apply for each triangle.  See the sample output.
    • Print the Perimeter for each triangle.

 

  • Inside a separate loop
  • Test each Circle for its properties and print appropriate output.
    • Print the values as shown in the Test Run.

Test Run (Data entered by the user is in boldface)

 

Do you wish to create a circle or a triangle? 

Enter 1 for a circle or 2 for a triangle

1.  Circle

2.  Triangle

1

Enter the radius for circle 1 as a double:  

2.2

Do you wish to process another shape

y

Do you wish to create a circle or a triangle? 

Enter 1 for a circle or 2 for a triangle

1.  Circle

2.  Triangle

1

Enter the radius for circle 2 as a double:  

2.2

Do you wish to process another shape

y

Do you wish to create a circle or a triangle? 

Enter 1 for a circle or 2 for a triangle

1.  Circle

2.  Triangle

2

Enter an integer dimension for side a of triangle 1: 3

Enter an integer dimension for side b of triangle 1: 4

Enter an integer dimension for side c of triangle 1: 5

Do you wish to process another shape

y

Properties for all Triangles created 

Triangle 1 has sides of:

Side a: 3

Side b: 4

Side c: 5

The perimeter is 12

Triangle properties:

Right Triangle

Scalene

 

Triangle 2 has sides of:

Side a: 3

Side b: 3

Side c: 3

The perimeter is 9

Triangle properties:

Acute

Equilateral

The total perimeter of all 9 triangles is: 129

My test for equals method

Triangle 4 and 5 are equal

Triangle 2 and 6 are not equal

Properties for all Circles created

Circle 1 has a radius of 2.2

Circle 1 has circumference of 13.82

Circle 1 has an area of 15.21

Circle 2 has a radius of 2.2

Circle 2 has circumference of 13.82

Circle 2 has an area of 15.21

 

Circles are congruent 

These circles are similar

Class Circle
A Circle will have a radius. The class will be able to keep track of the number of Circle
objects created. It will also hold the total of the circumferences of all the Circle objects
created.
It will allow a client to create a Circle, passing in a double value for the radius into the Circle
constructor.
If the value for the radius that is passed in is or negative, then the radius will be set to a
value of 999.
The constructor should add 1 to the count of the number of Circles created.
The constructor should call a method to calculate the circumference and then add the
circumference for that object to an accumulator.
In addition to the constructor, the Circle class must have the following methods that return a
boolean value:
isCongruent(Circle c) – Compares two Circle objects to determine if they are congruent
(radii are equal).
is Valid() – the radius may not be 0 or negative.
equals (Triangle t) – compares two Triangle objects to determine if they are equal. We
will compare their circumferences to determine equality.
Additional methods in the Circle class
toString() – returns a String that specifies the value of the radius
calcCircumference() – calculate and return the circumference of the object.
calcArea() – calculate and return the area of the object
addTotalCircumference(). This method will call calcCircumference() and add the
çircumberence for that object to an accumulator.
reduceTotalCircumference(). This method should subtract the circumference for that
object from the accumulator.
Accessor methods for all properties.
-
Transcribed Image Text:Class Circle A Circle will have a radius. The class will be able to keep track of the number of Circle objects created. It will also hold the total of the circumferences of all the Circle objects created. It will allow a client to create a Circle, passing in a double value for the radius into the Circle constructor. If the value for the radius that is passed in is or negative, then the radius will be set to a value of 999. The constructor should add 1 to the count of the number of Circles created. The constructor should call a method to calculate the circumference and then add the circumference for that object to an accumulator. In addition to the constructor, the Circle class must have the following methods that return a boolean value: isCongruent(Circle c) – Compares two Circle objects to determine if they are congruent (radii are equal). is Valid() – the radius may not be 0 or negative. equals (Triangle t) – compares two Triangle objects to determine if they are equal. We will compare their circumferences to determine equality. Additional methods in the Circle class toString() – returns a String that specifies the value of the radius calcCircumference() – calculate and return the circumference of the object. calcArea() – calculate and return the area of the object addTotalCircumference(). This method will call calcCircumference() and add the çircumberence for that object to an accumulator. reduceTotalCircumference(). This method should subtract the circumference for that object from the accumulator. Accessor methods for all properties. -
Class Triangle
A Triangle will have 3 sides. The class will be able to keep track of the number of Triangle
objects created. It will also hold the total of the perimeters of all the Triangle objects
created.
It will allow a client to create a Triangle, passing in integer values for the three sides into the
Triangle constructor.
If the values for the sides that are passed in do not represent a valid Triangle (read below for
the requirements for a Triangle to be valid) , then all sides will be set to a value of 1.
The constructor should add 1 to the count of the number of Triangles created.
The constructor should call a method to calculate the perimeter and then add the perimeter
for that object to an accumulator.
In addition to the constructor, the Triangle class must have the following methods that return
a boolean value:
isRight () - see note 1 below regarding Acute triangles.
- see note 1 below regarding Acute triangles.
isObtuse() - see note 1 below regarding Obtuse triangles.
- no two sides are the same length
isIsosceles() - exactly two sides are the same length
- all three sides are the same length
isAcute()
isScalene()
is Valid() - the sum of any two sides of a triangle must be greater than the third in order to
represent a valid triangle. Also, no side may be 0 or negative.
equals (Triangle t) – compares two Triangle objects to determine if they are equal. We
will compare their perimeters to determine equality.
Additional methods in the Triangle class
toString() – returns a String that specifies the values for the 3 sides of the triangle
calcPerim()
addTotalPerim(). This method will call calc perim() and add the perimeter for that object
- calculate and return the perimeter of the object.
to an accumulator.
reduce TotalPerim). This method should subtract the perimeter for that object from the
accumulator.
Accessor methods for all properties.
The Triangle object cannot assume that the values of the 3 sides are entered in any
particular order. Think about what that means.
Transcribed Image Text:Class Triangle A Triangle will have 3 sides. The class will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. It will allow a client to create a Triangle, passing in integer values for the three sides into the Triangle constructor. If the values for the sides that are passed in do not represent a valid Triangle (read below for the requirements for a Triangle to be valid) , then all sides will be set to a value of 1. The constructor should add 1 to the count of the number of Triangles created. The constructor should call a method to calculate the perimeter and then add the perimeter for that object to an accumulator. In addition to the constructor, the Triangle class must have the following methods that return a boolean value: isRight () - see note 1 below regarding Acute triangles. - see note 1 below regarding Acute triangles. isObtuse() - see note 1 below regarding Obtuse triangles. - no two sides are the same length isIsosceles() - exactly two sides are the same length - all three sides are the same length isAcute() isScalene() is Valid() - the sum of any two sides of a triangle must be greater than the third in order to represent a valid triangle. Also, no side may be 0 or negative. equals (Triangle t) – compares two Triangle objects to determine if they are equal. We will compare their perimeters to determine equality. Additional methods in the Triangle class toString() – returns a String that specifies the values for the 3 sides of the triangle calcPerim() addTotalPerim(). This method will call calc perim() and add the perimeter for that object - calculate and return the perimeter of the object. to an accumulator. reduce TotalPerim). This method should subtract the perimeter for that object from the accumulator. Accessor methods for all properties. The Triangle object cannot assume that the values of the 3 sides are entered in any particular order. Think about what that means.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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