미니프로젝트 수정코드

William Parker·2022년 11월 27일

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class CustomerService {
private List customers;
public List reservations;
private int count = 0;
private LocalDateTime createdAt;

public List<Reservation> getReservations() {
    return reservations;
}

public CustomerService() {
    this.customers = new ArrayList<>();
    this.reservations = new ArrayList<>();
    this.createdAt = LocalDateTime.now();

}

public void customerList() {
    for (Customer customer : customers) {
        System.out.println(customer.toString());
    }
}


public Object reservationList() {
    for (Reservation reservation : reservations) {
        System.out.println(reservation.toString());
    }
    return reservations;
}

public void addCustomer(String customerName, String customerPhoneNumber, int customerMoney) {
    count++;
    Customer customer = new Customer(count, customerName, customerPhoneNumber, customerMoney);
    customers.add(customer);
    System.out.println("Success add Customer. Thanks.");
}

public void makingReservation(String roomSize, String customerName, String customerPhoneNumber, ArrayList<Room> rooms, Hotel hotel) {
    if (OtherService.validPhoneNumber(customerPhoneNumber)) {
        for (Room room : rooms) {
            if (Objects.equals(roomSize, room.getRoomSize())) {
                if (Objects.equals(room.getIsBooked(), "false")) {
                    for (Customer customer : customers) {
                        System.out.println(customerName);
                        System.out.println(customer.getCustomerName());
                        if (Objects.equals(customerName, customer.getCustomerName())) {
                            if (Objects.equals(customerPhoneNumber, customer.getCustomerPhoneNumber())) {
                                if (customer.getCustomerMoney() >= room.getRoomCharge()) {
                                    String reservationNumber = UUID.randomUUID().toString();
                                    Reservation reservation1 = new Reservation(reservationNumber, roomSize, customer.getCustomerName(), customer.getCustomerPhoneNumber(), createdAt);
                                    reservations.add(reservation1);
                                    room.setIsBooked("true");
                                    customer.setCustomerMoney(customer.getCustomerMoney() - room.getRoomCharge());
                                    hotel.setHotelIncome(hotel.getHotelIncome() + room.getRoomCharge());
                                    System.out.println(customer.getCustomerMoney());
                                    System.out.println(hotel.getHotelIncome());
                                    System.out.println("Success Booking." + reservations);
                                } else {
                                    System.out.println("Failed Money");
                                }
                            } else {
                                System.out.println("Failed phone number");
                            }
                        } else {
                            System.out.println("Failed Name");
                        }
                    }
                } else {
                    System.out.println("예약된방");
                }
            }
        }
    }
}

public void checkCustomerOwnReservation(String reservationNumber) {
    for (Reservation reservation : reservations) {
        if (Objects.equals(reservationNumber, reservation.getReservationNumber())) {
            System.out.println(reservation.toString());
        }
    }
}

public void deleteCustomerOwnReservation(String reservationNumber, ArrayList<Room> rooms, Hotel hotel) {
    for (int i = reservations.size() - 1; i >= 0; i--) {
        Reservation reservationList = reservations.get(i);
        if (reservationNumber.equals(reservationList.getReservationNumber())) {
            reservations.remove(reservationList);
            for (Room room : rooms) {
                for (Customer customer : customers) {
                    System.out.println(reservationList.getCustomerName()); //park1
                    System.out.println(customer.getCustomerName()); //park
                    if (customer.getCustomerName().equals(reservationList.getCustomerName())) {
                        room.setIsBooked("false");
                        customer.setCustomerMoney(customer.getCustomerMoney() + room.getRoomCharge());
                        hotel.setHotelIncome(hotel.getHotelIncome() - room.getRoomCharge());
                        System.out.println(hotel.getHotelIncome());
                        System.out.println(customer.getCustomerMoney());
                        System.out.println("예약취소완료");
                    }
                }
                break;
            }
        }
    }
}

}

public class Customer {
private int count;
private String customerName;
private String customerPhoneNumber;
private int customerMoney;
private Reservation reservations;

public Customer(int count,String customerName, String customerPhoneNumber, int customerMoney) {
    this.count = count;
    this.customerName = customerName;
    this.customerPhoneNumber = customerPhoneNumber;
    this.customerMoney = customerMoney;
}

public String getCustomerName() {
    return customerName;
}

public String getCustomerPhoneNumber() {
    return customerPhoneNumber;
}

public int getCustomerMoney() {
    return customerMoney;
}

public void setCustomerMoney(int customerMoney) {
    this.customerMoney = customerMoney;
}

@Override
public String toString() {
    return "Customer{" +
            "count='" + count + '\'' +
            "customerName='" + customerName + '\'' +
            ", customerPhoneNumber='" + customerPhoneNumber + '\'' +
            ", customerMoney=" + customerMoney +
            '}';
}

}

profile
Developer who does not give up and keeps on going.

0개의 댓글