Question

Making Multiple Comparisons in Decision Statements in Java Q Sear Making Multiple Airline java Comparisons in Decision Statements 1 /1 Atrline. java - Thts progran deterntnes tf an atrline passenger 2! // eligible for a 25% discount. 4 inport java. util.Scanner; 6 public class Atrltne 8 public static void nain(String args[1) Summary In this lab, you complete a partially written Java program for an airline that offers a 25 percent discount to passengers who are 6 years old or younger and the same discount to passengers who are 65 years old or older. The program should request a passengers name and age and then print whether the passenger is eligible or not eligible for a discount. Scanner s new Scanner (Systen. in): String passengerNane ; I Passengers nane String ageString 12 // String verston of , passenger s age // Thts ts the vork done in the housekeeptng() nethod Systen.out. println( Enter passengers nane). passengerNane s.nextl tneO Systen.out.println Enter passengers age: ). ageString #s.nextLine(); Instructions 1. Ensure the file named Airline.java is open. 2. Variables have been declared and DOLL
media%2F07d%2F07d9cd01-db05-4577-9e76-72
media%2F02c%2F02c140cf-2cce-4ac5-a4a2-64
media%2F381%2F381f29f8-c579-4237-9ba2-86
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here you go as requested I have provided the code with

appropriate comments and variable names.

If there is any further query kindly add it as a comment.

Note: here I have used the logical OR represented by || in the if condition

******************************************************************

You can either add these lines after the comment

// This is the work done in detailLoop() method

// Test to see if this customer is eligible for a 25% discount

******************************************************************

System.out.println("Customer Name: " + passengerName);

System.out.println("Customer Age: " + passengerAge);

// This is the conditional statement which checks if the passengerAge is lesser

// than or equal to 6 or if the passenger's age is greater than or equal to 65.

if ((passengerAge <= 6) || (passengerAge >= 65)) {

System.out.println("Passenger is eligible for a discount");

} else {

System.out.println("Passenger is not eligible for a discount");

}

*****************************************************************

This is the complete code with the above changes

*****************************************************************

//Airline.java - This program determines if an airline passenger is

//eligible for a 25% discount.

import java.util.Scanner;

public class Airline {

public static void main(String args[]) {

Scanner s = new Scanner(System.in);

String passengerName = ""; // Passenger's name

String ageString = ""; // String version of passenger's age

int passengerAge = 0; // Passenger's age

// This is the work done in the housekeeping() method

System.out.println("Enter passenger's name: ");

passengerName = s.nextLine();

System.out.println("Enter passenger's age: ");

ageString = s.nextLine();

passengerAge = Integer.parseInt(ageString);

// This is the work done in detailLoop() method

// Test to see if this customer is eligible for a 25% discount

System.out.println("Customer Name: " + passengerName);

System.out.println("Customer Age: " + passengerAge);

// This is the conditional statement which checks if the passengerAge is lesser

// than or equal to 6 or if the passenger's age is greater than or equal to 65.

if ((passengerAge <= 6) || (passengerAge >= 65)) {

System.out.println("Passenger is eligible for a discount");

} else {

System.out.println("Passenger is not eligible for a discount");

}

// This is the work done in endOfJob() method

System.exit(0);

}

}

******************************************************

Add a comment
Know the answer?
Add Answer to:
Making Multiple Comparisons in Decision Statements in Java Q Sear Making Multiple Airline java Comparisons in...
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  =...

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