Use Eclipse Create New Project Called Lab04 Inheritance Add Following Classes Project Test Q43816424
Use Eclipse to create a new project calledLab_04-Inheritance
- Add the following classes to your project
- Tester
- Automobile ( make sure Tester can’t createan actual Automobile object )
- Car
- Truck
- Bus
- Build out the classes so that Automobile is the parent of Car,Truck, and Bus.
- Automobile should have the following constructors:
- Workhorse
- One that will accept a RandomAccessFile
- Automobile should have the following properties:
- vin (String)
- gasTankSize (double)
- currentGasLevel (double)
- currentMiles (double)
- milesPerGallon (double)
- color (Color)
- isAutomatic (boolean)
- Automobile should have the following methods and coded:
- save(RandomAccessFile raf) throws Exception { }
- load(RandomAccessFile raf) throws Exception { }
- drive(double miles)
- fillTank(double gallons)
- toString()
- Automobile should force it’s children to draw themself
- Each other class ( Car, Truck, Bus ) should override theparent’s load() and save() methods in order to save and load anyadditional information needed that is different between theclasses. For example: A Truck might have a properties: isPickUp,maxLoadCapacity, etc. Car and Bus wouldn’t have have theseproperties so a Truck needs to save the Truck’s personal data. Thiswill apply for the other two classes.
- Each class ( Car, Truck, Bus ) needs to have at least 1property specific to that class and that class only (I’ve alreadygiven you 2 for Truck)
- Each class ( Automobile, Car, Truck, Bus ) needs to haveprivate properties with getters and setters as well as sectionbreaks.
- Each class ( Car, Truck, Bus ) must have their own toStringthat will add the parent’s toString to any additional informationthey have.
- In Tester copy and fix the code below so that it works bysaving and loading the records and printing them out. You will onlyneed to fill in the “. . .”
StarterCode:
public static void main(String[] args) { RandomAccessFile raf = null; try { (new File(“Automobiles.bin”)).delete(); raf = new RandomAccessFile(“Automobiles.bin”, “rw”); (new Car(…)).save(raf); (new Truck(…)).save(raf); (new Bus(…)).save(raf); } catch (Exception e) { e.printStackTrace(); } finally { try { raf.close(); } catch (Exception e) {} } loadAndPrint(); } private static void loadAndPrint() { RandomAccessFile raf = null; try { raf = new RandomAccessFile(“Automobiles.bin”, “r”); System.out.println(new Car(raf)); System.out.println(new Truck(raf)); System.out.println(new Bus(raf)); } catch (Exception e) { e.printStackTrace(); } finally { try { raf.close(); } catch (Exception e) {} } }
Expert Answer
Answer to Use Eclipse to create a new project called Lab_04-Inheritance Add the following classes to your project Tester Automobil…
OR