Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Triangle (25 points) Description: In this assignment you'll write a class that represents a triangle but no test client. The test client Collaborations

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Part 2: Triangle (25 points) Description: In this assignment you'll write a class that represents a triangle but no test client. The test client Collaborations is already provided (see below). As always make sure to follow best practices as described in earlier assignments. - side2: double - side3 : double +getSide2 0): double sTriangle ( side1 : double, side2: double, side3 +isRight 0: boolean double): boolean Notice that this class has no setters. It is an immutable class. This means that instances of this class can no longer been changed once they have been created. Instructions: TriangleApp.java . Add the fields, constructors. and methods as specified in the UML class diagram Make sure to match the names, types, parameter lists, access modifiers, etc. specified No class has 3 3583/assignments/59407707module item _id 8881351 Constructor. The constructor has 3 parameters to initialize the fields. However, before we can assign the arguments to the fields we need to ensure that they form a valid triangle. If that is not the case all sides should be initialized with 1d Hint: To find out whether the 3 sides form a valid triangle the constructor should call the private method isTriangle ( see below) FYI: Typically you might throw an exception if the arguments don't form a valid triangle. We haven't learned how to use exceptions yet, so for now we just set the values to something appropriate (in our case 1d) e isTriangle: The method isTriangle determines whether the three argument values form a triangle or not. E.g. 3 sides of length 2,3, and 7 do not form a triangle, nor do-1, 1, and 3. However, 2, 3, and 4 do form a triangle) Notice that this method is declared private. It is meant for internal use only to be called by isEquilateral: The method isEquilateral does not need any parameters. It takes the values of the fields to find out whether the given triangle happens to be an equilateral triangle. It returns the boolean value. . isRight The method isRight also takes the field values to find out whether the given triangle is a right triangle. It returns the corresponding boolean value Caveat: we do not know which of the 3 sides is the longest Hint 1: Use the logical operators (&&, I) to implement the methods above Hint 2: The class Triangle should include no print statements Create a video recording that shows shows the code of class Triangle. Please start at the very top of the file and slowly scroll down so that I can stop in order to have a closer look at the code e compile and run the program Hint 1: Use the logical operators(&&, ID to implement the methods above. Hint 2: The class Triangle should include no print statements. Create a video recording that shows shows the code of class Triangle. Please start at the very top of the file and slowly scroll down so that I can stop in order to have a closer look at the code. After showing the code compile and run the program. Make the size of the output window large enough to see all of the output. The length of the video should be about 1 minute. Expected Output: Triangle (3.0, 5.e, 4.0) is right Triangle (5.0, 4.0, 3.0) is right Triangle (4.0, 3.0, 5.0) is right Triangle (4.5, 4.5, 4.5) is equilateral Triangle (1.e, 1.e, 1.0) is equilateral Triangle (4.0, 4.0, 5.0) Triangle (1.0, 1.0, 1.0) is equilateral Triangle (1.e, 1.e, 1.0) is equilateral Triangle (1.0, 1.e, 1.e) is equilateral Submission: Submit both the video recording and the java file. A05 Triangle Ratings Pts Criteria 3.0 pts Follow bcst in the i Name: Margret Posch Assignment : Triangle * TriangleApp 13 a test client for class Triangle. + No changes should be made to this class publie class Triangleapp public static void main (String tl arga) doublet side1Values H3.0. 5.0. 4.0, 4.5, 0.0, 4.0 double[] side2values {5.0, 4.0, 3.0, 4.5, ., 4.0, doublet) aide3Values4.0, 3.0, 5.0, 4.5, 0.0, 5.0, 2.0..0.(3.11 2.0./2.0.2.11 1.0/a.0o.0) int number0fTest ideiva lues. length; for (int i # 0; i le sideivaiuestil). sidezvaluest4i, side 2valuea i1)i Private ecatie void testaziangle (Triangle t) System.out.printE("Triangle (.1f, .1f, .1f) t.gersidel).t.gerside20. t.getside30)2 Byptem.out.print(t.iRighe02 "io right" )z syatem.out.println)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

The following figure depicts the hit allocation for a 1 6 bit word

Answered: 1 week ago

Question

=+Differentiate between social media roles

Answered: 1 week ago