Question: Use Eclipse to create a new project called Lab_04-Inheritance Add the following classes to your project Tester Automobile ( make sure Tester can't create an

Use Eclipse to create a new project called Lab_04-Inheritance

  1. Add the following classes to your project
    • Tester
    • Automobile ( make sure Tester can't create an actual Automobile object )
    • Car
    • Truck
    • Bus
  2. Build out the classes so that Automobile is the parent of Car, Truck, and Bus.
  3. Automobile should have the following constructors:
    • Workhorse
    • One that will accept a RandomAccessFile
  4. Automobile should have the following properties:
    • vin (String)
    • gasTankSize (double)
    • currentGasLevel (double)
    • currentMiles (double)
    • milesPerGallon (double)
    • color (Color)
    • isAutomatic (boolean)
  5. 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()
  6. Automobile should force it's children to draw themself
  7. Each other class ( Car, Truck, Bus ) should override the parent's load() and save() methods in order to save and load any additional information needed that is different between the classes. For example: A Truck might have a properties: isPickUp, maxLoadCapacity, etc. Car and Bus wouldn't have have these properties so a Truck needs to save the Truck's personal data. This will apply for the other two classes.
  8. Each class ( Car, Truck, Bus ) needs to have at least 1 property specific to that class and that class only (I've already given you 2 for Truck)
  9. Each class ( Automobile, Car, Truck, Bus ) needs to have private properties with getters and setters as well as section breaks.
  10. Each class ( Car, Truck, Bus ) must have their own toString that will add the parent's toString to any additional information they have.
  11. In Tester copy and fix the code below so that it works by saving and loading the records and printing them out. You will only need 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) {} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!