In: Computer Science
import java.util.ArrayList;
import java.util.Scanner;
class Room{
String firstname,lastname,roomgrade;
int phoneNumber;
public Room(String firstName,String lastName, int phone, String
roomGrade ){
this.firstname = firstName;
this.lastname = lastName;
this.phoneNumber = phone;
this.roomgrade = roomGrade;
}
void printDetails(){
System.out.println("Name :" +this.firstname +" " +
this.lastname);
System.out.println("Phone: " + this.phoneNumber);
System.out.println("Room Grade :" + this.roomgrade);
System.out.println("Payment : " + this.payment());
}
int payment(){
if (this.roomgrade == "Suite")
return 600;
else if (this.roomgrade.equals("Delux"))
return 250;
else
return 100;
}
}
public class Main {
public static void main() {
ArrayList<Room> customersA = new
ArrayList<Room>();
ArrayList<Room> customersB = new
ArrayList<Room>();
int enex = 0;
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Enter 1 for entry 0 for exit of customer!
:");
enex = sc.nextInt();
if (enex == 1)
entry(customersA, customersB);
if (enex == 0) {
System.out.println("Enter First Name: ");
String firstname = sc.next();
System.out.println("Enter Last Name: ");
String lastname = sc.next();
System.out.println("ENter Phone number: ");
int phone = sc.nextInt();
exit(firstname, lastname, phone, customersA, customersB);
}
}
}
public static void exit(String firstName, String lastName, int phone, ArrayList<Room> customersA, ArrayList<Room> customersB) {
int Asize = customersA.size();
int Bsize = customersB.size();
for (int i = 0; i < Math.max(Asize, Bsize); i++) {
if (i < Asize)
if (customersA.get(i).firstname.equals(firstName)) {
if (customersA.get(i).lastname.equals(lastName)) {
if (customersA.get(i).phoneNumber == phone) {
customersA.get(i).printDetails();
customersA.remove(customersA.get(i));
}
}
}
if (i < Bsize)
if (customersB.get(i).firstname.equals(firstName)) {
if (customersB.get(i).lastname.equals((lastName))) {
if (customersB.get(i).phoneNumber == phone) {
customersB.get(i).printDetails();
customersB.remove(customersB.get(i));
}
}
}
}
}
public static void entry(ArrayList<Room> customersA, ArrayList<Room> customersB) {
int totalCustomers = 0;
int occupiedStandardA = 0;
int occupiedStandardB = 0;
int occupiedDeluxA = 0;
int occupiedDeluxB = 0;
int occupiedSuiteA = 0;
int occupiedSuiteB = 0;
String firstName = "";
String lastName = "";
int phone = 0;
String roomGrade = "";
Scanner sc = new Scanner(System.in);
char exit = ' ';
while (exit != 'Y' || exit != 'y') {
System.out.println("Enter first Name: ");
firstName = sc.next();
System.out.println("Enter Last Name: ");
lastName = sc.next();
System.out.println("Enter Phone Number: ");
phone = sc.nextInt();
System.out.println("Enter Room Grade(Standard, Delux, Suite):
");
roomGrade = sc.next();
System.out.println("Exit [Y/N]");
exit = sc.next().strip().charAt(0);
if (roomGrade.equals("Standard")) {
if (occupiedStandardA < 10) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedStandardA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedStandardB < 8) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedStandardB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Standard Rooms Available!!");
} else if (roomGrade.equals("Dulex")) {
if (occupiedDeluxA < 5) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedDeluxA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedDeluxB < 4) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedDeluxB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Delux Rooms Available!!");
} else if (roomGrade.equals("Suite")) {
if (occupiedSuiteA < 5) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedSuiteA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedSuiteB < 4) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedSuiteB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Suite Available!!");
} else
System.out.println("No Rooms Available!!");
}
}
}