Answered step by step
Verified Expert Solution
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
- Add the following classes to your project
- Tester
- Automobile ( make sure Tester can't create an 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 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.
- 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)
- Each class ( Automobile, Car, Truck, Bus ) needs to have private properties with getters and setters as well as section breaks.
- Each class ( Car, Truck, Bus ) must have their own toString that will add the parent's toString to any additional information they have.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started