Question

Create a Java Program to calculate baggage charges. Here are the rules: A. Two bags per...

Create a Java Program to calculate baggage charges. Here are the rules:

A. Two bags per person are free.

B. The Excess Bag Charge is $75 per bag.

The program needs to do the following:

1. In your main method(),

   Create integers to store the number of Passengers and also the total number of bags

   Prompt for the number of passengers on a ticket.

   Prompt for the total number of bags for all passengers on a ticket.

2. From the main() method, pass the number of passengers and the number of bags to a method named "calculateMyBaggageFees".

This method needs to determine the number of free bags allowed. A bag count over the free count should be multiplied by the Excess Bag Charge.

Calculate the total excess bag fee and return the amount as a double variable. The result can also be 0.

3. In the main() method, display the cost for baggage.

Example Input/Output:

Enter number of passengers on your ticket:2

Enter number of bags for this ticket:5

The cost for baggage will be $75.00

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// BaggageCharges.java

import java.util.Scanner;

public class BaggageCharges {

   public static void main(String[] args) {
       //Declaring variables
       int noOfPassengers,noOfBags;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       //Getting the input entered by the user
System.out.print("Enter number of passengers on your ticket:");
noOfPassengers=sc.nextInt();
System.out.print("Enter number of bags for this ticket:");
noOfBags=sc.nextInt();
double baggageCharges=calculateMyBaggageFees(noOfPassengers,noOfBags);
System.out.printf("The cost for baggage will be $%.2f",baggageCharges);


   }

   private static double calculateMyBaggageFees(int noOfPassengers,
           int noOfBags) {
      
       return (noOfBags-(noOfPassengers*2))*75;
   }

}
_______________________________

output:

Enter number of passengers on your ticket:2
Enter number of bags for this ticket:5
The cost for baggage will be $75.00

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create a Java Program to calculate baggage charges. Here are the rules: A. Two bags per...
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
  • An airline company needs a program to convert pounds to kilograms for passengers to determine baggage...

    An airline company needs a program to convert pounds to kilograms for passengers to determine baggage weight in kilograms. Write a C++ program that displays the prompt: Enter pounds. After the user responds to the prompt, the program should calculate the number of kilograms and display the result with a short message. One kilogram = 2.2 pounds. The program should then determine the cost of the bag, which is $3.00 per kilogram if the bag weighs more than 21 kilograms;...

  • Create a Java Program/Class named ComputeInterest to calculate compound interest. This can all be done entirely...

    Create a Java Program/Class named ComputeInterest to calculate compound interest. This can all be done entirely in the main() method. Create a double variable named currentBalance. Create a double variable named newBalance. Create a final double variable named INTEREST_RATE and assign 1.05 to it. Create a int variable named yearCount. Prompt for the "Number of years to invest" and store the input into the yearCount variable. Prompt for the "Amount to Invest" and store this in the currentBalance variable. Assign...

  • Code a Java program to create and use OO classes. Comment your code throughout. Create a...

    Code a Java program to create and use OO classes. Comment your code throughout. Create a Super class named Home Properties address SF (this is the number of Square feet) value (this is the dollar value of the home) Methods Set and get methods for all properties calcValue() - calculate the value as sf * 400 displayCondo() - displays all properties of a condo Create a sub class named Condo Properties HOAfee (home owners association fee) Methods Set and get...

  • in Java, temperature problem Create a package named temperature and create a program that has a...

    in Java, temperature problem Create a package named temperature and create a program that has a while loop. • • Inside the while loop, your program will prompt the user for temperature in Centigrade. If the Centigrade value read in is <= -100. the loop will exit. Otherwise, your program will compute the Fahrenheit equivalent temperature. Inside the while loop, your program will print out the Centigrade and Fahrenheit temperatures. Keep a count of the valid user inputs and a...

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • 25. In this exercise, you create a program for the sales manager at Computer Haven, a...

    25. In this exercise, you create a program for the sales manager at Computer Haven, a small business that offers motivational seminars to local companies. Figure 7-53 shows the charge for attending a seminar. Notice that the charge per person depends on the number of people the company registers. For example, the cost for four registrants is $400; the cost for two registrants is $300. The program should allow the sales manager to enter the number of registrants for as...

  • Hospital Charges ASSIGNMENT: Write a program to calculate and display the amount of the charges for...

    Hospital Charges ASSIGNMENT: Write a program to calculate and display the amount of the charges for a hospital stay. Create a global constant for the daily fee of a hospital room ($350.00/day). Ask the user for: The number of days spent in the hospital The amount of the medication charges The amount of the surgical charges The amount of the lab fees The amount of the physical rehabilitation charges Then, using functions, calculate the stay charges (number of days *...

  • Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...

    Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times. b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the...

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
ADVERTISEMENT