Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Change this code in java just with changing abstraction and exception handling #include #include #include typedef struct Guests { char name[50]; int status; int

Question: Change this code in java just with changing abstraction and exception handling

#include #include #include

typedef struct Guests { char name[50]; int status; int nights; float room_cost; float srv; float cost; } G;

void options(G guest[]) { int option; printf(" Menu ----------- "); printf("1. Check in "); printf("2. Services "); printf("3. Invoice ");; printf("4. Check out "); printf("5. Exit "); printf(" Please Choose a Number According to the Option: "); scanf("%d", &option); switch(option) { case 1: printf(" Check in ----------- "); check_in(guest); break;

case 3: printf(" Invoice ----------- "); invoice(guest); break;

case 2: printf(" Request ----------- "); request(guest); break;

case 4: printf(" Check out ----------- "); check_out(guest); break;

case 5: exit(0); break; } }

void check_in(G guest[]) { int i, choice, nights; printf("Rooms: "); for(i=0;i<4;i++) { printf("Room No.%d ", i+1); printf("Room Cost: %.2f/night ", guest[i].room_cost); printf("Status: "); if(guest[i].status==0) { printf("Available "); } else if(guest[i].status==1) { printf("Unavailable "); } printf(" "); } printf("*All services provided are for 1 guest only* "); printf("Input Room No. for chosen room: "); scanf("%d", &choice); for(i=0;i<4;i++) { if(choice==i+1 && guest[i].status==0) { printf(" Your name: "); scanf("%s", guest[i].name); printf("How many nights?: "); scanf("%d", &guest[i].nights); guest[i].status=1; guest[i].cost=guest[i].room_cost*guest[i].nights; printf(" You've been checked in at Room %d! ", i+1); } } options(guest); }

void check_out(G guest[]) { int i, room_no; printf("Input your room no.: "); scanf("%d", &room_no); for(i=0;i<4;i++) { if(room_no==i+1 && guest[i].status==1) { guest[i].status=0; guest[i].cost=0; guest[i].nights=0; strcpy(guest[i].name, "BLANK"); } } options(guest); }

void request(G guest[]) { int option, i, room_no; printf("Input your room no.: "); scanf("%d", &room_no); for(i=0;i<4;i++) { if(room_no==i+1 ) { printf(" 1. Request Breakfast "); printf("2. Request Lunch ");; printf("3. Request Dinner "); printf("4. Request Dry Cleaning "); printf("5. Exit "); printf(" Please Choose a Number According to the Option: "); scanf("%d", &option); switch(option) { case 1: guest[i].cost=guest[i].cost+10; guest[i].srv=guest[i].srv+10; printf(" Breakfast requested! "); break;

case 2: guest[i].cost=guest[i].cost+15; guest[i].srv=guest[i].srv+15; printf(" Lunch requested! "); break;

case 3: guest[i].cost=guest[i].cost+20; guest[i].srv=guest[i].srv+20; printf(" Dinner requested! "); break;

case 4: guest[i].cost=guest[i].cost+20; guest[i].srv=guest[i].srv+20; printf(" Dry cleaning requested! "); break;

case 5: exit(0); break; } } } options(guest); }

void printing(G guest[]) { int i, room_no; float tax=0, serv_chrg=50; FILE *fp; fp=fopen("Invoice.txt", "w"); if(fp==NULL) { printf("Couldn't create file"); } printf(" Input your room no.: "); scanf("%d", &room_no); for(i=0;i<4;i++) { if(room_no==i+1 && guest[i].status==1) { guest[i].cost=guest[i].cost+(serv_chrg*guest[i].nights)+guest[i].srv; tax=(guest[i].cost*.14); guest[i].cost=guest[i].cost+tax; fprintf(fp,"Name: %s ", guest[i].name); fprintf(fp,"Room No.: %d ", i+1); fprintf(fp,"-------------------------------- "); fprintf(fp,"Room Charge: %.2f ", guest[i].room_cost*guest[i].nights); fprintf(fp,"Service Charge: %.2f ", serv_chrg*guest[i].nights); fprintf(fp,"Other services: %.2f ", guest[i].srv); fprintf(fp,"Room & Service Tax: %.2f ", tax); fprintf(fp,"-------------------------------- "); fprintf(fp,"Total:\t%.2f ", guest[i].cost);

} tax=0; } fclose(fp); printf(" Text file created! "); options(guest); }

void invoice(G guest[]) { int i, room_no, option; float tax=0, serv_chrg=50; printf("Input your room no.: "); scanf("%d", &room_no); for(i=0;i<4;i++) { if(room_no==i+1 && guest[i].status==1) { guest[i].cost=guest[i].cost+(serv_chrg*guest[i].nights)+guest[i].srv; tax=(guest[i].cost*.14); guest[i].cost=guest[i].cost+tax; printf(" Name: %s ", guest[i].name); printf("Room No.: %d ", i+1); printf("-------------------------------- "); printf("Room Charge: %.2f ", guest[i].room_cost*guest[i].nights); printf("Service Charge: %.2f ", serv_chrg*guest[i].nights); printf("Other services: %.2f ", guest[i].srv); printf("Room & Service Tax: %.2f ", tax); printf("-------------------------------- "); printf("Total:\t%.2f ", guest[i].cost);

} tax=0; } printf(" 1. Convert invoice to text file "); printf("2. Return to Menu "); printf("Choose a Number According to the Option: "); scanf("%d", &option); if(option==1) { printing(guest); } else if(option==0); { options(guest); } }

int main() { int i; G guest[4]; printf("Pre-define data: "); for(i=0;i<4;i++) { printf("Pre-define cost of Room %d: ", i+1); scanf("%f", &guest[i].room_cost); } for(i=0;i<4;i++) { guest[i].status=0; strcpy(guest[i].name, "BLANK"); guest[i].nights=0; guest[i].srv=0; } options(guest); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

What business entities canNOT register as a real estate brokerage?

Answered: 1 week ago