Create the logic for a program that computes hotel guest rates at the Renaissanc
ID: 3812337 • Letter: C
Question
Create the logic for a program that computes hotel guest rates at the Renaissance hotel. Include two overloaded methods named computeRate(). One version accepts a number of days and calculates the rate at $99.99 per day. The other accepts a number of days and a code for a meal plan. If the code is A, three meals per day are included, and the price is $169.00 per day. If the code is C, breakfast is included, and the price is $112.00 per day. All other codes are invalid. Each method returns the rate to the calling program where it is displayed. The main program asks the user for the number of days in a stay and whether meals should be included; then, based on the user’s response, the program either calls the first method or prompts for a meal plan code and calls the second method.
Your program should also include a module that welcomes the user and an end of the program module that thanks the user for using the program and outputs the rate they can expect to pay.
Explanation / Answer
PROGRAM CODE:
package util;
import java.util.Scanner;
public class HotelSystem {
public static double computeRate(int numDays)
{
return numDays*99.99;
}
public static double computeRate(int numDays, char code)
{
if(code == 'A')
return numDays*169;
else if(code == 'C')
return numDays*112;
else return 0;
}
public static void main(String args[])
{
int days = 0;
Scanner kbd = new Scanner(System.in);
System.out.println("Welcome to Renaissance Hotel!");
System.out.print(" Please enter the number of days you are wishing to stay: ");
days = Integer.valueOf(kbd.nextLine());
System.out.print("Do you want to add meals ?(Y/N): ");
char mealChoice = kbd.nextLine().charAt(0);
if(mealChoice == 'Y' || mealChoice == 'y')
{
System.out.println("Select A for three meals a day or C for only breakfast");
System.out.print("Enter your option: ");
char code = kbd.nextLine().charAt(0);
System.out.printf(" Your total amount to pay is $%.2f", computeRate(days, code));
}
else System.out.printf(" Your total amount to pay is $%.2f", computeRate(days));
System.out.println(" Thank you for using Renaissance hotel system Have a pleasant stay ");
}
}
OUTPUT:
Welcome to Renaissance Hotel!
Please enter the number of days you are wishing to stay: 3
Do you want to add meals ?(Y/N): n
Your total amount to pay is $299.97
Thank you for using Renaissance hotel system
Have a pleasant stay