Answer to Question #249885 in Java | JSP | JSF for Rob

Question #249885

Passenger fare is classified according to the type of passenger. Senior Citizen enjoys 20%

discount from the regular fare, Students get 10% discount. Regular passengers who do

not qualified as neither Senior Citizen nor a Student should pay the regular fare of 150.

Write an algorithm that will accept details of five (5) passengers, including its name and

passenger type and will compute for the corresponding fare of each passenger. Display

the name and type of passenger, as well as the computer fare.


1
Expert's answer
2021-10-12T00:36:34-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] names = new String[5];
        int[] type = new int[5];
        for (int i = 0; i < names.length; i++) {
            System.out.println("Name:");
            names[i] = in.nextLine();
            System.out.println("Type(1 - Senior, 2 - Student, 3 - Regular): ");
            type[i] = Integer.parseInt(in.nextLine());
        }
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i] + " fare: " +
                    (type[i] == 1 ? 150.d * 0.8 : (type[i] == 2 ? 150.d * 0.9 : (type[i] == 3 ? 150 : -1))));
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS