Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a JAVA question. You have online flight ticket calculator. Assume that th

ID: 3761382 • Letter: I

Question

I have a JAVA question.

You have online flight ticket calculator. Assume that the total price of traveling is 0.10 $/km. First calculate the total price of the flight and apply the following discounts depending on the conditions of the customer;

1. Input values must be valid (positive value for distance and age, 1 or 2 for trip type) Otherwise the output will be “Inputs are invalid”.

2. Anyone under the age of 12 gets a 50% discount on the ticket price.

3. Anyone between the age of 12 and 24 gets a 10% discount on the ticket price.

4. Anyone older than the age of 65 gets a 30% discount on the ticket price.

5. The other customers will not get any discount.

6. If the customer plans “Round Trip”, gets a %20 discount in the ticket price, otherwise no discount for one way. One way: 1 - Round : 2

Scenario- 1: Input your distance of the destination km: 1500

Input your age: 20

Input your trip type: 2

Output - 1: The total cost of your flight is 216 $

Scenario- 2:

Input your distance of the destination km: -500

Input your age: -65 Input your trip type: 3

Output - 2: Inputs are invalid

Hint: Normal Price = Distance * 0.10 = 1500 * 0.10 = 150 $

Age Discount = Normal Price * Age Discount Rate = 150 * 0.10= 15 $

Price after Discount = Normal Price – Age Discount = 150 – 15 = 135 $

Discount for Trip Type 1 = Price after Discount * 0.20 = 135 * 0.20 = 27 $

Total Cost of Round Flight = (135-27)* 2 = 216 $

Explanation / Answer

import java.util.Scanner;

public class planeTicket {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

      

       System.out.print("Input your distance of the destination km: ");

       double dest = sc.nextDouble();

      

       System.out.print("Input your age: ");

       int age = sc.nextInt();

      

       System.out.print("Input your trip type(1-> oneway and 2-> round trip): ");

       int tripType = sc.nextInt();

      

       double price=0;

       if (dest <= 0 || age <=0 || !(tripType==1 || tripType ==2)) {

           System.out.println("Invalid Input");

       } else {

           price = dest*.10;

           if (age < 12) {

               price = price - price*.5;

           } else if (age <=24) {

               price = price - price*.1;

           } else if (age > 65) {

               price = price - price*.3;

           }

          

           if (tripType == 1) {

               price = price - price*.2;

           }

           System.out.println("The total cost of your flight is "+price+"$");

       }

   }

}