Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Topic - 3 E-Box

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Topic – 3

Single inheritance
Write a Java program to implement Single Inheritance.

[Note: Strictly adhere to the object oriented specifications given as a part of the problem
statement. Use the same class names and member variable names.
Follow the naming conventions mentioned for getters/setters]

Consider a class named Person with the following private data members.

Data Type Data Member


String name
String dateOfBirth
String gender
String mobileNumber
String bloodGroup

Include appropriate getters and setters.

Consider a class named Donor which extends Person class with the following private data
members.
Data Type Data Member
String bloodBankName
String donorType
String donationDate

Include appropriate getters and setters.

The class Donor should have the following method


Method Description
This method displays the donation details.
public void displayDonationDetails( )
Display the statement ‘Donation Details :’ inside this method

Consider another class Main and write the main method to test the above class.

In the main( ) method, read the person and donor details from the user and call the
displayDonationDetails( ) method.

[Note: The date format should be “dd-MM-yyyy”]

The link to download the template code is given below


Code Template

Input and Output Format:


Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:


Enter the name :
Justin
Enter Date of Birth :
11-01-1995
Enter Gender :
Male
Enter Mobile Number :
9994910354
Enter Blood Group :
B+ve
Enter Blood Bank Name :
Blood Assurance
Enter Donor Type :
Whole Blood
Enter Donation Date :
09-07-2017
Donation Details :
Name : Justin
Date Of Birth : 11-01-1995
Gender : Male
Mobile Number : 9994910354
Blood Group : B+ve
Blood Bank Name : Blood Assurance
Donor Type : Whole Blood
Donation Date : 09-07-2017

Sample Input and Output 2:


Enter the name :
Steffie
Enter Date of Birth :
12-01-1996
Enter Gender :
Female
Enter Mobile Number :
8868875432
Enter Blood Group :
O+ve
Enter Blood Bank Name :
Edward Blood Bank
Enter Donor Type :
Whole Blood
Enter Donation Date :
21-12-2016
Donation Details :
Name : Steffie
Date Of Birth : 12-01-1996
Gender : Female
Mobile Number : 8868875432
Blood Group : O+ve
Blood Bank Name : Edward Blood Bank
Donor Type : Whole Blood
Donation Date : 21-12-2016
Answer
import java.io.*;
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 the name :");
String name=sc.next();
System.out.println("Enter Date of Birth :");
String dateOfBirth=sc.next();
System.out.println("Enter Gender :");
String gender=sc.next();
System.out.println("Enter Mobile Number :");
String mobileNumber=sc.next();
System.out.println("Enter Blood Group :");
String bloodGroup=sc.next();
System.out.println("Enter Blood Bank Name :");

String bloodBankName=sc.next();
System.out.println("Enter Donor Type :");

String donorType=sc.next();
System.out.println("Enter Donation Date :");
String donationDate=sc.next();
Donor donor=new Donor();
donor.setName(name);
donor.setDateOfBirth(dateOfBirth);
donor.setGender(gender);
donor.setMobileNumber(mobileNumber);
donor.setBloodGroup(bloodGroup);
donor.setBloodBankName(bloodBankName);

donor.setDonorType(donorType);
donor.setDonationDate(donationDate);
donor.displayDonationDetails();
}
}
class Donor extends Person {
private String bloodBankName;
private String donorType;
private String donationDate;
public String getBloodBankName() {
return bloodBankName;
}
public void setBloodBankName(String bloodBankName) {
this.bloodBankName = bloodBankName;
}
public String getDonorType() {
return donorType;
}
public void setDonorType(String donorType) {
this.donorType = donorType;
}
public String getDonationDate() {
return donationDate;
}
public void setDonationDate(String donationDate) {
this.donationDate = donationDate;
}
public void displayDonationDetails(){
System.out.println("Donation Details :");
System.out.println("Name : " +getName());
System.out.println("Date Of Birth : " +getDateOfBirth());
System.out.println("Gender : " +getGender());
System.out.println("Mobile Number : " +getMobileNumber());
System.out.println("Blood Group : " +getBloodGroup());
System.out.println("Blood Bank Name : " +getBloodBankName());
System.out.println("Donor Type : " +getDonorType());
System.out.println("Donation Date : " +getDonationDate());
}
}

class Person {
private String name;
private String dateOfBirth;
private String gender;
private String mobileNumber;
private String bloodGroup;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(String dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMobileNumber() {
return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}
public String getBloodGroup() {
return bloodGroup;
}
public void setBloodGroup(String bloodGroup) {
this.bloodGroup = bloodGroup;
}

Calculate Reward Points

ABC Bank announced a new scheme of reward points for a transaction using an ATM card.
Each transaction using the normal card will be provided 1% of the transaction amount as a
reward point. If a transaction is made using a premium card and it is for fuel expenses,
additional 10 points will be rewarded. Write a java program to calculate the total reward points.

[Note: Strictly adhere to the object-oriented specifications given as a part of the


problem statement.
Follow the naming conventions as mentioned]
Consider a class VISACard with the following method.
Method Description
public Double computeRewardPoints(String type, Double amount) This method returns t

Consider a class HPVISACard which extends VISACard class and overrides the following

Method Description
public Double computeRewardPoints(String type, Double amount) In this method, calculate the reward points from the base
method.

Hint:

Use super keyword to calculate reward points from base class.

Consider the Main class with the main method and read all the transaction details in the main
method.
Card type will be either ‘VISA card’ or ‘HPVISA card’. Otherwise, display ‘Invalid data’

Calculate the reward points corresponding to the card type and transaction type and print the
reward points(upto two decimal places).

The link to download the template code is given below


Code Template

Input and Output Format:

Refer sample input and output for formatting specifications.


Enter the transaction details in CSV format ( Transaction type, amount, card type)

All text in bold corresponds to the input and the rest corresponds to output.

Sample Input and Output 1:

Enter the transaction detail


Shopping,5000,VISA card
Total reward points earned in this transaction is 50.00
Do you want to continue?(Yes/No)
Yes
Enter the transaction detail
Fuel,5000,HIVISA card
Invalid data
Do you want to continue?(Yes/No)
Yes
Enter the transaction detail
Fuel,5000,HPVISA card
Total reward points earned in this transaction is 60.00
Do you want to continue?(Yes/No)
No
Sample Input and Output 2:

Enter the transaction detail


Fuel,1000,HPVISA card
Total reward points earned in this transaction is 20.00
Do you want to continue?(Yes/No)
No

class HPVISACard extends VISACard{

public Double computeRewardPoints(String type, Double amount){

Double rewardPoints = super.computeRewardPoints(type,amount);

if(type.equalsIgnoreCase("fuel")){

rewardPoints +=10;

return rewardPoints;

import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args){

Scanner sc=new Scanner(System.in).useDelimiter("\n");

VISACard visaCard;
String contd;
do{
System.out.println("Enter the transaction detail");
String input=sc.next();
String[] inputs=input.split(",");
if(inputs[2].equals("VISA card")){
visaCard=new VISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDoubl
e(inputs[1]));

System.out.println("Total reward points earned in this transaction is


"+String.format("%.2f",reward));
}
else if(inputs[2].equals("HPVISA card")){
visaCard=new HPVISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDoub
le(inputs[1]));

System.out.println("Total reward points earned in this transaction is


"+String.format("%.2f",reward));
}
else{
System.out.println("Invalid data");
}
System.out.println("Do you want to continue?(Yes/No)");
contd=sc.next();

}
while(contd.equalsIgnoreCase("Yes"));
}
}

public class VISACard {

public Double computeRewardPoints(String type, Double amount){

Double rewardPoints = amount/100;

return rewardPoints;

}
GST Calculation
Write a program to calculate the total amount with GST for the events. The Events are
Stage show and Exhibition. For the Stage show, GST will be 15% and for exhibition,
GST will be 5%.

[Note: Strictly adhere to the object oriented specifications given as a part of the
problem statement.
Follow the naming conventions as mentioned]

Consider class Event with the following protected attributes/variables.


Data Type Variable
String name
String type
Double costPerDay
Integer noOfDays

Prototype for the parametrized constructor,


public Event(String name, String type, Double costPerDay, Integer noOfDays)

Consider class Exhibition which extends the Event class with the following private
attributes/variables.
Data Type Variable
static Integer gst = 5
Integer noOfStalls

Prototype for the parametrized constructor,


public Exhibition(String name, String type, Double costPerDay, Integer noOfDays,
Integer noOfStalls)

Include appropriate getters and setters.

Include the following method.


Method Name Description
public Double totalCost() This method is to calculate the total amount with 5% GST

Consider class StageEvent which extends the Event class with the following private
attributes/variables.
Data Type Variable
static Integer gst = 15
Integer noOfSeats

Prototype for the parametrized constructor,


public StageEvent(String name, String type, Double costPerDay, Integer
noOfDays, Integer noOfSeats)

Include appropriate getters and setters.

Include the following method.


Method Name Description
public Double totalCost() This method is to calculate the total amount with 15% GST

Override toString() method in all classes to display the event details in the format
specified in sample input and output.

Consider Main class with main method.


In the main() method, read the event details from the user and then create the object of
the event according to the event type.
The total amount will be calculated according to the GST of the corresponding event.

The link to download the template code is given below


Code Template

Input and Output Format:

Refer sample input and output for formatting specifications.


All the double values should formatted to two decimal places.

All text in bold corresponds to the input and the rest corresponds to output.

Sample Input and Output 1:

Enter event name


Sky Lantern Festival
Enter the cost per day
1500
Enter the number of days
3
Enter the type of event
1.Exhibition
2.Stage Event
2
Enter the number of seats
100
Event Details
Name:Sky Lantern Festival
Type:Stage Event
Number of seats:100
Total amount: 5175.00

Sample Input and Output 2:

Enter event name


Glastonbury
Enter the cost per day
5000
Enter the number of days
2
Enter the type of event
1.Exhibition
2.Stage Event
1
Enter the number of stalls
10
Event Details
Name:Glastonbury
Type:Exhibition
Number of stalls:10
Total amount: 10500.00

Sample Input and Output 3:

Enter event name


Glastonbury
Enter the cost per day
5000
Enter the number of days
2
Enter the type of event
1.Exhibition
2.Stage Event
3
Invalid input

public class Event {


protected String name, type;
protected double costPerDay;
protected int noOfDays;

public Event(String name, String type, double costPerDay, int noOfDays) {


this.costPerDay = costPerDay;
this.type = type;
this.name = name;
this.noOfDays = noOfDays;

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");
}
}
}

import java.text.DecimalFormat;

public 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 noOfDa


ys, Integer noOfStalls){
super(name,type,costPerDay,noOfDays);
this.name=name;
this.type=type;
this.costPerDay=costPerDay;
this.noOfStalls=noOfStalls;
this.noOfDays=noOfDays;
}
public Double totalCost(){
amt1 = costPerDay*noOfDays*1.05;

return amt1;
}
public String toString(){
return "Event Details\n"+"Name:"+name+"\n"+"Type:"+type+"\n"+"Number of s
talls:"+noOfStalls+"\n"+"Total amount:"+df.format(totalCost());

}
import java.text.DecimalFormat;

public 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 noOfDa


ys, 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 s
eats:"+getNoOfSeats()+"\n"+"Total amount:"+df.format(totalCost());
}

Abstract Class
Write a program to calculate total cost of the event based on the type of event and display
details using Abstract class and method.

Strictly adhere to the Object-Oriented specifications given in the problem


statement. All class names, attribute names and method names should be the same
as specified in the problem statement.

Consider an abstract class called Event with following protected attributes.


Attributes Datatype
name String
detail String
type String
organiser String

Prototype for the parametrized constructor, Event(String name, String detail, String
type, String organiser)
Include appropriate getters and setters

Include the following abstract method in the class Event.


Method Name Description
abstract Double calculateAmount() an abstract method

Consider a class named Exhibition which extends Event class with the following private
attributes
Attributes Datatype
noOfStalls Integer
rentPerStall Double

Prototype for the parametrized constructor,


public Exhibition(String name, String detail, String type, String organiser, Integer
noOfStalls,Double rentPerStall)
Include appropriate getters and setters
Use super( ) to call and assign values in base class constructor.

Include the following abstract method in the class Exhibition.


Method Name Description
Double calculateAmount () This method returns the product of noOfStalls and rentPerStall

Consider a class named StageEvent which extends Event class with the following
private attributes.
Attribute Datatype
noOfShows Integer
costPerShow Double

Prototype for the parametrized constructor,


public StageEvent(String name, String detail, String type, String organiser, Integer
noOfShows,Double costPerShow)
Include appropriate getters and setters
Use super( ) to call and assign values in base class constructor.
Include the following abstract method in the class StageEvent.
Method Name Description
Double calculateAmount() This method returns the product of noOfShows and costPerShow

Consider a driver class called Main. In the main method, obtain input from the user and
create objects accordingly.

The link to download the template code is given below


Code Template

Input format:
Input format for Exhibition is in the CSV format
(name,detail,type,organiser,noOfStalls,rentPerStall)
Input format for StageEvent is in the CSV
format (name,detail,type,organiser,noOfShows,costPerShow)

Output format:
Print "Invalid choice" if the input is invalid to our application and terminate.
Display one digit after the decimal point for Double datatype.
Refer to sample Input and Output for formatting specifications.

[All text in bold corresponds to the input and rest corresponds to output]

Sample Input and output 1:


Enter your choice
1.Exhibition
2.StageEvent
1
Enter the details in CSV format
Book expo,Special sale,Academics,Martin,100,1000
Exhibition Details
Event Name:Book expo
Detail:Special sale
Type:Academics
Organiser Name:Martin
Total Cost:100000.0

Sample Input and Output 2:


Enter your choice
1.Exhibition
2.StageEvent
2
Enter the details in CSV format
JJ magic show,Comedy magic,Entertainment,Steffania,5,1000
Stage Event Details
Event Name:JJ magic show
Detail:Comedy magic
Type:Entertainment
Organiser Name:Steffania
Total Cost:5000.0

Sample Input and Output 3:


Enter your choice
1.Exhibition
2.StageEvent
3
Invalid choice

public abstract class Event {


protected String name;
protected String detail;
protected String type;
protected String organiser;

public Event(String name, String detail, String type, String organiser) {


this.name = name;
this.detail = detail;
this.type = type;
this.organiser = 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;
}
abstract Double calculateAmount();
}

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 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].tr
im(), inputs[3].trim(), Integer.parseInt(inputs[4].trim()), Double.parseDouble(in
puts[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.calculat
eAmount()));
}
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].tr
im(), inputs[3].trim(), Integer.parseInt(inputs[4].trim()), Double.parseDouble(in
puts[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.calculat
eAmount()));
}
else{
System.out.println("Invalid choice");
}

}
}

public class Exhibition extends Event {

private Integer noOfStalls;


private Double rentPerStall;

public Exhibition(String name, String detail, String type, String organiser,


Integer noOfStalls,Double rentPerStall) {
super(name, detail, type, organiser);
this.noOfStalls = noOfStalls;
this.rentPerStall = rentPerStall;

}
public Integer getNoOfStalls() {
return noOfStalls;
}
public void setNoOfStalls(Integer noOfStalls) {
this.noOfStalls = noOfStalls;
}
public Double getRentPerStall() {
return rentPerStall;
}
public void setRentPerStall(Double rentPerStall) {
this.rentPerStall = rentPerStall;
}

Double calculateAmount() {
double a=getRentPerStall();
double b=getNoOfStalls();
double c=a*b;
return c;
}

public class StageEvent extends Event {


private Integer 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;
}
public Integer getNoOfShows() {
return noOfShows;
}

public void setNoOfShows(Integer noOfShows) {


this.noOfShows = noOfShows;
}

public Double getCostPerShow() {


return costPerShow;
}

public void setCostPerShow(Double costPerShow) {


this.costPerShow = costPerShow;
}

Double calculateAmount() {
double z=getNoOfShows();
double y=getCostPerShow();
double x=z*y;

return x;

Overriding
Overriding is a runtime polymorphism. The inherited class has the overridden method
which has the same name as the method in the parent class. The argument number,
types, or return types should not differ in any case. The method is invoked with the
object of the specific class ( but with the reference of the parent class).

Write a program to calculate projected revenue for exhibition and stage event using
inheritance and method overriding

[Note :
Strictly adhere to the object-oriented specifications given as a part of the problem
statement.
Use the same class names and member variable names. ]
Consider a parent class Event and define the following protected attributes,
Attributes Datatype
name String
detail String
ownerName String

Include appropriate getters and setters.


Prototype for the parameterized constructors to the Event class in the following
order Event(String name, String detail, String ownerName)

Declare the abstract method public abstract Double projectedRevenue() in the Event
class

Consider a child class Exhibition that extends Event that defines with the
following attribute,
Attributes Datatype
noOfStalls Integer
Include appropriate getters and setters.
Prototype for the parameterized constructors to the Exhibition class in the following
order Exhibition(String name, String detail, String ownerName, Integer
noOfStalls). Use super( ) to call and assign values in the base class constructor.
Implement the abstract method projectedRevenue() in Exhibition class
MethodName Description
public Double projectedRevenue() Calculate revenue and return the double value. Each stall will prod

Consider another child class StageEvent that extends Event that defines with the
following attribute,

Attributes Datatype
noOfShows Integer
noOfSeatsPerShow Integer
Include appropriate getters and setters.
Prototype for the parameterized constructors to the StageEvent class in the following
order StageEvent(String name, String detail, String ownerName, Integer
noOfShows, Integer noOfSeatsPerShow). Use super( ) to call and assign values in
the base class constructor.
Implement the abstract method projectedRevenue() in StageEvent class
MethodName Description
public Double projectedRevenue() Calculate revenue and return the double value. Each seat produc

Consider the class Main. It includes the method main. In the main( ) method the event
details are read from the user and the methods of the above classes are called

The link to download the template code is given below


Code Template

Input and Output Format:

Refer to sample input/output for other further details and format of the output.
The double values should be formatted to 1 decimal place .

[All Texts in bold corresponds to the input and rest are output]

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

abstract class Event{


protected String name;
protected String detail;
protected String ownerName;

public Event(String name, String detail, String ownerName, Integer noOfStalls)


{
this.name = name;
this.detail = detail;
this.ownerName = ownerName;
}

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 getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

abstract public Double projectedRevenue();

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.StageE
vent");
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.pro
jectedRevenue());
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.pro
jectedRevenue());
break;
}
}
}

class Exhibition extends Event {

protected Integer noOfStalls;

public Exhibition(String name, String detail, String ownerName, Integer noOf


Stalls){
super(name, detail, ownerName, noOfStalls);
this.noOfStalls = noOfStalls;
}

public Integer getNoOfStalls() {


return noOfStalls;
}

public void setNoOfStalls(Integer noOfStalls) {


this.noOfStalls = noOfStalls;
}

public Double projectedRevenue() {


double a=getNoOfStalls();
double g=10000.0;
double b=g*a;
return b;

class StageEvent extends Event {

protected Integer noOfShows;


protected Integer noOfSeatsPerShow;

public StageEvent(String name, String detail, String ownerName, Integer noOfSt


alls, int seat) {
super(name, detail, ownerName, noOfStalls);
this.noOfShows = noOfStalls;
this.noOfSeatsPerShow = seat;

}
public Integer getNoOfShows(){
return noOfShows;
}
public void setNoOfShows(Integer noOfShows) {
this.noOfShows = noOfShows;
}
public Integer getNoOfSeatsPerShow() {
return noOfSeatsPerShow;
}
public void setNoOfSeatsPerShow(Integer noOfSeatsPerShow) {
this.noOfSeatsPerShow = noOfSeatsPerShow;
}

public Double projectedRevenue() {

double z=getNoOfShows();
double y=getNoOfSeatsPerShow();
double x=50.0;
double w=z*y;
double v=w*x;
return v;

You might also like