Answer to Question #299490 in Java | JSP | JSF for Kamalesh

Question #299490

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.


1
Expert's answer
2022-02-18T12:50:45-0500
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);
    }
}

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