Can you kindly help me with the assignment attached below re
Can you kindly help me with the assignment attached below regarding java programming?
I\'m using eclipse for this assignment. My task is to write a program that sells different types of tickets (e.g., student, child, adult, senior citizen) for a theater by using inheritance, abstract class and java interfaces.
I really appreciate your time and effort.
Write a program that sells different types of tickets (e.g., student, child, adult, senior citizen) for a theater. (utilize the concepts of : inheritance, abstract class and java interfaces. )
- Create an abstract class Ticket that has:
variable id: a unique identify for each ticket and has type int
variable price: price per one ticket, has type float
Constructor Ticket(int id, float price) for assigning values to 2 variables id and price
- Create 4 classes: SeniorTicket, AdultTicket, ChildTicket and StudentTicket which extends abstract class Ticket and implement constructor and toString method for each class.
- Prices: $20 for adult, $10 for senior and children and $15 for student ticket.
- Create class TheaterTicketService which implements TicketService interface ( file TicketService.java) and sellTicket method. sellTicket method should return an object that is instance of one of 4 class: SeniorTicket, AdultTicket, ChildTicket and StudentTicket depend on ticketType.
- Class TheaterTicketService should:
-Instance variable int capacity : total number of tickets
-Instance variable int soldTicket : total number of sold tickets
-Instance variable float revenue which is the total money of selling tickets; also implement a getter for this variable .
- constructor TheaterTicketService(int capacity)
For example:
TheaterTicketService tts = new TheaterTicketService(20);
Ticket adultTicket = tts.sellTicket(TicketService.Type.ADULT);
System.out.println(\"Sold \" + adultTicket.toString());
Ticket childTicket = tts.sellTicket(TicketService.Type.CHILD);
System.out.println(\"Sold \" + childTicket.toString());
System.out.println(\"Total tickets: \" + tts.getCapacity() + \" ;Ticket Sold: \" + tts.getTicketLeft());
System.out.println(\"Revenue until now: \" + tts.getRevenue());
should have output:
Sold Adult ticket, id: 1, price: $20.0
Sold Child ticket, id: 2, price: $10.0
Total tickets: 20 ;Ticket Sold: 18
Revenue until now: $30.0
- Please document your code internally with comments
Solution
Abstract class ticket{
int vairableid;
float price;
int Ticket(int id, float price);{
id=123;
price=4.2;}
}
public class TheaterTicketService implements TicketService{
int capacity;
int ticketssold;
float revenue;
TheaterTicketService(int capacity) {
capacity=100;
}
int sellTicket(){
childticket a;
adultticket b;
seniorticket c;
studentticket d;
if(Tickettype=\"a\")
return a;
or else if(tickettype=\"b\")
return b;
else if(tickettype=\"c\")
return c;
else return d;
}
class childticket(){
System.out.println(\"enter age\");
Scanner in =new scanner(system.in);
if (in<10){
system.out.println(\"childticket \");} //similary we write other three classes student, adult , seniorcitizen ticket
}
public int getcapacity(int capacity)
{
Integer[] oapQuantityList = {0,1,2,3,4,5};
}
}
string toomanytickets()
{
System.out.println(\"You cannot Process more than 5 tickets at a time!\"\");
}
string notEnoughSeats()
{
system.out.println(\"There are not enough seats remaining to process the number of tickets selected\", \"Ticket Quantity Error\");
}
public int getrevenue(int){
}
public static void main (String[] args)
{
TheaterTicketService tts = new TheaterTicketService(20);
Ticket adultTicket = tts.sellTicket(TicketService.Type.ADULT);
System.out.println(\"Sold \" + adultTicket.toString());
Ticket childTicket = tts.sellTicket(TicketService.Type.CHILD);
System.out.println(\"Sold \" + childTicket.toString());
System.out.println(\"Total tickets: \" + tts.getCapacity() + \" ;Ticket Sold: \" + tts.getTicketLeft());
System.out.println(\"Revenue until now: \" + tts.getRevenue());
}
| Integer[] adultQuantityList = {0,1,2,3,4,5}; |


