-
-
Save Godfreythuo80/98e8d7c6aa7e2de19b6696e33181eefe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Calendar; | |
| import java.util.Date; | |
| import java.util.Scanner; | |
| class WrongInputException extends Exception | |
| { | |
| String str1=new String(); | |
| WrongInputException(String str) | |
| { | |
| str1=str; | |
| } | |
| public String toString() | |
| { | |
| return("WrongInputException -> "+str1); | |
| } | |
| } | |
| class Customer | |
| { | |
| String name=new String(); | |
| String add=new String(); | |
| String no=new String(); | |
| void display_Customer() | |
| { | |
| System.out.println("Name- "+name); | |
| System.out.println("Address- "+add); | |
| System.out.println("Contact No.- "+no); | |
| } | |
| } | |
| class Food | |
| { | |
| static final String b[]=new String[6]; | |
| static final int rate[]=new int[6]; | |
| int f[]=new int[6]; | |
| int i; | |
| Food() | |
| { | |
| for(i=0;i<6;i++) | |
| { | |
| f[i]=0; | |
| } | |
| for(i=0;i<6;i++) | |
| { | |
| b[i]=new String(); | |
| } | |
| b[0]="Bread Butter "; | |
| b[1]="Bread Omelet "; | |
| b[2]="Coffee "; | |
| b[3]="Tea "; | |
| b[4]="Mineral Water "; | |
| b[5]="Ice Cream "; | |
| rate[0]=40; | |
| rate[1]=55; | |
| rate[2]=35; | |
| rate[3]=30; | |
| rate[4]=25; | |
| rate[5]=50; | |
| } | |
| void food_billing() | |
| { | |
| System.out.println(" Item Quantity Price"); | |
| for(i=0;i<6;i++) | |
| { | |
| if(f[i]!=0) | |
| { | |
| System.out.println(b[i]+" "+f[i]+" "+(rate[i]*f[i])); | |
| } | |
| } | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| } | |
| } | |
| class Room | |
| { | |
| static int vacant=20; | |
| int room_no; | |
| Customer c=new Customer(); | |
| Calendar in=Calendar.getInstance(); | |
| final int base=1500; | |
| Food food=new Food(); | |
| int food_bill=0; | |
| double tax; | |
| double total_bill; | |
| void display() | |
| { | |
| System.out.println("Room No.- "+room_no); | |
| c.display_Customer(); | |
| } | |
| void billing(long x) | |
| { | |
| int i; | |
| for(i=0;i<6;i++) | |
| { | |
| food_bill+=food.f[i]*Food.rate[i]; | |
| } | |
| tax=0.19*((base*x)+food_bill); | |
| total_bill=(base*x)+food_bill+tax; | |
| Date d1=new Date(); | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| System.out.println(" Hotel Transylvania "); | |
| System.out.println(" New Delhi "); | |
| System.out.println(" +1234567890,9876543210 \n"); | |
| System.out.println(" Dated: "+d1+"\n"); | |
| System.out.println("Customer Details:\n"); | |
| c.display_Customer(); | |
| System.out.println("No. of Days = "+x); | |
| System.out.println("------------------------------Room Billing-----------------------------------"); | |
| System.out.println("Base Price For "+x+" Days ---------- "+(base*x)+" Rs."); | |
| System.out.println("------------------------------Food Billing-----------------------------------"); | |
| food.food_billing(); | |
| System.out.println("Total Food Price ---------- "+food_bill+" Rs."); | |
| System.out.println("Total Tax (19%) ---------- "+tax+" Rs."); | |
| System.out.println("Total Bill ---------- "+total_bill+" Rs."); | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| } | |
| } | |
| public class Hotel | |
| { | |
| public static void main(String args[]) | |
| { | |
| WrongInputException ex=new WrongInputException("Invalid Choice!"); | |
| Room r[]=new Room[20]; | |
| int i; | |
| for(i=0;i<20;i++) | |
| { | |
| r[i]=new Room(); | |
| } | |
| int ch; | |
| Date d=new Date(); | |
| System.out.println(" Hotel Transylvania "); | |
| System.out.println(" New Delhi "); | |
| System.out.println(" +1234567890,9876543210 \n"); | |
| System.out.println(" Dated: "+d+"\n"); | |
| Scanner scan=new Scanner(System.in); | |
| int x1=1; | |
| while(x1!=0) | |
| { | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| System.out.println("Enter your choice: \n1.Check In\n2.Customer Info\n3.Order Food\n4.Check Out\n5.Exit"); | |
| System.out.println("-----------------------------------------------------------------------------"); | |
| ch=scan.nextInt(); | |
| switch(ch) | |
| { | |
| case 1: if(Room.vacant==0) | |
| { | |
| System.out.println("Rooms Not Available!"); | |
| System.out.println("Thanks for Your Visit!"); | |
| break; | |
| } | |
| System.out.println("No. of Rooms Vacant = "+Room.vacant); | |
| System.out.println("Rooms Vacant:"); | |
| for(i=0;i<20;i++) | |
| { | |
| if(r[i].room_no!=i+1) | |
| { | |
| System.out.println(" Room No."+(i+1)); | |
| } | |
| } | |
| System.out.println("Enter the Room No. to be Alloted"); | |
| System.out.println(" OR "); | |
| System.out.println("To go back to Main Menu--Enter 0"); | |
| int allot=scan.nextInt(); | |
| scan.nextLine(); | |
| if(allot==0) | |
| { | |
| break; | |
| } | |
| else if(allot>20) | |
| { | |
| try | |
| { | |
| throw ex; | |
| } | |
| catch(WrongInputException e) | |
| { | |
| System.out.println(e); | |
| break; | |
| } | |
| } | |
| else | |
| { | |
| if(r[allot-1].room_no==allot) | |
| { | |
| System.out.println("Room Not Available"); | |
| break; | |
| } | |
| r[allot-1].room_no=allot; | |
| Customer c1=new Customer(); | |
| System.out.println("Enter the Customer Name"); | |
| c1.name=scan.nextLine(); | |
| System.out.println("Enter the Address"); | |
| c1.add=scan.nextLine(); | |
| System.out.println("Enter the Contact No."); | |
| c1.no=scan.nextLine(); | |
| r[allot-1].c=c1; | |
| Calendar date=Calendar.getInstance(); | |
| System.out.println("Enter the Date Today in Numerical Form:"); | |
| System.out.println("Day:"); | |
| int d3=scan.nextInt(); | |
| System.out.println("Month:"); | |
| int d2=scan.nextInt(); | |
| System.out.println("Year:"); | |
| int d1=scan.nextInt(); | |
| date.set(d1,d2,d3); | |
| r[allot-1].in=date; | |
| System.out.println("Room No. "+allot+" Alloted!"); | |
| Room.vacant--; | |
| } | |
| break; | |
| case 2: System.out.println("Enter Room No. For Information"); | |
| int info=scan.nextInt(); | |
| if(r[info-1].room_no!=info) | |
| { | |
| System.out.println("Room Is Vacant!"); | |
| break; | |
| } | |
| r[info-1].display(); | |
| break; | |
| case 3: System.out.println("Enter your Room No."); | |
| int no=scan.nextInt(); | |
| if(r[no-1].room_no!=no) | |
| { | |
| System.out.println("Room Is Vacant!"); | |
| break; | |
| } | |
| System.out.println("Choose the Index You Want to order:"); | |
| System.out.println(" Item Price"); | |
| for(i=0;i<6;i++) | |
| { | |
| System.out.println((i+1)+". "+Food.b[i]+Food.rate[i]+" Rs."); | |
| } | |
| int ch1=scan.nextInt(); | |
| try | |
| { | |
| if((ch1<1)||(ch1>6)) | |
| { | |
| throw ex; | |
| } | |
| } | |
| catch(WrongInputException e) | |
| { | |
| System.out.println(e); | |
| break; | |
| } | |
| System.out.println("Enter the Quantity"); | |
| int quan=scan.nextInt(); | |
| r[no-1].food.f[ch1-1]+=quan; | |
| System.out.println("Item Ordered Successfully"); | |
| break; | |
| case 4: System.out.println("Enter Your Room No."); | |
| int unallot=scan.nextInt(); | |
| if(r[unallot-1].room_no!=unallot) | |
| { | |
| System.out.println("Room Is Vacant!"); | |
| break; | |
| } | |
| r[unallot-1].display(); | |
| Calendar date1=Calendar.getInstance(); | |
| System.out.println("Enter the Date Today in Numerical Form:"); | |
| System.out.println("Day:"); | |
| int d6=scan.nextInt(); | |
| System.out.println("Month:"); | |
| int d5=scan.nextInt(); | |
| System.out.println("Year:"); | |
| int d4=scan.nextInt(); | |
| date1.set(d4,d5,d6); | |
| long diff=date1.getTimeInMillis()-r[unallot-1].in.getTimeInMillis(); | |
| long x=diff/(24*60*60*1000); | |
| r[unallot-1].billing(x); | |
| System.out.println("Thanks For Your Visit"); | |
| r[unallot-1]=new Room(); | |
| Room.vacant++; | |
| break; | |
| case 5: x1=0; | |
| break; | |
| default:try | |
| { | |
| throw ex; | |
| } | |
| catch(WrongInputException e) | |
| { | |
| System.out.println(e); | |
| } | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment