Question: Class _ Method Part 1 Write down the code for creating a class, Restaurant, It should have the following functionality. Data An instance variable, name,

Class_Method
Part 1
Write down the code for creating a class, Restaurant, It should have the following functionality.
Data
An instance variable, name, of type String
An instance variable, rate, of type int
Method
A constructor without any parameters, that initialize above variables.
Another constructor that initializes the above variables with arguments received by class user.
Methods that return the value of defined variables.
Methods that set the value of above variables.
Part 2
Now, add the main method.
Create 2 instances of the class Restaurant.
Call set and get methods for these objects.
After your program is finished, copy and paste the program output below.
import java.util.*;
public class Restaurant {
private String name ="";
private int rate =0;
//constructor
public Restaurant ()
{
name ="No Name";
rate =-1;
}
// xxx your codes
public static void main(String[] args)
{
Restaurant A = new Restaurant();
Restaurant B = new Restaurant("myRes",5);
List arr = Arrays.asList (A, B );
for (Restaurant r: arr ){
int rate = r.getRate();
String name = r.getName();
System.out.println(rate+""+name);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!