Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//create an abstract Shape class abstract class Shape { static int shapeCount = 0; public Shape() { //shapeCount is incremented every time a new shape

image text in transcribed

//create an abstract Shape class abstract class Shape { static int shapeCount = 0; public Shape() { //shapeCount is incremented every time a new shape is created shapeCount = shapeCount + 1; } //define abstract methods area(), perimeter(), and getShape() abstract double area(); abstract double perimeter(); //getShape() will return a String that represents a particular shape abstract String getShape(); }

Comparable (3 points) 1. Java has a built-in interface called Comparable. It only has one method, compareTo (). The T in Comparable is a generic type. When you implement the interface, you replace T with the type that you want to compare to compareTo () returns an integer. For two objects x and y, x.compare To (y) should be negative if xy and zero if x=y. 2. Modify Shape so that it implements Comparable. Notice that we can implement multiple interfaces, but we can only extend one class. For the purpose of this assignment, we will consider one shape to be bigger than another if its area is bigger. In the main method of Shape Tester, sort the array you have created using the Collections.sort() method. Since Shape implements Comparable, the Collections.sort() method will know how it should compare two shapes. It will use this to sort the shapes by their area. Display the elements of this array again to make sure the sorting worked properly

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

Use a three-step process to develop effective business messages.

Answered: 1 week ago