Page 1 of 1

Set up: Download Lot.java and TestLots.java, and import them into a blank NetBeans project (or if you're using a differ

Posted: Tue Jul 05, 2022 10:27 am
by answerhappygod
Set up: Download Lot.java and TestLots.java, and import them into a blank NetBeans project (or if you're using a different IDE, import/open the files in whichever manner is appropriate for that IDE).
Requirements:
For this lab, you’ll 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 in 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 you’ll have to implement
TestLots.java: driver file, run this file once you have everything implemented. The results you should get are specified in that file’s header
Your assignment is to implement the two child classes of the abstract Lot class, and to make them Comparable (implement the Comparable<Lot> interface). Your compareTo function results should be based on the area of the Lot:
LotType1.java: extend Lot, implement Comparable<Lot> 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 you’ve 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.
Lot:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package lottype1;
/** * * @author Michael Obernesser */public class Lot {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here }
double calculateArea() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }}
TestLots:
/* 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(); }
}}