Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change your Vehicle, Truck and Motorcycle Classes to be more robust by including exception options for their constructor methods and their set methods. Re-write your

Change your Vehicle, Truck and Motorcycle Classes to be more robust by including exception options for their constructor methods and their set methods.

Re-write your VehicleTest.java program to "handle" any exceptions.

Vehicle.java

01: public class Vehicle 02: { 03: private String make; 04: private String model; 05: private double year; 06: 07: public Vehicle() 08: {} 09: public Vehicle( String mak, String mod, double yea) 10: { 11: make = mak; 12: model = mod; 13: year = yea; 14: } 15: 16: 17: public void setMake( String mak) 18: { 19: make = mak; 20: } 21: 22: public String getMake() 23: { 24: return make; 25: } 26: 27: public void setModel( String mod) 28: { 29: model = mod; 30: } 31: 32: public String getModel() 33: { 34: return model; 35: } 36: 37: public void setYear(double yea) 38: { 39: year = yea; 40: } 41: 42: public double getYear() 43: { 44: return year; 45: } 46: 47: public void Display() 48: { 49: 50: System.out.println("make: " + getMake()); 51: System.out.println("model: " + getModel()); 52: System.out.println("year: " + getYear()); 53: } 54: } 55:

truck.java

File: /home/ax/Downloads/Truck-1.java 01: public class Truck extends Vehicle 02: { 03: private String drive; 04: private String bed; 05: private String cab; 06: 07: public Truck() 08: {} 09: 10: public Truck(String d, String b, String c) 11: { 12: drive = d; 13: bed = b; 14: cab = c; 15: } 16: 17: public void setDrive(String d) 18: { 19: drive = d; 20: } 21: 22: public String getDrive() 23: { 24: return drive; 25: } 26: 27: public void setBed(String b) 28: { 29: bed = b; 30: } 31: 32: public String getBed() 33: { 34: return bed; 35: } 36: 37: public void setCab(String c) 38: { 39: cab = c; 40: } 41: 42: public String getCab() 43: { 44: return cab; 45: } 46: 47: public void Display() 48: { 49: System.out.println("Drive: " + getDrive()); 50: System.out.println("Bed Type: " + getBed()); 51: System.out.println("Cab Type: " + getCab()); 52: } 53: } 54:

motorcycle.java

File: /home/ax/Downloads/Motorcycle-1.java 01: public class Motorcycle extends Vehicle 02: { 03: private String type; 04: private String wheels; 05: 06: public Motorcycle() 07: {} 08: public Motorcycle( String t, String w) 09: { 10: type = t; 11: wheels = w; 12: } 13: 14: public void setType( String t) 15: { 16: type = t; 17: } 18: 19: public String getType() 20: { 21: return type; 22: } 23: 24: public void setWheels(String w) 25: { 26: wheels = w; 27: } 28: 29: public String getWheels() 30: { 31: return wheels; 32: } 33: 34: public void Display() 35: { 36: System.out.println("Type: " + getType()); 37: System.out.println("Wheels: " + getWheels()); 38: } 39: }

vehicleTest.java

File: /home/ax/Desktop/javacode/VehicleTest.java 01: public class VehicleTest 02: { 03: public static void main(String args[]) 04: { 05: Vehicle vehicle = new Vehicle("Dodge","Ram", 2017); 06: Truck truck = new Truck("4WD", "long", "regular"); 07: Motorcycle motorcycle = new Motorcycle("Street", "2 Wheeler"); 08: 09: vehicle.Display(); 10: truck.Display(); 11: 12: System.out.println("New Truck:"); 13: 14: 15: vehicle.setMake("Ford"); 16: vehicle.getMake(); 17: vehicle.setModel("Raptor"); 18: vehicle.getModel(); 19: vehicle.setYear(2016); 20: vehicle.getYear(); 21: truck.setDrive("2WD"); 22: truck.getDrive(); 23: truck.setBed("short"); 24: truck.getBed(); 25: truck.setCab("extended"); 26: truck.getCab(); 27: 28: 29: vehicle.Display(); 30: truck.Display(); 31: 32: System.out.println("MotorCycle:"); 33: 34: vehicle.setMake("Suszuki"); 35: vehicle.getMake(); 36: vehicle.setModel("Hayabusa"); 37: vehicle.getModel(); 38: vehicle.setYear(2016); 39: vehicle.getYear(); 40: 41: vehicle.Display(); 42: motorcycle.Display(); 43: 44: System.out.println ("New MotorCycle:"); 45: vehicle.setMake("Kawasaki"); 46: vehicle.getMake(); 47: vehicle.setModel("ninja"); 48: vehicle.getModel(); 49: vehicle.setYear(2017); 50: vehicle.getYear(); 51: motorcycle.setType("Dual Road"); 52: motorcycle.getType(); 53: motorcycle.setWheels("3 Wheels"); 54: motorcycle.getWheels(); 55: 56: vehicle.Display(); 57: motorcycle.Display(); 58: 59: } 60: }

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago