Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab, youll be provided two files. Do not make any changes in these (20 points for no changes in these two files; I

For this lab, youll be provided two files. Do not make any changes in these (20 points for no changes in these two files; I will be using my own files to test, so changing yours would result int this deduction, if it turns out that your lab only "works" with your versions of Lot.java and TestLots.java):

  • Lot.java: abstract class, parent of the two classes youll have to implement

  • TestLots.java: driver file, run this file once you have everything implemented. The results you should get are specified in that files header

Your assignment is to implement the two child classes of the abstract Lot class, and to make them Comparable (implement the Comparable interface:

  • LotType1.java: extend Lot, implement Comparable interface. Lots of Type 1 are triangular, use this information to implement the area calculation correctly (40 points total; 20 points for correct abstract class extension, 20 points for correct interface implementation).

  • LotType2.java: same, but lots of Type 2 are rectangular -- use the correct formula for area (40 points total; 20 points for correct abstract class extension, 20 points for correct interface implementation).

Once youve successfully implemented both of these classes, you should be able to run TestLots and get correct (and correctly sorted) results. Make sure all four files are included in the same NetBeans project.

Note: there is no need to submit either Lot.java or TestLots.java -- I will use my own for testing (they'll be exactly the same as the ones you downloaded, this is just meant to test for "no changes" in those files). Please submit only LotType1.java and LotType2.java.

/* abstract class, parent of LotType1 and LotType2 */

public abstract class Lot { public abstract double calculateArea(); public abstract String getID(); @Override // Implement the toString method in GeometricObject public String toString() { return "Lot ID "+ getID() +" has area: "+ calculateArea(); } }

/* driver to test code -- use with Lot.java, LotType1.java, LotType2.java */ /* implement LotType1 and LotType2 prior to testing */

/* once everything is correctly implemented, the output of this driver will be: Lot ID L3 has area: 13500.0 Lot ID L2 has area: 27000.0 Lot ID L1 has area: 35000.0 Lot ID L4 has area: 70000.0 */

public class TestLots { public static void main(String args[]){ // an array of lots -- some of type1, some of type2 Lot[] lots = {new LotType1("L1",350, 200), new LotType2("L2",100,270), new LotType1("L3",100, 270), new LotType2("L4",350,200) }; // sort the lots of mixed types by area (note, you'll have to implement // Comparable interface correctly in LotType1 and LotType2 for this to work: java.util.Arrays.sort(lots); // print out sorted results for (Lot lot: lots) { System.out.print(lot + " "); System.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 Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

=+ Are they breakable for any reason?

Answered: 1 week ago

Question

=+When and under what circumstances are contracts renegotiated?

Answered: 1 week ago

Question

=+Are the contracts enforceable?

Answered: 1 week ago