to develop an object-oriented application. They provide trucks, cars, and bikes on rent for a maximum period of 5 days, and if the number of days increases they double the rent for the extra days. They have different cars like luxury, sports and ordinary and all of them are powered by both electricity and petrol while trucks have only petrol option. In the case of bikes, they have electric street-bike and sportbikes have only petrol option. Further, the choice of the customer for the trucks is based upon weight, length, and wheels. The owner of the company can add, view and update vehicle, customer, and employee information.
interface Vechicle {
final int pricePerDailyRent=0;
public static final Powered powered = null;
}
interface Bike extends Vechicle{
}
interface Car extends Vechicle{
}
public class Track implements Vechicle {
private int countOfWheels;
private double weight;
private double length;
public Track() {
}
public Track(int countOfWheels, double weight, double length) {
this.countOfWheels = countOfWheels;
this.weight = weight;
this.length = length;
}
public int getCountOfWheels() {
return countOfWheels;
}
public void setCountOfWheels(int countOfWheels) {
this.countOfWheels = countOfWheels;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
@Override
public String toString() {
return "Track [countOfWheels=" + countOfWheels + ", weight=" + weight + ", length=" + length + "]";
}
}
public class SportsCar implements Car{
public SportsCar() {
}
}
public class LuxuryCar implements Car {
public LuxuryCar() {
}
}
public enum Powered {
electrinity, petrol
}
public class ElectricStreetBike implements Bike{
}
public class SportBike implements Bike{
}
import java.util.List;
public class Customer {
OrderingSystem orderingSystem;
Vechicle vechicle;
public List<Vechicle> ordering(Vechicle vechicle, int dayForOrder) {
List<Vechicle> newList;
for (Vechicle vh : orderingSystem.getVechicless()) {
if (vh.equals(vechicle))
orderingSystem.getVechicless().remove(vh);
}
newList = orderingSystem.getVechicless();
return newList;
}
void payment(int daysForOrdering, int pricePerDailyRent) {
int payment = 0;
if (daysForOrdering <= 5) {
payment = daysForOrdering * pricePerDailyRent;
System.out.println("You should pay for renting: " + payment);
} else if (daysForOrdering > 5) {
payment = daysForOrdering * pricePerDailyRent * 2;
System.out.println("You should pay for renting: " + payment);
}
}
public List<Vechicle> returnVechicle(Vechicle vechicle) {
List<Vechicle> newList = orderingSystem.getVechicless();
newList.add(vechicle);
return newList;
}
}
import java.util.List;
public class OrderingSystem {
private List<Vechicle> vechicless;
public List<Vechicle> getVechicless() {
return vechicless;
}
public void setVechicless(List<Vechicle> vechicless) {
this.vechicless = vechicless;
}
}
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) {
Customer customer=new Customer();
OrderingSystem orderingSystem=new OrderingSystem();
Vechicle bmw=new SportsCar();
List<Vechicle>vechicles=new ArrayList<>();
}
}
Comments
Leave a comment