Inheritance

OVERRIDING-SIMPLE

Sample Input/Output 1:

Enter the name of the event:
Science Fair
Enter the detail of the event:
Explore Technology
Enter the owner name of the event:
ABCD
Enter the type of the event:
1.Exhibition
2.StageEvent
1
Enter the number of stalls:
65
The projected revenue of the event is 650000.0

Sample Input/Output 2:

Enter the name of the event:
Magic Show
Enter the detail of the event:
See Magic without Logic
Enter the owner name of the event:
SDFG
Enter the type of the event:
1.Exhibition
2.StageEvent
2
Enter the number of shows:
10
Enter the number of seats per show:
100
The projected revenue of the event is 50000.0

CODE:

public abstract class Event {

    String name,detail,ownerName;
    
    Event(String name, String detail, String ownerName){
        this.name=name;
    this.detail=detail;
    this.ownerName=ownerName;
    }
    
    
    
    public String getName() {
return name;
}



public String getDetail() {
return detail;
}


public String getOwnerName() {
return ownerName;
}


public abstract Double projectedRevenue();
    

}


class Exhibition extends Event {
    
Integer noOfStalls;
double revenue;
      
Exhibition(String name, String detail, String ownerName, Integer noOfStalls){
super(name,detail,ownerName);
this.noOfStalls=noOfStalls;
}

public Double projectedRevenue() {
revenue=10000*noOfStalls;
return revenue;
}
}

class StageEvent extends Event {
    
double revenue;
Integer noOfShows,noOfSeatsPerShow;
StageEvent(String name, String detail, String ownerName, Integer noOfShows, Integer noOfSeatsPerShow){
super(name,detail,ownerName);
this.noOfShows=noOfShows;
this.noOfSeatsPerShow=noOfSeatsPerShow;
}
public Double projectedRevenue() {
revenue=50*noOfSeatsPerShow*noOfShows;
return revenue;
}

      
          //your code here
}

import java.io.IOException;
import java.util.Scanner;

 

public class Main {
    public static void main(String[] args) throws IOException {
         Scanner sc = new Scanner(System.in);
         System.out.println("Enter the name of the event:");
         String name=sc.nextLine();
         System.out.println("Enter the detail of the event:");
         String detail=sc.nextLine();
         System.out.println("Enter the owner name of the event:");
         String owner=sc.nextLine();      
         System.out.println("Enter the type of the event:\n1.Exhibition\n2.StageEvent");
         int n=sc.nextInt();
         switch (n)
         {
            case 1:
                System.out.println("Enter the number of stalls:");
                int stall=sc.nextInt();
                Event e=new Exhibition(name,detail,owner,stall);
                System.out.println("The projected revenue of the event is "+e.projectedRevenue());
                break;
            case 2:
                System.out.println("Enter the number of shows:");
                int show=sc.nextInt();
                System.out.println("Enter the number of seats per show:");
                int seat=sc.nextInt();
                Event s=new StageEvent(name,detail,owner,show,seat);
                System.out.println("The projected revenue of the event is "+s.projectedRevenue());
                break;
         }
    }
}

Comments

Popular posts from this blog