Abstract Class

 EVENT.JAVA:
  public abstract class Event {
	    String name;

	    String detail;

	    String type;

	    String organiser;
	    

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getDetail() {
			return detail;
		}

		public void setDetail(String detail) {
			this.detail = detail;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getOrganiser() {
			return organiser;
		}

		public void setOrganiser(String organiser) {
			this.organiser = organiser;
		}

		public Event(String name, String detail, String type, String organiser) {
			super();
			this.name = name;
			this.detail = detail;
			this.type = type;
			this.organiser = organiser;
		}

    //Fill your code here
		abstract double calculateAmount();

}






EXHIBITION.JAVA:
public class Exhibition extends Event {

   private int noOfStalls;

    private double rentPerStalls;



    public int getNoOfStalls() {

        return noOfStalls;

    }



    public double getRentPerStalls() {

        return rentPerStalls;

    }



    public void setRentPerStalls(double rentPerStalls) {

        this.rentPerStalls = rentPerStalls;

    }



    public void setNoOfStalls(int noOfStalls) {

        this.noOfStalls = noOfStalls;

    }



    public Exhibition(String name, String detail, String type, String organiser, Integer noOfStalls, Double rentPerStall){

        super(name, detail, type, organiser);

        this.noOfStalls=noOfStalls;

        this.rentPerStalls=rentPerStall;

    }







    double calculateAmount(){

        return noOfStalls*rentPerStalls;

    }

}
 
 
STAGEEVENT.JAVA:
public class StageEvent extends Event {
    
    //Fill your code here
	   private int noOfShows;

	    private double costPerShow;
	    
	    public StageEvent(String name, String detail, String type, String organiser, Integer noOfShows,Double costPerShow){

	        super(name,detail,type,organiser);

	        this.noOfShows=noOfShows;

	        this.costPerShow=costPerShow;
		}



	double calculateAmount() {

        //Fill your code here

        return noOfShows*costPerShow;

    }  
	
}





MAIN.JAVA:
import java.util.Scanner;

public class Main {
    public static void main(String[] args)throws Exception{
		Scanner sc =new Scanner(System.in).useDelimiter("\n");
		System.out.println("Enter your choice\n1.Exhibition\n2.StageEvent");
		String eventType=sc.next();
		
		Event event=null;
		if(Integer.parseInt(eventType.trim())==1){
			System.out.println("Enter the details in CSV format");
			String input=sc.next();
			String[] inputs=input.split(",");
			
			event=new Exhibition(inputs[0].trim(), inputs[1].trim(), inputs[2].trim(), inputs[3].trim(), Integer.parseInt(inputs[4].trim()), Double.parseDouble(inputs[5].trim()));
            System.out.println("Exhibition Details");
            System.out.println("Event Name:"+event.name);
    	    System.out.println("Detail:"+event.detail);
		    System.out.println("Type:"+event.type);
		    System.out.println("Organiser Name:"+event.organiser);
		    System.out.println("Total Cost:"+String.format("%.1f", event.calculateAmount()));
		}
		else if(Integer.parseInt(eventType.trim())==2){
			System.out.println("Enter the details in CSV format");
			String input=sc.next();
			String[] inputs=input.split(",");
			event=new StageEvent(inputs[0].trim(), inputs[1].trim(), inputs[2].trim(), inputs[3].trim(), Integer.parseInt(inputs[4].trim()), Double.parseDouble(inputs[5].trim()));
            System.out.println("Stage Event Details");
            System.out.println("Event Name:"+event.name);
            System.out.println("Detail:"+event.detail);
		    System.out.println("Type:"+event.type);
		    System.out.println("Organiser Name:"+event.organiser);
		    System.out.println("Total Cost:"+String.format("%.1f", event.calculateAmount()));
		}
		else{
			System.out.println("Invalid choice");
		}
			
		}
	}
	

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.