diff --git a/Main.java b/Main.java index 2255c0a..c86fa06 100755 --- a/Main.java +++ b/Main.java @@ -7,216 +7,203 @@ import java.util.ArrayList; import java.util.Scanner; -class Food implements Serializable -{ +class Food implements Serializable { int itemno; - int quantity; + int quantity; float price; - - Food(int itemno,int quantity) - { - this.itemno=itemno; - this.quantity=quantity; - switch(itemno) - { - case 1:price=quantity*50; + + Food(int itemno, int quantity) { + this.itemno = itemno; + this.quantity = quantity; + switch (itemno) { + case 1: + price = quantity * 50; break; - case 2:price=quantity*60; + case 2: + price = quantity * 60; break; - case 3:price=quantity*70; + case 3: + price = quantity * 70; break; - case 4:price=quantity*30; + case 4: + price = quantity * 30; break; } } } -class Singleroom implements Serializable -{ + +class Singleroom implements Serializable { String name; String contact; - String gender; - ArrayList food =new ArrayList<>(); + String gender; + ArrayList food = new ArrayList<>(); - - Singleroom() - { - this.name=""; + + Singleroom() { + this.name = ""; } - Singleroom(String name,String contact,String gender) - { - this.name=name; - this.contact=contact; - this.gender=gender; + + Singleroom(String name, String contact, String gender) { + this.name = name; + this.contact = contact; + this.gender = gender; } } -class Doubleroom extends Singleroom implements Serializable -{ + +class doubleRoom extends Singleroom implements Serializable { String name2; String contact2; - String gender2; - - Doubleroom() - { - this.name=""; - this.name2=""; + String gender2; + + doubleRoom() { + this.name = ""; + this.name2 = ""; } - Doubleroom(String name,String contact,String gender,String name2,String contact2,String gender2) - { - this.name=name; - this.contact=contact; - this.gender=gender; - this.name2=name2; - this.contact2=contact2; - this.gender2=gender2; + + doubleRoom(String name, String contact, String gender, String name2, String contact2, String gender2) { + this.name = name; + this.contact = contact; + this.gender = gender; + this.name2 = name2; + this.contact2 = contact2; + this.gender2 = gender2; } } -class NotAvailable extends Exception -{ + +class NotAvailable extends Exception { @Override - public String toString() - { + public String toString() { return "Not Available !"; } } -class holder implements Serializable -{ - Doubleroom luxury_doublerrom[]=new Doubleroom[10]; //Luxury - Doubleroom deluxe_doublerrom[]=new Doubleroom[20]; //Deluxe - Singleroom luxury_singleerrom[]=new Singleroom[10]; //Luxury - Singleroom deluxe_singleerrom[]=new Singleroom[20]; //Deluxe +class holder implements Serializable { + doubleRoom[] luxury_doublerrom = new doubleRoom[10]; //Luxury + doubleRoom[] deluxe_doublerrom = new doubleRoom[20]; //Deluxe + Singleroom[] luxury_singleerrom = new Singleroom[10]; //Luxury + Singleroom[] deluxe_singleerrom = new Singleroom[20]; //Deluxe } -class Hotel -{ - static holder hotel_ob=new holder(); +class Hotel { + static holder hotel_ob = new holder(); static Scanner sc = new Scanner(System.in); - static void CustDetails(int i,int rn) - { + + static void CustDetails(int i, int rn) { String name, contact, gender; - String name2 = null, contact2 = null; - String gender2=""; - System.out.print("\nEnter customer name: "); + String name2 = null, contact2 = null; + String gender2 = ""; + System.out.println("Enter customer name: "); name = sc.next(); System.out.print("Enter contact number: "); - contact=sc.next(); + contact = sc.next(); System.out.print("Enter gender: "); gender = sc.next(); - if(i<3) - { - System.out.print("Enter second customer name: "); - name2 = sc.next(); - System.out.print("Enter contact number: "); - contact2=sc.next(); - System.out.print("Enter gender: "); - gender2 = sc.next(); - } - - switch (i) { - case 1:hotel_ob.luxury_doublerrom[rn]=new Doubleroom(name,contact,gender,name2,contact2,gender2); + if (i < 3) { + System.out.print("Enter second customer name: "); + name2 = sc.next(); + System.out.print("Enter contact number: "); + contact2 = sc.next(); + System.out.print("Enter gender: "); + gender2 = sc.next(); + } + + switch (i) { + case 1: + hotel_ob.luxury_doublerrom[rn] = new doubleRoom(name, contact, gender, name2, contact2, gender2); break; - case 2:hotel_ob.deluxe_doublerrom[rn]=new Doubleroom(name,contact,gender,name2,contact2,gender2); + case 2: + hotel_ob.deluxe_doublerrom[rn] = new doubleRoom(name, contact, gender, name2, contact2, gender2); break; - case 3:hotel_ob.luxury_singleerrom[rn]=new Singleroom(name,contact,gender); + case 3: + hotel_ob.luxury_singleerrom[rn] = new Singleroom(name, contact, gender); break; - case 4:hotel_ob.deluxe_singleerrom[rn]=new Singleroom(name,contact,gender); + case 4: + hotel_ob.deluxe_singleerrom[rn] = new Singleroom(name, contact, gender); break; - default:System.out.println("Wrong option"); + default: + System.out.println("Wrong option"); break; } } - - static void bookroom(int i) - { + + static void bookRoom(int i) { int j; int rn; - System.out.println("\nChoose room number from : "); + System.out.println("Choose room number from : "); switch (i) { case 1: - for(j=0;j60) - System.out.println("Room doesn't exist"); - else if(ch2>40) - Hotel.order(ch2-41,4); - else if(ch2>30) - Hotel.order(ch2-31,3); - else if(ch2>10) - Hotel.order(ch2-11,2); - else if(ch2>0) - Hotel.order(ch2-1,1); - else - System.out.println("Room doesn't exist"); - break; - case 5: - System.out.print("Room Number -"); - ch2 = sc.nextInt(); - if(ch2>60) - System.out.println("Room doesn't exist"); - else if(ch2>40) - Hotel.deallocate(ch2-41,4); - else if(ch2>30) - Hotel.deallocate(ch2-31,3); - else if(ch2>10) - Hotel.deallocate(ch2-11,2); - else if(ch2>0) - Hotel.deallocate(ch2-1,1); - else - System.out.println("Room doesn't exist"); - break; - case 6:break x; - - } - - System.out.println("\nContinue : (y/n)"); - wish=sc.next().charAt(0); - if(!(wish=='y'||wish=='Y'||wish=='n'||wish=='N')) - { - System.out.println("Invalid Option"); - System.out.println("\nContinue : (y/n)"); - wish=sc.next().charAt(0); - } - - }while(wish=='y'||wish=='Y'); - - Thread t=new Thread(new write(Hotel.hotel_ob)); - t.start(); - } - catch(Exception e) - { - System.out.println("Not a valid input"); + try { + File f = new File("backup"); + if (f.exists()) { + FileInputStream fin = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fin); + Hotel.hotel_ob = (holder) ois.readObject(); } + Scanner sc = new Scanner(System.in); + int ch, ch2; + char wish; + x: + do { + + System.out.println("\nEnter your choice :\n1.Display room details\n2.Display room availability \n3.Book\n4.Order food\n5.Checkout\n6.Exit\n"); + ch = sc.nextInt(); + switch (ch) { + case 1: + System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room \n4.Deluxe Single Room\n"); + ch2 = sc.nextInt(); + Hotel.features(ch2); + break; + case 2: + System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n"); + ch2 = sc.nextInt(); + Hotel.availability(ch2); + break; + case 3: + System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n"); + ch2 = sc.nextInt(); + Hotel.bookRoom(ch2); + break; + case 4: + System.out.print("Room Number -"); + ch2 = sc.nextInt(); + if (ch2 > 60) + System.out.println("Room doesn't exist"); + else if (ch2 > 40) + Hotel.order(ch2 - 41, 4); + else if (ch2 > 30) + Hotel.order(ch2 - 31, 3); + else if (ch2 > 10) + Hotel.order(ch2 - 11, 2); + else if (ch2 > 0) + Hotel.order(ch2 - 1, 1); + else + System.out.println("Room doesn't exist"); + break; + case 5: + System.out.print("Room Number -"); + ch2 = sc.nextInt(); + if (ch2 > 60) + System.out.println("Room doesn't exist"); + else if (ch2 > 40) + Hotel.deallocate(ch2 - 41, 4); + else if (ch2 > 30) + Hotel.deallocate(ch2 - 31, 3); + else if (ch2 > 10) + Hotel.deallocate(ch2 - 11, 2); + else if (ch2 > 0) + Hotel.deallocate(ch2 - 1, 1); + else + System.out.println("Room doesn't exist"); + break; + case 6: + break x; + + } + + System.out.println("\nContinue : (y/n)"); + wish = sc.next().charAt(0); + if (!(wish == 'y' || wish == 'Y' || wish == 'n' || wish == 'N')) { + System.out.println("Invalid Option"); + System.out.println("\nContinue : (y/n)"); + wish = sc.next().charAt(0); + } + + } while (wish == 'y' || wish == 'Y'); + + Thread t = new Thread(new write(Hotel.hotel_ob)); + t.start(); + } catch (Exception e) { + System.out.println("Not a valid input"); + } } }