Suppose you are planning to go to park so you are going to check tickets criteria online. The
ticket rates details have been given
*If children below 10 are not allowed to swing
*If age is between 10 to 15 allowed to swing and getting 10% discount
*If age is between 15 to 20 allowed to swing and getting 5% discount *If age is more than 20 not then not eligible for swing and discount
The age of person will run until you enter the age of last family member and then calculate the total charge amount after entering each person's age. Assume price of ticket is 100 Rs. each person.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Persons: ");
int n = in.nextInt();
double total = 0;
int ticket = 100;
for (int i = 0; i < n; i++) {
System.out.println("Age: ");
int age = in.nextInt();
if (age >= 10 && age < 15) {
total += ticket * 0.9;
} else if (age >= 15 && age <= 20) {
total += ticket * 0.95;
} else if (age > 20) {
total += 100;
}
}
System.out.println("Total: " + total);
}
}
Comments
Leave a comment