Design a console application that will print a movie ticket for a customer. Make use of an abstract class named Tickets that contains variables to store the customer name, movie title, customer age and price of the movie. Create a constructor that accepts the customer name, movie title, customer age and price of the movie as parameters and create get methods for the variables. The Tickets class must implement an iTickets interface .
Create a subclass called TicketSales that extends the Tickets class. The TicketSales class must contain a constructor to accept the customer name, movie title, customer age and price of the movie as parameters. . A discount of 10% is applied if the customer’s age is greater than or equal to 65. If the customer is under 65 years old, no discount is given. Finally, write a Movie_Tickets class to instantiate the TicketSales class.
Source code
public class Movie_Tickets
{
public static void main(String[] args) {
TicketSales t=new TicketSales("Mary","Outpost",67,1500);
t.discount();
}
}
interface iTickets
{
}
abstract class Tickets implements iTickets {
public String customer_name;
public String movie_title;
public int customer_age;
public double price;
public Tickets(String cn,String mt, int ca, double p){
customer_name=cn;
movie_title=mt;
customer_age=ca;
price=p;
}
public String getCustomerName(){
return customer_name;
}
public String getMovieTitle(){
return movie_title;
}
public int getCustomerAge(){
return customer_age;
}
public double getPrice(){
return price;
}
}
class TicketSales extends Tickets{
public TicketSales(String cn,String mt, int ca, double p){
super(cn,mt,ca,p);
}
public void discount(){
double disc=0.1*getPrice();
double final_price;
if(getCustomerAge()>=65){
final_price=getPrice()-disc;
}
else{
final_price=getPrice();
}
System.out.println("Customer name: "+getCustomerName());
System.out.println("Movie title: "+getMovieTitle());
System.out.println("Customer age: "+getCustomerAge());
System.out.println("Movie price: "+final_price);
}
}
Sample output 1
Sample output 1
Comments
Leave a comment