Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Alter your Rectangle class to include compareTo and make any other modifications you need. DO NOT alter the toString method. Write a main program so

Alter your Rectangle class to include compareTo and make any other modifications you need. DO NOT alter the toString method. Write a main program so that it will first read an int to say how many rectangles you will input. Then read that many lengths and widths from the keyboard, create rectangles, add to an ArrayList. Finally sort and output the ArrayList. Note: One rectangle is bigger than another if its area is bigger.

import java.util.Scanner;

/** * * @author Jean Mehta */ public class Lab7Num2 {

public static class Rectangle { private double length, width; public Rectangle() { length=0; width=0; } public Rectangle(double len, double wid) { length=len; width=wid; }

public double getLength() { return length; }

public void setLength(double length) { this.length = length; }

public double getWidth() { return width; }

public void setWidth(double width) { this.width = width; } public double area() { return length*width; } public double perimeter() { return 2*(length+width); } public String toString() { return "Length: " + length + " Width: " + width; } public int compareTo(Rectangle r) { //put your code here } } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); //declare an ArrayList to hold your Rectangles //input the number of rectangles int howMany = keyboard.nextInt(); //loop howMany times, //each time input a length and width, create a rectangle, add it to the ArrayList //sort the ArrayList //output the ArrayList } }

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

2. What type of team would you recommend?

Answered: 1 week ago

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago