Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

instance variables for adult tickets, child tickets, popcorn, and drinks getters

ID: 3543483 • Letter: I

Question

instance variables for adult tickets, child tickets, popcorn, and drinks


getters and setters for each instance variable


constants for the cost of the tickets and refreshments


at least two constructors, one must be a defualt constructor


methods to calculate and return the salesw for adult tickets, child tickets, popcorn and drinks and the total sales


An adult ticket is $9.50, a child ticket is $5.75, popcorn is $5.50 and a drink is $3.25



The owner will enter the number of each sold item. Then the program will determine what the sales is for each item, and the total sales of all the items.

Explanation / Answer

//Worker Class
public class TheaterSales_1 {
    //Create instance variable for adult tickets, child tickets, popcorn and drinks
    private double adultTickets;
    private double childTickets;
    private double popcorn;
    private double drinks;
    //Getters and setters for each instance variable   
    public double getAdultTickets() {
        return adultTickets;
    }
    public void setAdultTickets(double adultTickets) {
        this.adultTickets = adultTickets;
    }
    public double getChildTickets() {
        return childTickets;
    }
    public void setChildTickets(double childTickets) {
        this.childTickets = childTickets;
    }
    public double getPopcorn() {
        return popcorn;
    }
    public void setPopcorn(double popcorn) {
        this.popcorn = popcorn;
    }
    public double getDrinks() {
        return drinks;
    }
    public void setDrinks(double drinks) {
        this.drinks = drinks;
    }
    //Constants for the cost of the tickets and refreshments
    final double adult = 9.50;
    final double child = 5.75;
    final double food = 5.50;
    final double beverage = 3.25;
    //Two constructors, one must be a default constructor
    public TheaterSales_1(){   
        adultTickets = 0;
        childTickets = 0;
        popcorn = 0;
        drinks = 0;   
    }
    public TheaterSales_1(double adultTickets, double childTickets,
                          double popcorn, double drinks ){   
    setAdultTickets(adultTickets);
    setChildTickets(childTickets);
    setPopcorn(popcorn);
    setDrinks(drinks);   
    }
    //Methods to calculate and return sales for adult tickets, child tickets, popcorn, drinks and the total sales
    public double getAdultTicketSales()
    {
    return adultTickets*adult;
    }
    public double getChildTicketSales()
    {
    return childTickets*child;
    }
    public double getPopcornSales()
    {
    return popcorn*food;
    }
    public double getDrinkSales()
    {
    return drinks*beverage;
    }
    public double getTotalSales()
    {
    return getAdultTicketSales() + getChildTicketSales() + getPopcornSales()+ getDrinkSales();
    }
}

// DRIVER Class
class driver
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
double ac,cc,pp,dr;
System.out.println("Enter Total number of adult tickets sold ");
ac =in.nextDouble();
System.out.println("Enter Total number of child tickets sold ");
cc =in.nextDouble();
System.out.println("Enter Total number of Pop corn sold ");
pp =in.nextDouble();
System.out.println("Enter Total number of Drinks sold ");
dr =in.nextDouble();
TheaterSales_1 TS = new TheaterSales_1(ac,cc,pp,dr);
System.out.println("total Adult ticket sales are " + TS.getAdultTicketSales());
System.out.println("total child ticket sales are " + TS.getChildTicketSales());
System.out.println("total Popcorn sales are " + TS.getPopcornSales());
System.out.println("total Drink sales are " + TS.getDrinkSales());
System.out.println("total Theatre sales are " + TS.getTotalSales());
}
}