1 changed files with 0 additions and 77 deletions
@ -1,77 +0,0 @@ |
|||||
package com.rental; |
|
||||
public class Car { |
|
||||
private String licensePlate; |
|
||||
private String brand; |
|
||||
private String model; |
|
||||
private double dailyRent; |
|
||||
private boolean isRented; |
|
||||
private static int totalCars = 0; |
|
||||
public Car(String licensePlate, String brand, String model, double dailyRent) { |
|
||||
this.licensePlate = licensePlate; |
|
||||
this.brand = brand; |
|
||||
this.model = model; |
|
||||
this.dailyRent = dailyRent; |
|
||||
this.isRented = false; |
|
||||
totalCars++; |
|
||||
} |
|
||||
public Car(String licensePlate, String brand, String model) { |
|
||||
this(licensePlate, brand, model, 300.0); |
|
||||
} |
|
||||
public String getLicensePlate() { |
|
||||
return licensePlate; |
|
||||
} |
|
||||
public String getBrand() { |
|
||||
return brand; |
|
||||
} |
|
||||
public void setBrand(String brand) { |
|
||||
this.brand = brand; |
|
||||
} |
|
||||
public String getModel() { |
|
||||
return model; |
|
||||
} |
|
||||
public void setModel(String model) { |
|
||||
this.model = model; |
|
||||
} |
|
||||
public double getDailyRent() { |
|
||||
return dailyRent; |
|
||||
} |
|
||||
public void setDailyRent(double dailyRent) { |
|
||||
if (dailyRent > 0) { |
|
||||
this.dailyRent = dailyRent; |
|
||||
} else { |
|
||||
System.out.println("Daily rent must be greater than 0, modification failed"); |
|
||||
} |
|
||||
} |
|
||||
public boolean isRented() { |
|
||||
return isRented; |
|
||||
} |
|
||||
public void rentCar() { |
|
||||
if (isRented) { |
|
||||
System.out.println("The car is already rented and cannot be rented again"); |
|
||||
} else { |
|
||||
isRented = true; |
|
||||
System.out.println("Car rented successfully"); |
|
||||
} |
|
||||
} |
|
||||
public void returnCar() { |
|
||||
if (!isRented) { |
|
||||
System.out.println("The car is not rented, no need to return"); |
|
||||
} else { |
|
||||
isRented = false; |
|
||||
System.out.println("Car returned successfully"); |
|
||||
} |
|
||||
} |
|
||||
public double calculateRent(int days) { |
|
||||
return dailyRent * days; |
|
||||
} |
|
||||
public static int getTotalCars() { |
|
||||
return totalCars; |
|
||||
} |
|
||||
public void displayInfo() { |
|
||||
System.out.println("License Plate: " + licensePlate |
|
||||
+ ", Brand: " + brand |
|
||||
+ ", Model: " + model |
|
||||
+ ", Daily Rent: " + dailyRent |
|
||||
+ ", Status: " + (isRented ? "Rented" : "Available")); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue