create a class called TableService It will have number of choices as an integer.
ID: 3709248 • Letter: C
Question
create a class called TableService It will have number of choices as an integer. It will have the taxes as a double It will have the constructor that inherits the place name and the price per person from Party along with the data members for this TableService class It will have a showInfo() method that will show all values from super class of Party and this class. It will have a calcCost() method that will return the cost of the Table service party based on the number of guests, the price per Person and the taxes. Create a tester class. It will have a Buffet object and TableService object For the Buffet, it will create this object after the user enters in location place, price, number of dishes and taxes. For TableService, it will create an object with any name location you pass, any price per person you pass, any number of choices you pass and any taxes you pass ALL at time of object creation. Output the cost of the party for 100 guests for Buffet in correct money format and for TableService in correct money format
Explanation / Answer
public class Party {
// Member variables
private String place;
private double pricePerPerson;
/**
* Constructor , Will be used to create new objects of this class
*/
public Party(String place, double pricePerPerson) {
super();
this.place = place;
this.pricePerPerson = pricePerPerson;
}
//Getters and Setters
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public double getPricePerPerson() {
return pricePerPerson;
}
public void setPricePerPerson(double pricePerPerson) {
this.pricePerPerson = pricePerPerson;
}
@Override
public String toString() {
return "Place = " + place + ", Price Per Person = " + pricePerPerson;
}
}
public class TableService extends Party{
private int numberOfChoices;
private double taxes;
/**
* Constructor , Will be used to create new objects of this class
*/
public double getTaxes() {
return taxes;
}
public TableService(String place, double pricePerPerson, int numberOfChoices, double taxes) {
super(place, pricePerPerson);
this.numberOfChoices = numberOfChoices;
this.taxes = taxes;
}
public void setTaxes(double taxes) {
this.taxes = taxes;
}
//Method to show the details
public void showInfo()
{
//calling using super to get parent class data
System.out.println(super.toString()+" Taxes = "+taxes);
}
/***
*
* @return cost of the Table service party based on the number of guests, the price per Person and the taxes
*/
public double calcCost()
{
return numberOfChoices*getPricePerPerson()+taxes;
}
}
public class Buffet extends Party {
private int numberOfDishes;
private double taxes;
/**
* Constructor , Will be used to create new objects of this class
*/
public Buffet(String place, double pricePerPerson, int numberOfDishes, double taxes) {
super(place, pricePerPerson);
this.numberOfDishes = numberOfDishes;
this.taxes = taxes;
}
public Buffet(String place, double pricePerPerson) {
super(place, pricePerPerson);
// TODO Auto-generated constructor stub
}
public int getNumberOfDishes() {
return numberOfDishes;
}
public void setNumberOfDishes(int numberOfDishes) {
this.numberOfDishes = numberOfDishes;
}
public double getTaxes() {
return taxes;
}
public void setTaxes(double taxes) {
this.taxes = taxes;
}
// Method to show the details
public void showInfo() {
// calling using super to get parent class data
System.out.println(super.toString() + " , Taxes = " + taxes + " , Number Of Dishes = " + numberOfDishes);
}
/***
*
* @return cost of the Table service party based on the number of guests, the
* price per Person and the taxes
*/
public double calcCost(int numberOfPersons) {
return numberOfPersons * getPricePerPerson() + taxes;
}
}
import java.util.Scanner;
import javafx.scene.control.Tab;
public class TestParty {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Please enter location Place : ");
String location=sc.nextLine();
System.out.println("Please enter Price ");
double price=sc.nextDouble();
//clear buffer
sc.nextLine();
System.out.println("Please enter number of dishes : ");
int dishes=sc.nextInt();
System.out.println("Please enter taxes : ");
double taxes=sc.nextDouble();
//Create Buffet Object
Buffet buffet=new Buffet(location, price, dishes, taxes);
System.out.println("----------------------------------------");
//Print details
buffet.showInfo();
System.out.println("----------------------------------------");
//Calculate cost
double cost=buffet.calcCost(100);
System.out.println("Cost of 100 Buffet is = "+cost);
//Create table Service Object .
TableService service=new TableService("New Delhi India", 500, 10, 100);
//Call show method
System.out.println("----------------------------------------");
service.showInfo();
System.out.println("----------------------------------------");
System.out.println("Cost of Table Service " +service.calcCost());
}
}
Output:
Please enter location Place :
Algarh
Please enter Price
1000
Please enter number of dishes :
5
Please enter taxes :
200
----------------------------------------
Place = Algarh, Price Per Person = 1000.0 , Taxes = 200.0 , Number Of Dishes = 5
----------------------------------------
Cost of 100 Buffet is = 100200.0
----------------------------------------
Place = New Delhi India, Price Per Person = 500.0 Taxes = 100.0
----------------------------------------
Cost of Table Service 5100.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.