I NEED IT BY DRJAVA PROGRAM//// Lab 17 Fleet of Vehicles Objective: Write a clas
ID: 3605754 • Letter: I
Question
I NEED IT BY DRJAVA PROGRAM////
Lab 17
Fleet of Vehicles
Objective:
Write a classes that represents a vehicle system
First download the driver and put it in your project
DO NOT ALTER THE DRIVER!
Write a class file called Vehicle
Some of the attributes are
Manufacturer’s name
Number of Cylinders (must be greater than 0)
Owner’s name
Create the following Constructors
Default – sets everything to default values
Parameterized Constructor
Check for valid values
Accessors and Mutators for each variable
MAKE SURE THE MUTATORS CHECK FOR VALID VALUES!
Create the following Methods
equals – takes in another instance of a Vehicle and returns true only if the names and the number of cylinders are equal
toString – returns a String that contains the Manufacturer’s name, number of cylinders, and the owners name
Write another class Truck which is a Vehicle
Some of the attributes of Truck are
Load capacity: a nonnegative number of tons represented by a decimal number
Towing capacity: a nonnegative number of tons represented by a decimal
Create the following constructorsDefault – sets everything to default values
This includes calling the Vehicle’s default constructor
Parameterized Constructor
This must also take in via parameter the manufacturer’s name, number of cylinders, and the owner’s name in addition to the load and towing capacity.
Accessors and Mutators for each variable
MAKE SURE THE MUTATORS CHECK FOR VALID VALUES!
Create the following methods
equals – This should override the vehicle’s equals method return true if all the properties of vehicle and truck are equal
toString – This should also override the vehicle’s toString method and also return the Vehicle’s toString along with the towing and load capacity
Write another class Car which is a Vehicle
Some of the attributes of Truck are
Gas Mileage: a nonnegative number of gallons represented by a decimal number
Number of passengers: a nonnegative number of passengers represented by a whole number
Create the following constructorsDefault – sets everything to default values
This includes calling the Vehicle’s default constructor
Parameterized Constructor
This must also take in via parameter the manufacturer’s name, number of cylinders, and the owner’s name in addition to the load and towing capacity.
Accessors and Mutators for each variable
MAKE SURE THE MUTATORS CHECK FOR VALID VALUES!
Create the following methods
equals – This should override the vehicle’s equals method return true if all the properties of vehicle and car are equal
toString – This should also override the vehicle’s toString method and also return the Vehicle’s toString along with the gas mileage and number of passengers
Example Dialog:
Welcome to the fleet manager
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
1
Enter 1: if it is a car
Enter 2: if it is a truck
Enter 3: if it is unclassified
1
Enter the manufacturer's name
Nissan
Enter the number of cylinders
6
Enter the owner's name
JJ
Enter the car's gas mileage
29
Enter the number of passengers
5
The Fleet currently
Manufacturer's Name: Nissan
Number Of Cylinders: 6
Owner's Name: JJ
Gas Mileage: 29.0
Number of Passengers: 5
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
1
Enter 1: if it is a car
Enter 2: if it is a truck
Enter 3: if it is unclassified
2
Enter the manufacturer's name
Chevy
Enter the number of cylinders
8
Enter the owner's name
Eddie
Enter the truck's load capacity
1
Enter the truck's towing capacity
2
The Fleet currently
Manufacturer's Name: Nissan
Number Of Cylinders: 6
Owner's Name: JJ
Gas Mileage: 29.0
Number of Passengers: 5
Manufacturer's Name: Chevy
Number Of Cylinders: 8
Owner's Name: Eddie
Towing Capacity: 2.0
Load Capacity: 1.0
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
1
Enter 1: if it is a car
Enter 2: if it is a truck
Enter 3: if it is unclassified
3
Enter the manufacturer's name
Ford
Enter the number of cylinders
6
Enter the owner's name
Bob
The Fleet currently
Manufacturer's Name: Nissan
Number Of Cylinders: 6
Owner's Name: JJ
Gas Mileage: 29.0
Number of Passengers: 5
Manufacturer's Name: Chevy
Number Of Cylinders: 8
Owner's Name: Eddie
Towing Capacity: 2.0
Load Capacity: 1.0
Manufacturer's Name: Ford
Number Of Cylinders: 6
Owner's Name: Bob
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
2
Enter 1: if it is a car
Enter 2: if it is a truck
Enter 3: if it is unclassified
2
Enter the manufacturer's name
Chevy
Enter the number of cylinders
8
Enter the owner's name
Eddie
Enter the truck's load capacity
1
Enter the truck's towing capacity
2
The Fleet currently
Manufacturer's Name: Nissan
Number Of Cylinders: 6
Owner's Name: JJ
Gas Mileage: 29.0
Number of Passengers: 5
Manufacturer's Name: Ford
Number Of Cylinders: 6
Owner's Name: Bob
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
9
The Fleet currently
Manufacturer's Name: Nissan
Number Of Cylinders: 6
Owner's Name: JJ
Gas Mileage: 29.0
Number of Passengers: 5
Manufacturer's Name: Ford
Number Of Cylinders: 6
Owner's Name: Bob
Goodbye
Explanation / Answer
Vehicle.java:
import java.util.Scanner;
//A class that keeps a track of vehicles
public class Vehicle{
private String manufacturerName;
private int numOfCylinders;
private String ownerName;
public Vehicle(){
manufacturerName = "";
ownerName = "";
numOfCylinders = 1;
}
public Vehicle(String mn, int nc, String on){
manufacturerName = mn;
ownerName = on;
if(nc > 0)
numOfCylinders = nc;
else
numOfCylinders = 1;
}
// Accessors
public String getMN(){
return manufacturerName;
}
public String getON(){
return ownerName;
}
public int getNC(){
return numOfCylinders;
}
// Mutators
public void setMN(String mn){
manufacturerName = mn;
}
public void setON(String on){
ownerName = on;
}
public void setNC(int nc){
if(nc > 0)
numOfCylinders = nc;
}
// Other Functions
public boolean equals(Vehicle vc){
if(numOfCylinders==vc.numOfCylinders && ownerName == vc.ownerName && manufacturerName == vc.manufacturerName){
return true;
}
else
return false;
}
public String toString(){
return manufacturerName + ", "+ numOfCylinders+ ", "+ ownerName;
}
}
==============================================================================
Truck.java
import java.util.Scanner;
//A class that keeps a track of vehicles
public class Truck extends Vehicle{
private double loadCapacity;
private double towingCapacity;
public Truck(){
super();
loadCapacity = 0.0;
towingCapacity = 0.0;
}
public Truck(String mn, int nc, String on, double lc, double tc){
super(mn,nc,on);
if(lc>0)
loadCapacity = lc;
else
loadCapacity = 0.0;
if(tc>0)
towingCapacity = tc;
else
towingCapacity = 0.0;
}
// Accessors
public double getLC(){
return loadCapacity;
}
public double getTC(){
return towingCapacity;
}
// Mutators
public void setLC(double lc){
if(lc>0)
loadCapacity = lc;
else
loadCapacity = 0.0;
}
public void setTC(double tc){
if(tc>0)
towingCapacity = tc;
else
towingCapacity = 0.0;
}
// Other Functions
public boolean equals(Truck t){
boolean isVehicle = super.equals(t);
if(towingCapacity==t.towingCapacity && loadCapacity == t.loadCapacity && isVehicle){
return true;
}
else
return false;
}
public String toString(){
return loadCapacity + ", "+ towingCapacity+ ", "+ super.toString();
}
}
==================================================================================
Car.java
import java.util.Scanner;
//A class that keeps a track of vehicles
public class Car extends Vehicle{
private double gasMileage;
private int passengerCount;
public Car(){
super();
gasMileage = 0.0;
passengerCount = 0;
}
public Car(String mn, int nc, String on, double gm, int pc){
super(mn,nc,on);
if(gm>0)
gasMileage = gm;
else
gasMileage = 0.0;
if(pc>0)
passengerCount = pc;
else
passengerCount = 0;
}
// Accessors
public double getGM(){
return gasMileage;
}
public int getPC(){
return passengerCount;
}
// Mutators
public void setPC(int pc){
if(pc>0)
passengerCount = pc;
else
passengerCount = 0;
}
public void setGM(double gm){
if(gm>0)
gasMileage = gm;
else
gasMileage = 0.0;
}
// Other Functions
public boolean equals(Car c){
boolean isVehicle = super.equals(c);
if(gasMileage==c.gasMileage && passengerCount == c.passengerCount && isVehicle){
return true;
}
else
return false;
}
public String toString(){
return gasMileage + ", "+ passengerCount+ ", "+ super.toString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.