The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 3 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
C&O: Triangle
A)Â Write a class to represent a Triangle called Triangle. This should include the following:
Â
1. 3 private integer attributes named side1 side2 and side3 that represent the triangle's sides.
2. 1 private Boolean attribute, called formed, to represent whether a triangle can be made from the sides or not.
3. A default constructor to set all sides to a value of 1 and formed to true.
4. A general constructor which will set the sides to values which are passed to the constructor and formed to true if the 3 sides meet the conditions to make a Triangle, otherwise formed should be set to false. Hint: call a method you create later here.
5. Getter and setter methods for the side1, side2 and side3 attributes.
6. A method called setFormed(), that takes no input and returns nothing, to set formed to true if the 3 sides meet the conditions to make a Triangle, otherwise formed should be set to false.
7. A method called getFormed() that returns the value of formed.
8. A method called getPerimeter to calculate and return the perimeter of the triangle if a triangle can be formed, otherwise returns 0.
9. A method called printDetails() that returns nothing and prints the details of each side, whether a triangle was formed or not, and the perimeter of the triangle. Use the relevant methods above here(getPerimeter() etc.). (Please look at appendix for exact output)
B)Â Write a main method in a new class called TestTriangle and in this method:
 1. Create an array of 3 Triangle objects where the sides of each triangle should be set by user input and the general constructor.
2. Call printDetails()on each of the Triangle objects.
3. Create an instance of a Triangle called Triangle1 using the default constructor.
4. Set each side of Triangle1 to user's input using the side attributes setter methods.
5. Make sure formed holds the correct value.
6. Call printDetails() on Triangle1.
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly