0% found this document useful (0 votes)
686 views5 pages

GST Calculation

The document contains Java code that calculates GST for events. It defines classes for Exhibition, StageEvent and a parent Event class. The code takes user input for event details, creates the appropriate object and calls the totalCost method to calculate the total cost including GST. Exhibition and StageEvent classes extend Event and override the GST percentage and totalCost method to calculate GST accordingly.

Uploaded by

Sharko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
686 views5 pages

GST Calculation

The document contains Java code that calculates GST for events. It defines classes for Exhibition, StageEvent and a parent Event class. The code takes user input for event details, creates the appropriate object and calls the totalCost method to calculate the total cost including GST. Exhibition and StageEvent classes extend Event and override the GST percentage and totalCost method to calculate GST accordingly.

Uploaded by

Sharko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

GST CALCULATION

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter event name");
String name=sc.nextLine();
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){

/*create a reference to the event class and assign it to


the exhibition instance and call the appropriate method in it*/
System.out.println("Enter the number of stalls");
int noOfStalls=sc.nextInt();
Exhibition ex=new Exhibition(name, "Exhibition", costPerDay, noOfDays, noOfStalls);
System.out.println(ex);

}
else if(type==2){

System.out.println("Enter the number of seats");


int noOfSeats=sc.nextInt();
StageEvent se=new StageEvent(name, "Stage Event", costPerDay, noOfDays, noOfSeats);
System.out.println(se);

}
else{
System.out.println("Invalid input");
}

}
}
class Exhibition extends Event{

static Integer gst = 5;


Integer noOfStalls;

public Exhibition(String name, String type, Double costPerDay, Integer noOfDays, Integer
noOfStalls) {
super(name, type, costPerDay, noOfDays);
this.noOfStalls = noOfStalls;
}

public static Integer getGst() {


return gst;
}

public static void setGst(Integer gst) {


Exhibition.gst = gst;
}

public Integer getNoOfStalls() {


return noOfStalls;
}

public void setNoOfStalls(Integer noOfStalls) {


this.noOfStalls = noOfStalls;
}

public Double totalCost() {

Double d = noOfDays*costPerDay;
Double gstAm=(d/100)*gst;
return d+gstAm;
}

public String toString() {


return String.format("Event Details\r\n" +
"Name:%s\r\n" +
"Type:%s\r\n" +
"Number of stalls:%s\r\n" +
"Total amount: %2f", name,type,noOfStalls,totalCost());
}
}

class StageEvent extends Event{

public StageEvent(String name, String type, Double costPerDay, Integer noOfDays, Integer
noOfSeats) {
super(name, type, costPerDay, noOfDays);
this.noOfSeats = noOfSeats;
}

static Integer gst = 15;


Integer noOfSeats;

public static Integer getGst() {


return gst;
}

public static void setGst(Integer gst) {


StageEvent.gst = gst;
}
public Integer getNoOfSeats() {
return noOfSeats;
}

public void setNoOfSeats(Integer noOfSeats) {


this.noOfSeats = noOfSeats;
}

public Double totalCost() {

Double d = noOfDays*costPerDay;
Double gstAm=(d/100)*gst;

return d+gstAm;

public String toString() {


return String.format("Event Details\r\n" +
"Name:%s\r\n" +
"Type:%s\r\n" +
"Number of seats:%s\r\n" +
"Total amount: %2f", name,type,noOfSeats,totalCost());
}
}

class Event{

String name;
String type;
Double costPerDay;
Integer noOfDays;
public Event(String name, String type, Double costPerDay, Integer noOfDays) {
super();
this.name = name;
this.type = type;
this.costPerDay = costPerDay;
this.noOfDays = noOfDays;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Double getCostPerDay() {
return costPerDay;
}
public void setCostPerDay(Double costPerDay) {
this.costPerDay = costPerDay;
}
public Integer getNoOfDays() {
return noOfDays;
}
public void setNoOfDays(Integer noOfDays) {
this.noOfDays = noOfDays;
}

You might also like