Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Driverimport java.util.Scanner;A class that keeps a f.pdf
1. Driver:
import java.util.Scanner;
//A class that keeps a fleet of different types of vehicles
public class FleetOfVehicles {
//An array of vehicles
private Vehicle[] fleet;
public static final int MAX_VEHICLES = 100;
public FleetOfVehicles()
{
fleet = new Vehicle[MAX_VEHICLES];
}
public Vehicle[] getFleet()
{
return this.fleet;
}
//Adds a new vehicle to the first empty spot in the fleet array
public void addVehicle(Vehicle aV)
{
for(int i=0;i
Solution
import java.util.Scanner;
//A class that keeps a fleet of different types of vehicles
public class FleetOfVehicles {
//An array of vehicles
private Vehicle[] fleet;
public static final int MAX_VEHICLES = 100;
public FleetOfVehicles()
{
fleet = new Vehicle[MAX_VEHICLES];
2. }
public Vehicle[] getFleet()
{
return this.fleet;
}
//Adds a new vehicle to the first empty spot in the fleet array
public void addVehicle(Vehicle aV)
{
for(int i=0;i 0)
this.cylinders = cylinders;
else
this.cylinders = 0;
}
/**
* @return the ownersName
*/
public String getOwnersName() {
return ownersName;
}
/**
* @param ownersName
* the ownersName to set
*/
public void setOwnersName(String ownersName) {
this.ownersName = ownersName;
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (obj instanceof Vehicle) {
Vehicle vehicle = (Vehicle) obj;
if ((this.getManuName().equals(vehicle.getManuName()))
&& (this.getOwnersName().equals(vehicle.getOwnersName()))
&& (this.getCylinders() == vehicle.getCylinders()))
return true;
else
3. return false;
} else
return false;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return getManuName() + " " + getCylinders() + " " + getOwnersName();
}
}
public class Truck extends Vehicle {
double loadCap, towCap;
public Truck() {
// TODO Auto-generated constructor stub
super();
setLoadCap(0);
setTowCap(0);
}
/**
* @param manuName
* @param cylinders
* @param ownersName
* @param loadCap
* @param towCap
*/
public Truck(String manuName, int cylinders, String ownersName,
double loadCap, double towCap) {
super(manuName, cylinders, ownersName);
setLoadCap(loadCap);
setTowCap(towCap);
}
/**
* @return the loadCap
*/
public double getLoadCap() {
4. return loadCap;
}
/**
* @param loadCap
* the loadCap to set
*/
public void setLoadCap(double loadCap) {
if (loadCap > 0)
this.loadCap = loadCap;
else
this.loadCap = 0;
}
/**
* @return the towCap
*/
public double getTowCap() {
return towCap;
}
/**
* @param towCap
* the towCap to set
*/
public void setTowCap(double towCap) {
if (towCap > 0)
this.towCap = towCap;
else
this.towCap = 0;
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (obj instanceof Truck) {
if (super.equals(obj)) {
Truck vehicle = (Truck) obj;
if (this.getLoadCap() == vehicle.getLoadCap()
&& this.getTowCap() == vehicle.getTowCap())
5. return true;
else
return false;
} else
return false;
} else
return false;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " " + getTowCap() + " " + getLoadCap();
}
}
public class Car extends Vehicle {
double mileage;
int passengers;
public Car() {
// TODO Auto-generated constructor stub
super();
setMileage(0);
setPassengers(0);
}
/**
* @param manuName
* @param cylinders
* @param ownersName
* @param mileage
* @param passengers
*
*/
public Car(String manuName, int cylinders, String ownersName,
double mileage, int passengers) {
super(manuName, cylinders, ownersName);
setMileage(mileage);
6. setPassengers(passengers);
}
/**
* @return the mileage
*/
public double getMileage() {
return mileage;
}
/**
* @param mileage
* the mileage to set
*/
public void setMileage(double mileage) {
if (mileage > 0)
this.mileage = mileage;
else
this.mileage = 0;
}
/**
* @return the passengers
*/
public int getPassengers() {
return passengers;
}
/**
* @param passengers
* the passengers to set
*/
public void setPassengers(int passengers) {
if (passengers > 0)
this.passengers = passengers;
else
this.passengers = 0;
}
@Override
public boolean equals(Object obj) {
7. // TODO Auto-generated method stub
if (obj instanceof Car) {
if (super.equals(obj)) {
Car vehicle = (Car) obj;
if (this.getMileage() == vehicle.getMileage()
&& this.getPassengers() == vehicle.getPassengers())
return true;
else
return false;
} else
return false;
} else
return false;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " " + getPassengers() + " " + getMileage();
}
}
OUTPUT:
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
Skoda
Enter the number of cylinders
2
Enter the owner's name
8. Srinivas
Enter the car's gas mileage
25
Enter the number of passengers
4
The Fleet currently
Skoda 2 Srinivas 4 25.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
2
Enter the manufacturer's name
Hyundai
Enter the number of cylinders
3
Enter the owner's name
Rajesh
Enter the truck's load capacity
522
Enter the truck's towing capacity
45
The Fleet currently
Skoda 2 Srinivas 4 25.0
Hyundai 3 Rajesh 45.0 522.0
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
1
9. Enter the manufacturer's name
Skoda
Enter the number of cylinders
2
Enter the owner's name
Srinivas
Enter the car's gas mileage
25
Enter the number of passengers
4
The Fleet currently
Hyundai 3 Rajesh 45.0 522.0
Enter 1: to add a Vehicle
Enter 2: to remove a Vehicle
Enter 9 to quit
9
The Fleet currently
Hyundai 3 Rajesh 45.0 522.0
Goodbye