Question

The program is described in Chapter 9, Exercise 11, in Programming Logic and Design. In this...

The program is described in Chapter 9, Exercise 11, in Programming Logic and Design. In this program, you should 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.

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.

// Cornwall.java - This program computes hotel guest rates.

// Input:  Days in stay and meals included

// Output:  Hotel guest rate

import java.util.Scanner;

public class Cornwall

{

    public static void main(String args[])

    {

        Scanner input = new Scanner(System.in);

        int days;

        String dayString;

        String mealPlan;

        String question;

        double rate = 0.00;

        

        System.out.println("How many days do you plan to stay? ");

        

        dayString = s.nextLine();

        days = Integer.parseInt(dayString);

        System.out.println(" Do you want a meal plan? Y or N: ");

        question = s.nextLine();

        // Figure out which arguments to pass to the computeRate() method and

        // then call the computeRate() method

        if(question.equals("Y")) {

            System.out.println("Enter meal plan (A or C: )");

            

            rate = computerRate(days, mealPlan);

        }

        else {

            rate = computerRate(days);

        }

        

        System.out.println("The rate for your stay is: " + rate);               

        System.exit(0);

    } // End of main() method.

    

    

    // Write computeRate methods here.

    public static double computerRate(int x) {

        double rate = 99.99 * x;

        return rate;

    }

    public static double computerRate(int x, String plan) {

           double rate;

           if(mealPlan.equals("A")) {

               rate = 169 * x;

           }

           else if(mealPlan.equals("C")) {

               rate = 112 * x;

           }

           else {

               rate = 0;

           }

           return rate;

       }

} // End of Cornwall class.

I keep getting errors I can't figure it out, help please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Cornwall

{

   public static void main(String args[])

   {

       Scanner input = new Scanner(System.in);

       int days;

       String dayString;

       String mealPlan;

       String question;

       double rate = 0.00;

       System.out.println("How many days do you plan to stay? ");
      
       // need to read it with input and we use use next

       dayString = input.next();

       days = Integer.parseInt(dayString);

       System.out.println(" Do you want a meal plan? Y or N: ");
       // need to read it with input and we use use next


       question = input.next();

       // Figure out which arguments to pass to the computeRate() method and

       // then call the computeRate() method

       if (question.equals("Y")) {

           System.out.println("Enter meal plan (A or C): ");
           // need to read it with input and we use use next

           mealPlan = input.next();

           rate = computeRate(days, mealPlan);

       }

       else {

           rate = computeRate(days);

       }

       System.out.println("The rate for your stay is: " + rate);

       System.exit(0);

   } // End of main() method.

   // Write computeRate methods here.

   public static double computeRate(int x) {

       double rate = 99.99 * x;

       return rate;

   }

   public static double computeRate(int x, String plan) {

       double rate;

       if (plan.equals("A")) {

           rate = 169 * x;

       }

       else if (plan.equals("C")) {

           rate = 112 * x;

       }

       else {

           rate = 0;

       }

       return rate;

   }

} // End of Cornwall class.

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
The program is described in Chapter 9, Exercise 11, in Programming Logic and Design. In this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

    - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.   Debugging 4:  Add the missing code in bold and red. import java.util.Scanner; public class Airline {             public static void main(String args[])             {                         Scanner s = new Scanner(System.in);                         String passengerName = ""                              String ageString = ""                           int passengerAge = 0                         System.out.println("Enter passenger's name: ");                         passengerName  =...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){...

    Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next();    String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word);    if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Extend this date validation program, so that it checks for valid leap years (in which the...

    Extend this date validation program, so that it checks for valid leap years (in which the month February has 29, instead of 28, days). A leap year is any year that is divisible by 4 but not divisible by 100, unless it is also divisible by 400. Do not allow February to have 29 days on years that are not leap years. **Please view both photos for the entire code and post new code with the leap year modification. Thank...

  • Write a program that stores a phrase as an array of words, and then prints it...

    Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{    public static void main(String[] args) {    String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 { public static void main(String args[]) { final int DAYS = 30; double money = 0.01; int day =...

  • Chapter 4 Loop logic and using loop logic for File Input/0utput. 1. Read Chapter 4 sections...

    Chapter 4 Loop logic and using loop logic for File Input/0utput. 1. Read Chapter 4 sections 4.10 until end of chapter. 2. Review Questions and Exercises, short answers. 3. [20 points] submit SalaryCalcLoopFile.java Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information to a file. use input file, where each employee has name,shift,hours worked,hourly rate: EmployeePayroll.txt output file should be named: EmployeePayStubs.txt EmployeePayroll.txt Rashid...

  • Separating calculations into methods simplifies modifying and expanding programs. The following program calculates the tax rate...

    Separating calculations into methods simplifies modifying and expanding programs. The following program calculates the tax rate and tax to pay, using methods. One method returns a tax rate based on an annual salary. Run the program below with annual salaries of 40000, 60000, and 0. Change the program to use a method to input the annual salary. Run the program again with the same annual salaries as above. Are results the same? This is the code including what I am...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT