1

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

This is the code

import java.util.Scanner;
import java.text.DecimalFormat;

public class CinemaTicket {
    public static void main(String[] args) {
        int no, refe, total = 0;
        double cost, sum, sum1, sum2, sum3;
        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 == "k") {
            total = no * 75;
        } else if (circle == "q") {
            total = no * 150;
        } else {
            System.out.println("Invalid Input");
        }
        if (no > 20) {
            sum = ((0.1) * total);
            sum1 = total - sum;
            if (co == "y") {
                sum2 = ((0.2) * total);
                sum3 = sum1 - sum2;
                if (ref == "y") {
                    refe = no * 150;
                    cost = sum3 + refe;
                } else {
                    cost = sum3;
                }
            } else {
                cost = sum1;
            }
        } else {
            cost = total;
        }
        DecimalFormat df = new DecimalFormat("#.##");
        System.out.println("Ticket cost:" + df.format(cost));
    }
} 

I tried this code, but it does not calculate the cost of the ticket.

thst
  • 4,592
  • 1
  • 26
  • 40

2 Answers2

0

Use the String method equals() or compareTo(). Logical operators won't compare strings in java as it's not a primitive type.

StackyChan
  • 41
  • 1
0

All you need to do is :

if (circle.equals("k")) {
            total = no * 75;
        } else if (circle.equals("q")) {
            total = no * 150;
        } else {
            System.out.println("Invalid Input");
        }

Dont use "==", use equals method and it will work fine.

Adya
  • 1,084
  • 9
  • 17