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 |
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 |
public Exhibition(String name, String detail, String type, String organiser, Integer noOfStalls,Double rentPerStall)
Include appropriate getters and setters
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
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:
Sample Input and Output 2:
Invalid choice
PROGRAM:
CLASS 1:
public abstract class Event {
public String name,detail,type,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();
double calculateAmount;
}
CLASS 2:
public class Exhibition extends Event {
private int 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 int getNoOfStalls() {
return noOfStalls;
}
public void setNoOfStalls(int noOfStalls) {
this.noOfStalls = noOfStalls;
}
public double getRentPerStall() {
return rentPerStall;
}
public void setRentPerStall(double rentPerStall) {
this.rentPerStall = rentPerStall;
}
Double calculateAmount() {
calculateAmount = getNoOfStalls() * getRentPerStall();
return calculateAmount;
}
}
CLASS 3:
public class StageEvent extends Event {
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;
}
public int getNoOfShows() {
return noOfShows;
}
public void setNoOfShows(int noOfShows) {
this.noOfShows = noOfShows;
}
public double getCostPerShow() {
return costPerShow;
}
public void setCostPerShow(double costPerShow) {
this.costPerShow = costPerShow;
}
Double calculateAmount() {
double calculateAmount = getNoOfShows() * getCostPerShow();
return calculateAmount;
}
CLASS 4:
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].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");
}
}
}
INPUT OUTPUT:
Sample Input and Output 2:
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 the 1% of the transaction amount as reward points |
Consider a class HPVISACard which extends VISACard class and overrides the following method.
Method | Description |
public Double computeRewardPoints(String type, Double amount) | In this method, calculate the reward points from the base class and add 10 points if it is for fuel expense |
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
PROGRAM:
CLASS 1:
public class VISACard {
public Double computeRewardPoints(String type, Double amount){
//Double computeRewardPoints = *0.01;
amount = amount/100;
return amount;
}
}
class HPVISACard extends VISACard{
public Double computeRewardPoints(String type, Double amount){
if(type.equals("Fuel")){
amount = (amount*0.01)+10;}
else{
amount = (amount*0.01);
}
//Double computeRewardPoints = (super.computeRewardPoints(type, amount)*0.01)+10;
return amount;
}
}
Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.
VISITE MORE BLOGS
Well done bro
ReplyDelete