Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. a. Write a class called Triangle that implements the Comparable interface. The class should contain 3 fields: vertexA (Point), vertexB (Point), vertexC (point). Write

image text in transcribed
1.
a. Write a class called Triangle that implements the Comparable interface. The class should contain 3 fields: vertexA (Point), vertexB (Point), vertexC (point). Write the necessary constructors, accessors, mutators and other methods. The Point class is given below.
b. Write a client class that creates an ArrayList of 10 Triangle objects called list1.
Print the list.
Call Collections.sort(list1), to sort the elements according to the area of the triangle.
Print the sorted list.
public class Point {
private int x;
private int y;
public Point() {
this(0, 0);
}
public Point(int x, int y) {
this.x=x;
this.y=y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String toString() {
return "(" + x + ", " + y + ")";
}
}
1. a. Write a class called Triangle that implements the Comparable interface. The class should contain 3 fields: vertexA (Point), vertexB (Point), vertexC (point). Write the necessary constructors, accessors, mutators and other methods. The Point class is given below b. Write a client class that creates an ArrayList of 10 Triangle objects called listl Print the list. Call Collections.sort(listl), to sort the elements according to the area of the triangle. Print the sorted list. public class Point private int x private int y public PointO this(0, 0); public Point(int x, int y this.x-x; this.y-y; public int getXO i public int getYO public String toString0 return X return y return "x+" "+y+")

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

Th ey told me Id have to write a lett er. Whos got time for that?

Answered: 1 week ago