Question

Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per...

Create a Java Program to calculate luggage costs.

The Business Rules are:

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(),

  1.    Create integers to store the number of Passengers and also the total number of bags
  2.    Prompt for the number of passengers on a ticket.
  3.    Prompt for the total number of bags for all passengers on a ticket.

2. From the main() method:

  1. Pass the number of passengers and the number of bags to a value 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.

3. In the method calculateMyBaggageFees:

  1. Using the passed passenger count and bag count, calculate the total excess bag fee and return that amount as a double variable. If the result is negative, return 0.

3. In the main() method, display the cost for baggage. This is only possible if the method calculateMyBaggageFees is a value method.

 

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

Homework Answers

Answer #1

Code:

// import the scanner class to read input from the user
import java.util.Scanner;

public class LuggageCost {

//   method calculateMyBaggageFees takes two parameters passengers and no_bags
//   it calculates the extra cost of the baggage
//   cost for extra bag is 75
//   this function return a double value
   static double calculateMyBaggageFees(int passengers ,int no_bags) {
      
//       calculate the number of free bags
//       we know that each person can have 2 bags so 2*passengers will give free bags
       int free_bags = 2*passengers;
      
//       now calculate the extra bags
//       we know total bags and free bags so subtract it we get extra bags
       int extra_bags =no_bags - free_bags ;
      
//       calculate the cost for extra bags
//       we know cost for one extra bag is 75
       double cost = 75 * extra_bags;
      
//       check if the cost is -ve value
//       if it is negative means there is no extra bags we simply return 0
       if(cost<0) {
          
           return 0;
       }
      
//       else return the cost of the extra bags
       else {
          
           return cost;
       }
   }

   public static void main(String[] args) {
      
//       declare the variables passengers and no_bags
       int passengers , no_bags;
      
//       create an object for scanner to read input from the user
       Scanner in = new Scanner(System.in);
      
//       prompt the user to enter passengers ticket
      
       System.out.print("Enter number of passengers on your ticket: ");
      
//       read the value and store it in passengers
       passengers = in.nextInt();
      
//       prompt the user to enter number of bags for ticket
       System.out.print("Enter number of bags for this ticket: ");
      
//       store the value in no_bags
       no_bags = in.nextInt();
  
//       now call the function calculateMyBaggageFees with passengers and no_bags as parameters
       double result = calculateMyBaggageFees(passengers,no_bags);
  
//       print the result
       System.out.println("The cost for baggage will be $"+result);
   }

}

Know the answer?
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
Similar Questions
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately....
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately. Hint: Only one of the methods you create needs to be called from the main method. */ public class LandCalculation { public static void main(String[] args) { final int FEET_PER_ACRE = 43560; // Number of feet per acre double tract = 0.0, acres = 0.0; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the tract size: "); tract = keyboard.nextDouble(); // Validate the user's input. while(tract...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT