What to submit: LotType1.java and LotType2.java (up to 10 points may be deducted for submitting anything else, or not su
Posted: Sun Jul 03, 2022 10:00 am
What to submit: LotType1.java and LotType2.java (up to 10 points may be deducted for submitting anything else, or not submitting these files, or naming them differently). Additional deductions (also up to 10 points) may be made for poor code style: lack of program headers, lack of methods headers, lack of in-code block-level commenting).
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.
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.
Lot:
/* 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();
}
}
LestLots:
/* 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();
}
}
}
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.
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.
Lot:
/* 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();
}
}
LestLots:
/* 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();
}
}
}