Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java language. Can you do only Part B Part A. Write out the Triangle class from: Triangle - sidel: double - side2: double -

Using Java language. Can you do only Part B
image text in transcribed
image text in transcribed
image text in transcribed
Part A. Write out the Triangle class from: Triangle - sidel: double - side2: double - side3: double + + + + + + + + Triangle () Triangle (s: double) Triangle (s1: double, s2: double, s3: double) setSides(51: double, s2: double, s3: double) getSides(): double toString(): String areal): double equals(t : Triangle): boolean Make Triangle implement the comparable interface. These objects should be ordered based on area. Write a sorting method for an array of these objects. (Use selection or insertion sort only). Part B. Make an interface that is called Scalable. It should have two functions: the ability to enlarge or shrink an object. Make Triangle Scalable Using Point class from lab 4, make Points Scalable as well. (You may ignore the z values if you want) For both classes, provide an explanation for your enlarge and shrink methods implementation. Part C. Create an array of random Triangles and Points. (There should be a random mixture of all the objects) o Random points should be generated using random integers values from the interval (-50,50] for both x and y values. (You may just keep z values as default 0 values.) o Random Triangles should be created by generating two random integers in the interval [1,100], say x and y. From these values for the sides are computed as: . x2 - y2 - 2xy . x2 + y2 Write a method to go through the array and : enlarge a Point if it's within distance of 20 from the origin, otherwise shrink the Point. enlarge a Triangle if its area is less than the average area of all the Triangles in the array and shrink it otherwise. Point - x: int - y:int - z: int + Point ( //should create the origin (0,0) + Point (x: int, y:int) //should create (x,y,0) + Point (x : int, y:int, z: int) //should create (x,y,z) + distance (Point p): double // should return the distance between the 2 points + distance From Origin (): double //should return the distance from (0,0) + toString(): String //should return the point in the form "(x,y,z)" + equals (Point p): boolean 1/2 points are equal if x, y,z values are all equal + translate (x: int, y:int) : Point + translate (x: int, y:int, z: int): Point (Hint: remember to add the get and set methods) Distance between two points is: (x1 - x2)2 + (y1 - y2)2 + (21 - 2)2 Translating a point is: creating a new point where the x value is the x of the original point plus the parameter, similarly for y and z. Ex. P =(3, -6) and we want to use translate (1, 2) then we should get P2 =(4,-4)

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_2

Step: 3

blur-text-image_3

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions