Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions