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.
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))));
}
}
}
Comments
Leave a comment