Question
Create a base class Vehicle that has a make, model and year, and all its set() and get() methods, and a DisplayVehicle() method: Vehicle.java. Create
Create a base class Vehicle that has a make, model and year, and all its set() and get() methods, and a DisplayVehicle() method: Vehicle.java. Create 2 subclasses of Vehicle: Motorcylce and Truck.Motorcylce has a classification: street/off-road or dual sport, and how many wheels (there are 3 wheelers out there too lol)...include all the set() and get() methods and a DisplayMotorcycle().Truck has a drive: 2WD/4WD, and bed: long bed/short bed, and cab: regular/extended...include all the set() and get() methods, and a DisplayTruck().
Be sure to validate input to your constructor() methods where appropriate. Have 2 constructors for each class: Default constructor() that takes no parameters, and a constructor that takes parameters to initialize the attributes.
Write a short test driver program that tests your vehicles. Test Driver That uses both constructors and then uses set() and get() methods to change that objects attributes. Be sure to use your display methods to show/output the updates to your vehicle objects.
class Vehicle { private String make; private String model; private int year;
Vehicle(String make, String model, int year) { this.make = make; this.model = model; this.year = year; }
String getMake() { return make; }
String getModel() { return model; }
int getYear() { return year; }
void print() { System.out.println("Make: " + make + ", Model: " + model + ", Year: " + year); } }
Truck file below:
class Truck extends Vehicle { private double tonnage;
Truck(String make, String model, int year, double tonnage) { super(make, model, year); this.tonnage = tonnage; }
double getTonnage() { return tonnage; }
void print() { super.print(); System.out.println("Tonnage: " + tonnage); } }
Test file:
class VehicleDemo { public static void main(String[] args) { Truck truck = new Truck("Ford", "F150", 2008, 0.5); System.out.println("Make = " + truck.getMake()); System.out.println("Model = " + truck.getModel()); System.out.println("Year = " + truck.getYear()); System.out.println("Tonnage = " + truck.getTonnage()); truck.print(); } }
I'm having trouble tyring to get the motorcycle subclasses file and having it all java files work together. I'm also having trouble with truck by having the 2WD/4WD, and bed: long bed/short bed, and cab: regular/extended. Thank you.
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