Question

In: Computer Science

An airline describes airfare as follows. A normal ticket's base cost is $300. Persons aged 60...

An airline describes airfare as follows. A normal ticket's base cost is $300. Persons aged 60 or over have a base cost of $290. Children 2 or under have $0 base cost. A carry-on bag costs $10. A first checked bag is free, second is $25, and each additional is $50. Given inputs of age, carry-on (0 or 1), and checked bags (0 or greater), compute the total airfare.

Hints:

  • First use an if-else statements to assign airFare with the base cost

  • Use another if statement to update airFare for a carryOn

  • Finally, use another if-else statement to update airFare for checked bags

  • Think carefully about what expression correctly calculates checked bag cost when bags are 3 or more

program code needed to finish (Airfare.java)

import java.util.Scanner;

public class Airfare {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int passengerAge;
int carryOns;
int checkedBags;
int airFare;
  
passengerAge = scnr.nextInt();
carryOns = scnr.nextInt();
checkedBags = scnr.nextInt();

/* Type your code here. */
  
System.out.println(airFare);
}
}

Solutions

Expert Solution

Ans)

Code :

Output:

Explanation :

From line 14 to 19, the code will put the base cost in the airFare variable. First it will check if the passenger is of age 2 or lower then it will assign 0 to it. If the passenger's age is greater than or equal to 60 then the base cost will be 290 and it will be assigned to the airFare. If the age is between 2 to 60( both exclusive), code will assign 300 to airFare.

In line 21, the code will check for the carry-on bags. If it is 1 then code will update the value of airFare by adding 10 to it.

If line 24, the code will check for the checked bags. If it is 1, then the code will do nothing. If it is 2, the code will update the value of airFare by adding 25 to it. If it is 3 or more, the code will update the value of airFare by first adding 25 and then 50 for each extra bag to it.  

Understanding the Output based on a Example:

First we have entered the age of passenger as 50. So the base cost will be 300.

airFare = 300

Now we have entered the carry-on bags as 1.

airFare = 300 + 10

airFare =  310

Now we have entered the checked bags as 5

So for first bag nothing to be done and for 2nd bag we have to add 25 and for extra we have to add 50. We have 3 extra bags.

airFare = 310 + (25 + (3 * 50))

airFare = 485

That is how our output is 485.

Hope you got it. Do like it, if it helps you.


Related Solutions

The LDL cholesterol level of all men aged 20 to 34 follows the Normal distribution with...
The LDL cholesterol level of all men aged 20 to 34 follows the Normal distribution with mean μ=120μ=120 milligrams per deciliter and the standard deviation is σ=30σ=30 milligrams per deciliter. If you choose an SRS of 25 men from this population, what is the sampling distribution of mean cholesterol level of the 25 selected men. Select one: a. x¯∼N(120,1.2)x¯∼N(120,1.2) b. Couldn't decide c. x¯∼N(120,30)x¯∼N(120,30) d. x¯∼N(120,6)
Suppose that in fact, the blood cholesterol level of all men aged 20-34 follows the Normal...
Suppose that in fact, the blood cholesterol level of all men aged 20-34 follows the Normal distribution with mean µ = 186 milligrams per deciliter (mg/dl) and standard deviation ? = 41 mg/dl. a) Choose an SRS of 100 men from this population. What is the sampling distribution of x?? What is the probability that x takes a value between 183 and 189 mg/dl? This is the probability that x? estimates µ within ± 3 mg/dl. b) Choose an SRS...
Assume that the mean hourly cost to operate a commercial airplane follows the normal distribution with...
Assume that the mean hourly cost to operate a commercial airplane follows the normal distribution with a mean of $1660 per hour and a standard deviation of $190. What is the maximum operating cost for the lowest 2% of the airplanes? (Round z-score computation to 2 decimal places and the final answer to 1 decimal place.) Maximum operating cost           $
Suppose that Body Mass Index (BMI) for a population of 30-60-year-old men follows a Normal distribution...
Suppose that Body Mass Index (BMI) for a population of 30-60-year-old men follows a Normal distribution with mean 26, and standard deviation 4. Q: Please calculate the range of BMI that 95% of subjects fall within: Suppose we know that the prevalence of asthma among American children is 11%. Researchers conducted a study among 600 children in Boston and found that 56 had asthma. Q:Suppose researchers originally planed to enroll 1000 children, but they had to reduce the sample size...
The claim cost of an insurance company follows a normal distribution with an expected value of $500 million and a standard deviation of $100 million.
The claim cost of an insurance company follows a normal distribution with an expected value of $500 million and a standard deviation of $100 million. Based on the above, work on the following questions.In the graph, indicate the probability of insolvency of the insurer when it has an asset of $750 million. Please clearly label the axes.Show the probability of insolvency of the insurer after the insurer raises $100 million of new capital.Compute the probabilities of insolvency for the insurer...
Total cost data follow for Glendale Manufacturing Company, which has a normal capacity per period of 8,000 units of product that sell for $60 each. For the foreseeable future, regular sales volume should continue to equal normal capacity.
Special OrderTotal cost data follow for Glendale Manufacturing Company, which has a normal capacity per period of 8,000 units of product that sell for $60 each. For the foreseeable future, regular sales volume should continue to equal normal capacity.Direct material$100,800Direct labor62,400Variable manufacturing overhead46,800Fixed manufacturing overhead (Note 1)38,400Selling expense (Note 2)35,200Administrative expense (fixed)15,000$298,600Notes:1. Beyond normal capacity, fixed overhead costs increase $1,800 for each 500 units or fraction thereof until a maximum capacity of 10,000 units is reached.2. Selling expenses consist of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT