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

Question #299976

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.


Hint:-

-get user input for how many family members

-give personal price along with discount based on age

-give total price along with discount

-give how many members are allowed



1
Expert's answer
2022-02-19T16:56:19-0500


import java.util.*;


class App {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		final double priceTicket = 100;// Assume price of ticket is 100 Rs. each person.
		int notAllowedFamilyMembers = 0;
		double discount = 0;
		double totalChargeAmount = 0;
		// -get user input for how many family members
		System.out.print("How many family members?: ");
		int members = in.nextInt();
		for (int i = 0; i < members; i++) {
			double totalPrice = 0;
			// 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.
			System.out.print("Enter the age of family member: ");
			int age = in.nextInt();
			// -If children below 10 are not allowed to swing
			if (age < 10) {
				notAllowedFamilyMembers++;
				System.out.println("Not allowed to swing");
			} else if (age >= 10 && age < 15) {
				// -If age is between 10 to 15 allowed to swing and getting 10 % discount
				discount = priceTicket * 0.1;
				System.out.printf("Discount: %.2f Rs.\n", discount);
				totalPrice = priceTicket - discount;
				System.out.printf("Total price: %.2f Rs.\n\n", totalPrice);
			} else if (age >= 15 && age <= 20) {
				// -If age is between 15 to 20 allowed to swing and getting 5 % discount
				discount = priceTicket * 0.05;
				System.out.printf("Discount: %.2f Rs.\n", discount);
				totalPrice = priceTicket - discount;
				System.out.printf("Total price: %.2f Rs.\n\n", totalPrice);
			} else if (age >= 20) {
				// -If age is more than 20 not then not eligible for swing and discount
				discount = priceTicket * 0.2;
				System.out.printf("Discount: %.2f Rs.\n", discount);
				totalPrice = priceTicket - discount;
				System.out.printf("Total price: %.2f Rs.\n\n", totalPrice);
			}
			totalChargeAmount += totalPrice;


		}


		System.out.printf("The total charge amount: %.2f Rs.\n", totalChargeAmount);
		System.out.printf("%d members are allowed\n\n", (members - notAllowedFamilyMembers));


		in.close();
	}
}

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