Auto commit

上级 5b0ce43e
class Main { import java.util.ArrayList;
public static void main(String[] args) { import java.util.Date;
System.out.println("Hello world!"); import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class CarRentalSystem {
// 定义汽车信息类
static class Car {
private String carId;
private String make;
private String model;
private int year;
private String color;
private double price;
public Car(String carId, String make, String model, int year, String color, double price) {
this.carId = carId;
this.make = make;
this.model = model;
this.year = year;
this.color = color;
this.price = price;
}
public String getCarId() {
return carId;
}
public void setCarId(String carId) {
this.carId = carId;
}
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 int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Car{" +
"carId='" + carId + '\'' +
", make='" + make + '\'' +
", model='" + model + '\'' +
", year=" + year +
", color='" + color + '\'' +
", price=" + price +
'}';
}
}
// 定义订单信息类
static class Order {
private String orderId;
private String carId;
private String customerId;
private Date rentDate;
private Date returnDate;
private double totalAmount;
public Order(String orderId, String carId, String customerId, Date rentDate, Date returnDate, double totalAmount) {
this.orderId = orderId;
this.carId = carId;
this.customerId = customerId;
this.rentDate = rentDate;
this.returnDate = returnDate;
this.totalAmount = totalAmount;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public void setCarId(String carId) {
this.carId = carId;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public Date getRentDate() {
return rentDate;
}
public void setRentDate(Date rentDate) {
this.rentDate = rentDate;
}
public Date getReturnDate() {
return returnDate;
}
public void setReturnDate(Date returnDate) {
this.returnDate = returnDate;
}
public double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(double totalAmount) {
this.totalAmount = totalAmount;
}
@Override
public String toString() {
return "Order{" +
"orderId='" + orderId + '\'' +
", carId='" + carId + '\'' +
", customerId='" + customerId + '\'' +
", rentDate=" + rentDate +
", returnDate=" + returnDate +
", totalAmount=" + totalAmount +
'}';
}
} }
}
\ No newline at end of file public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 初始化汽车信息
Map<String, Car> carMap = new HashMap<>();
carMap.put("001", new Car("001", "Toyota", "Camry", 2019, "White", 100.0));
carMap.put("002", new Car("002", "Honda", "Accord", 2020, "Black", 120.0));
carMap.put("003", new Car("003", "Ford", "Mustang", 2021, "Red", 150.0));
carMap.put("004", new Car("004", "BMW", "X5", 2018, "Silver", 200.0));
// 初始化客户信息
Map<String, String> customerMap = new HashMap<>();
customerMap.put("001", "John");
customerMap.put("002", "Mary");
customerMap.put("003", "David");
customerMap.put("004", "Alice");
// 初始化订单信息
List<Order> orderList = new ArrayList<>();
while (true) {
// 显示菜单
System.out.println("1. Rent a car");
System.out.println("2. Return a car");
System.out.println("3. Display available cars");
System.out.println("4. Display rented cars");
System.out.println("5. Display rental history");
System.out.println("6. Exit");
// 读取用户输入的选项
System.out.print("Please enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
// 租车
System.out.print("Enter car ID: ");
String rentCarId = scanner.next();
if (!carMap.containsKey(rentCarId)) {
System.out.println("Invalid car ID.");
break;
}
System.out.print("Enter customer ID: ");
String customerId = scanner.next();
if (!customerMap.containsKey(customerId)) {
System.out.println("Invalid customer ID.");
break;
}
System.out.print("Enter rent date (yyyy-MM-dd): ");
String rentDateStr = scanner.next();
Date rentDate = new Date(rentDateStr);
Order rentOrder = new Order(
String.format("%d", orderList.size() + 1),
rentCarId,
customerId,
rentDate
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册