From 2eaef79fab7d356ac78db3b12b13edb4d6d194d2 Mon Sep 17 00:00:00 2001 From: KyleYin <131144602+KyleWinter@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:13:11 +0800 Subject: [PATCH] Add files via upload --- Main.java | 1235 ++++++++++++++++++++++++++++------------------------- 1 file changed, 647 insertions(+), 588 deletions(-) diff --git a/Main.java b/Main.java index 2255c0a..cefe496 100755 --- a/Main.java +++ b/Main.java @@ -1,588 +1,647 @@ -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Scanner; - -class Food implements Serializable -{ - int itemno; - int quantity; - float price; - - Food(int itemno,int quantity) - { - this.itemno=itemno; - this.quantity=quantity; - switch(itemno) - { - case 1:price=quantity*50; - break; - case 2:price=quantity*60; - break; - case 3:price=quantity*70; - break; - case 4:price=quantity*30; - break; - } - } -} -class Singleroom implements Serializable -{ - String name; - String contact; - String gender; - ArrayList food =new ArrayList<>(); - - - Singleroom() - { - this.name=""; - } - Singleroom(String name,String contact,String gender) - { - this.name=name; - this.contact=contact; - this.gender=gender; - } -} -class Doubleroom extends Singleroom implements Serializable -{ - String name2; - String contact2; - 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; - } -} -class NotAvailable extends Exception -{ - @Override - 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 Hotel -{ - static holder hotel_ob=new holder(); - static Scanner sc = new Scanner(System.in); - static void CustDetails(int i,int rn) - { - String name, contact, gender; - String name2 = null, contact2 = null; - String gender2=""; - System.out.print("\nEnter customer name: "); - name = sc.next(); - System.out.print("Enter contact number: "); - 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); - break; - 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); - break; - case 4:hotel_ob.deluxe_singleerrom[rn]=new Singleroom(name,contact,gender); - break; - default:System.out.println("Wrong option"); - break; - } - } - - static void bookroom(int i) - { - int j; - int rn; - System.out.println("\nChoose 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"); - } - } -} +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Scanner; + +class Food implements Serializable +{ + int itemno; + int quantity; + float price; + + Food(int itemno,int quantity) + { + this.itemno=itemno; + this.quantity=quantity; + switch(itemno) + { + case 1:price=quantity*50; + break; + case 2:price=quantity*60; + break; + case 3:price=quantity*70; + break; + case 4:price=quantity*30; + break; + } + } +} +class Singleroom implements Serializable +{ + String name; + String contact; + String gender; + ArrayList food =new ArrayList<>(); + + + Singleroom() + { + this.name=""; + } + Singleroom(String name,String contact,String gender) + { + this.name=name; + this.contact=contact; + this.gender=gender; + } +} +class Doubleroom extends Singleroom implements Serializable +{ + String name2; + String contact2; + 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; + } +} +class NotAvailable extends Exception +{ + @Override + 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 Hotel +{ + static holder hotel_ob=new holder(); + static Scanner sc = new Scanner(System.in); + static void CustDetails(int i,int rn) + { + String name, contact, gender; + String name2 = null, contact2 = null; + String gender2=""; + System.out.print("\nEnter customer name: "); + name = sc.next(); + System.out.print("Enter contact number: "); + 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); + break; + 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); + break; + case 4:hotel_ob.deluxe_singleerrom[rn]=new Singleroom(name,contact,gender); + break; + default:System.out.println("Wrong option"); + break; + } + } + + static void bookroom(int i) + { + int j; + int rn; + System.out.println("\nChoose room number from : "); + switch (i) { + case 1: + for(j=0;j= min && result <= max) + break; + else { + System.out.println("Your input number should be greater than or equal to " + min + " and less than or equal to " + max + ". Please try again."); + } + } + return result; + } + + + // Get a numeric string + public int getNumStr(Scanner scanner) { + int result; + while (true) { + while (!scanner.hasNextInt()) { + scanner.next(); + System.out.println("Your input string should not contain non-numeric characters."); + } + result = scanner.nextInt(); + break; + } + return result; + } +} + +public class Main { + public static void main(String[] args){ + + 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 = MyFormatter.getInstance().getInt(1,6,sc); + 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 = MyFormatter.getInstance().getInt(1,4,sc); + 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 = MyFormatter.getInstance().getInt(1,4,sc); + 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 = MyFormatter.getInstance().getInt(1,4,sc); + Hotel.bookroom(ch2); + break; + case 4: + System.out.print("Room Number -"); + ch2 = MyFormatter.getInstance().getInt(sc); + 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 = MyFormatter.getInstance().getInt(sc); + 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"); + } + } +} \ No newline at end of file