1 / 3100%
public class Restaurant {
//instance variables seats and name
private int seats;
protected String name;
//constructor to initialize seats and name
public Restaurant(int seats,String name) {
this.seats = seats;
this.name = name;
}
public int getSeats() {
return seats;
}
public void setSeats(int seats) {
this.seats = seats;
}
@Override
public String toString() {
return name+"\n"+seats+" seats"; //return name and seats
}
}
FastFood.java
public class FastFood extends Restaurant {
//instance variable slogan
private String slogan;
//constructor for initializing all the variables
public FastFood(int seats, String name,String slogan) {
super(seats, name);
this.slogan = slogan;
}
public String getSlogan() {
return slogan;
}
public void setSlogan(String slogan) {
this.slogan = slogan;
}
//increase the seats and set
public void increaseSeats(int seats) {
this.setSeats(this.getSeats()+seats);
}
@Override
public String toString() {
return name+" - "+"\""+slogan+"\""; //print tostring in this format
}
}
FastFoodDemo.java
import java.util.Scanner;
public class FastFoodDemo {
//main method
public static void main(String[] args) {
Scanner sc =new Scanner(System.in); //scanner object
int seats = sc.nextInt(); //input number of seats
sc.nextLine();
String name = sc.nextLine(); //input name
String slogan = sc.nextLine(); //input slogan
FastFood fastFood = new FastFood(seats, name, slogan); //fastFood variable
int increaseSeats = sc.nextInt(); //input increaseSeats
fastFood.increaseSeats(increaseSeats); //increase seats
System.out.println(fastFood); //print object
System.out.println(fastFood.getSeats()+" seats"); //print seats with newline
}
}
Students also viewed