Create a class called Restaurant that is the base class for all restaurants. It
ID: 3854853 • Letter: C
Question
Create a class called Restaurant that is the base class for all restaurants. It should have attributes for the restaurant's name and numSeats.(number of seats inside the restaurant). It should have appropriate accessor and mutator methods for each of the attributes and a toString that prints the name and the number of seats. Derive a class FastFoodRestaurant from Restaurant. The new class should override the accessor method for the numSeats, reporting actual seats times 2 (twice the number of seats in a restaurant because it also counts the parking spots where people eat in their cars as restaurant seating). It also should override the toString method so that it includes the correct number of seats and the restaurant ad slogan "Best Burgers Ever!" For example, the toString in the FastFoodRestaurant might return [Welcome to Bob's Burgers with 30 seats. "Best Burgers liver!"] Write an appropriate demo class that full tests both Restaurant and FastFoodRestaurant.Explanation / Answer
Hi,
Belw is the code in java-
class Restaurant{
private String name;
private int numSeats;
Restaurant(String name1,int count)
{
name=name1;
numSeats=count;
}
public void setname(String nm)
{
name=nm;
}
public int getname()
{
return name;
}
public void setnumSeats(int count1)
{
numSeats=count1;
}
public int getnumSeats()
{
return numSeats;
}
public void toString()
{
System.out.println("Name : "+name);
System.out.println("Number of seats : "+numSeats;
}
}
class FastFoodRestaurant extends Restaurant{
public int getnumSeats()
{
return 2*numSeats;
}
public void toString()
{
System.out.println("Welcome to Bobs Burger's with %s +"Best Burger Ever "+numSeats;
}
public static void main( String args[]) {
FastFoodRestaurant fr1=new FastFoodRestaurant ()
fr1.getnumSeats();
fr1.toString();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.