Movie Ticket Calculation
In a multiplex theater, there is a discount scheme announced where one gets a 10% discount on the total cost of tickets when there is a bulk booking of more than 20 tickets, and a discount of 2% on the total cost of tickets if a special coupon card is submitted. Develop a program to find the total cost as per the scheme. The cost of the king class ticket is Rs.75 and queen class is Rs.150. Refreshments can also be opted by paying an additional of Rs. 50 per member. Hint: k-king and q-queen and You have to book minimum of 5 tickets and maximum of 40 at a time. If fails display "Minimum of 5 and Maximum of 40 Tickets". If circle is given a value other than 'k' or 'q' the output should be "Invalid Input".
The ticket cost should be printed exactly to two decimal places.
Sample Input 1:
Enter the no of ticket:35
Do you want refreshment:y
Do you have coupon code:y
Enter the circle:k
Sample Output 1:
Ticket cost:4065.25
Sample Input 2:
Enter the no of ticket:1
Sample Output 2: Minimum of 5 and Maximum of 40 Tickets
My current program looks like this:
import java.util.Scanner;
import java.text.DecimalFormat;
public class Movie_Ticket_Calculation {
private static DecimalFormat df1 = new DecimalFormat("0.00");
public static void main(String[] args) {
int no;
double cost, sum, sum1, sum2, sum3,total = 0,refe;
String ref, co, circle;
Scanner s = new Scanner(System.in);
System.out.println("Enter the no of ticket:");
no = s.nextInt();
if (no < 5 || no > 40) {
System.out.println("Minimum of 5 and Maximum of 40 tickets");
}
System.out.println("Do you want refreshment:");
ref = s.next();
System.out.println("Do you have a coupon code:");
co = s.next();
System.out.println("Enter the circle:");
circle = s.next();
if (circle.equals("k")) {
total = no * 75;
} else if (circle.equals("q")) {
total = no * 150;
} else {
System.out.println("Invalid Input");
}
if (no > 20)
{
sum = ((0.1) * total);
sum1 = total - sum;
if (co.equals("y")) {
sum2 = ((0.02) * total);
sum3 = sum1 - sum2;
if (ref.equals("y")) {
refe = no * 50;
cost = sum3 + refe;
} else {
cost = sum3;
}
} else {
cost = sum1;
}
} else {
cost = total;
}
System.out.println("Ticket cost:" + df1.format(cost));
}
}
Aucun commentaire:
Enregistrer un commentaire