EVENT.JAVA:
class Event{
protected String name;
protected String type;
protected Double costPerDay;
protected Integer noOfDays;
//Fill your code here
public Event(String name, String type, Double costPerDay, Integer noOfDays) {
this.name = name;
this.type = type;
this.costPerDay = costPerDay;
this.noOfDays = noOfDays;
}
}
class Event{ protected String name; protected String type; protected Double costPerDay; protected Integer noOfDays; //Fill your code here public Event(String name, String type, Double costPerDay, Integer noOfDays) { this.name = name; this.type = type; this.costPerDay = costPerDay; this.noOfDays = noOfDays; } }
EXHIBITION.JAVA:
import java.text.DecimalFormat; class Exhibition extends Event { DecimalFormat df= new DecimalFormat("#.00"); static int gst=5; int noOfStalls; double amt1; public int getNoOfStalls() { return noOfStalls; } public void setNoOfStalls(int noOfStalls) { this.noOfStalls = noOfStalls; } public Exhibition(String name, String type, Double costPerDay, Integer noOfDays, int noOfStalls) { super(name, type, costPerDay, noOfDays); // TODO Auto-generated constructor stub this.type=type; this.costPerDay=costPerDay; this.noOfStalls=noOfStalls; this.noOfDays=noOfDays; } public Double totalCost() { //Fill your code here amt1 = costPerDay*noOfDays*1.05; return amt1; } public String toString() { //Fill your code here return "Event Details\n"+"Name:"+name+"\n"+"Type:"+type+"\n"+"Number of stalls:"+noOfStalls+"\n"+"Total amount:"+df.format(totalCost()); } }
STAGEEVENT.JAVA:
import java.text.DecimalFormat; class StageEvent extends Event{ private static int gst=15; private int noOfSeats; double amt; DecimalFormat df = new DecimalFormat("#.00"); public int getNoOfSeats() { return noOfSeats; } public void setNoOfSeats(int noOfSeats) { this.noOfSeats = noOfSeats; } public static int getGst() { return gst; } public static void setGst(int gst) { StageEvent.gst = gst; } public StageEvent(String name, String type, Double costPerDay, Integer noOfDays, Integer noOfStalls){ super(name,type,costPerDay,noOfDays); this.noOfSeats=noOfStalls; } public double totalCost(){ amt = costPerDay*noOfDays*1.15; return amt; } public void display(){ System.out.println("Event Details"); System.out.println("Name:"+name); System.out.println("Type:"+type); System.out.println("Number of seats:"+noOfSeats); System.out.println("Total amount:"+amt); } public String toString(){ return "Event Details\n"+"Name:"+name+"\n"+"Type:"+type+"\n"+"Number of seats:"+getNoOfSeats()+"\n"+"Total amount:"+df.format(totalCost()); } }
MAIN.JAVA:
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in).useDelimiter("\n"); System.out.println("Enter event name"); String name=sc.next(); System.out.println("Enter the cost per day"); double costPerDay=sc.nextDouble(); System.out.println("Enter the number of days"); int noOfDays=sc.nextInt(); System.out.println("Enter the type of event\n1.Exhibition\n2.Stage Event"); int type=sc.nextInt(); Event event; if(type==1){ System.out.println("Enter the number of stalls"); int noOfStalls=sc.nextInt(); event = new Exhibition(name,"Exhibition",costPerDay,noOfDays,noOfStalls); System.out.println(event.toString()); } else if(type==2){ System.out.println("Enter the number of seats"); int noOfStalls=sc.nextInt(); event = new StageEvent(name,"Stage Event", costPerDay,noOfDays,noOfStalls); System.out.println(event.toString()); } else{ System.out.println("Invalid input"); } } }