Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please find the code below::: Vehicle.java package automobiles; import java.text.NumberFormat; import java.util.Locale; public class Vehicle { private String make; private String model; private boolean isFourWheeler;

image text in transcribed

Please find the code below:::

Vehicle.java

package automobiles;

import java.text.NumberFormat;

import java.util.Locale;

public class Vehicle {

private String make;

private String model;

private boolean isFourWheeler;

private double retailPrice;

private double milesPerGallon;

NumberFormat formatter=NumberFormat.getCurrencyInstance(Locale.US);

public Vehicle(String make, String model, boolean isFourWheeler, double retailPrice, double milesPerGallon) {

super();

this.make = make;

this.model = model;

this.isFourWheeler = isFourWheeler;

this.retailPrice = retailPrice;

this.milesPerGallon = milesPerGallon;

}

public String getMake() {

return make;

}

public void setMake(String make) {

this.make = make;

}

public String getModel() {

return model;

}

public void setModel(String model) {

this.model = model;

}

public boolean isFourWheeler() {

return isFourWheeler;

}

public void setFourWheeler(boolean isFourWheeler) {

this.isFourWheeler = isFourWheeler;

}

public double getRetailPrice() {

return retailPrice;

}

public void setRetailPrice(double retailPrice) {

this.retailPrice = retailPrice;

}

public double getMilesPerGallon() {

return milesPerGallon;

}

public void setMilesPerGallon(double milesPerGallon) {

this.milesPerGallon = milesPerGallon;

}

public void printVehicle(){

System.out.println("Printing car details");

}

@Override

public String toString() {

String fourWheeler ="4WD ";

if(!isFourWheeler){

fourWheeler = "Not a "+fourWheeler;

}

String cost=formatter.format(retailPrice)+" ";

return make+" "+model+" "+fourWheeler+cost+milesPerGallon+" MPG ";

}

}

Car.java

package automobiles;

public class Car extends Vehicle {

private boolean isConvertible;

public Car(String make, String model, boolean isFourWheeler, double retailPrice, double milesPerGallon,boolean isConvertible) {

super(make, model, isFourWheeler, retailPrice, milesPerGallon);

this.isConvertible = isConvertible;

// TODO Auto-generated constructor stub

}

public boolean isConvertible() {

return isConvertible;

}

public void setConvertible(boolean isConvertible) {

this.isConvertible = isConvertible;

}

@Override

public String toString() {

return "Car [isConvertible=" + isConvertible + "]";

}

public void printVehicle(){

System.out.println("Detials for Car");

String hasConvertible="";

if(isConvertible){

hasConvertible="Support Convertible ";

}else{

hasConvertible="Does not have Convertible ";

}

System.out.println(super.toString()+hasConvertible);

}

}

Truck.java

package automobiles;

public class Truck extends Vehicle {

private boolean hasSlideStep;

private double towCapacity;

public Truck(String make, String model, boolean isFourWheeler, double retailPrice, double milesPerGallon, boolean slideStep, int towCap) {

super(make, model, isFourWheeler, retailPrice, milesPerGallon);

this.hasSlideStep = slideStep;

this.towCapacity = towCap;

}

public void printVehicle(){

System.out.println("Detials for truck");

String slideStep="";

if(hasSlideStep){

slideStep="Havinng Slide Step ";

}else{

slideStep="No Slide Step ";

}

String towCap = "Tow up to "+towCapacity+" tons";

System.out.println(super.toString()+slideStep+towCap+" ");

}

}

Tester.java

package automobiles;

public class Tester {

public static void main(String[] args) {

Car c1 = new Car("2015","Farrai c5", true, 12000, 13, true);

Car c2 = new Car("2012","BMW", false, 99000, 20, false);

Truck t1 = new Truck("2015","Ford F-150", true, 35000, 17, false,2);

Truck t2 = new Truck("2002","TATA C-999", true, 99000, 66, true,9);

Vehicle vehicles[] = {c1,c2,t1,t2};

for(Vehicle vehi : vehicles){

vehi.printVehicle();

}

}

}

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

ISBN: 0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago