Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a new class called Store This class will store information about a restau

ID: 3744209 • Letter: D

Question

Define a new class called Store This class will store information about a restaurant.

The Restaurant should keep track the following information about the restaurant:

The name of the restaurant.

The restaurant’s cuisine

The Address of the restaurant (include street, City, state and zip code)

Whether it has liquor store license or not.

Whether it is kid’s friendly or not.

The restaurant class need to also implement:

A constructor for populating the restaurant.

Setter and getter methods for all its private attributes.

Any additional methods you think might be useful for completing this exercise.

Define a class called RestaurantCatalog.This class will model a catalog or restaurants that can be edited, and searched.

The RestaurantCatalog class should maintain a list of Restaurant objects in a java array (DO NOT USE ARRAYLIST). It must also provide methods for:

Adding a new Restaurant.
Result: a new restaurant object is added onto the list.

Search a restaurant by its name.
Result: Returns a reference to the restaurant class that matches the information.

Define a class classed MyApp that includes a main method. This class will serve as the entry point of your application. Within the main method, write code to instantiate a RestaurantCatalog, populate the catalog with information for five restaurants (you can choose the information). Issue a search command to look for a restaurant by name, and display it.

Explanation / Answer

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks

// Restaurant.java

public class Restaurant {

      private String name;

      private String cuisine;

      private String streetAddress;

      private String cityAddress;

      private String stateAddress;

      private String zipcode;

      private boolean liquorStoreLicense;

      private boolean kidsFriendly;

      /**

      * Constructor with values to initialize all fields

      */

      public Restaurant(String name, String cuisine, String streetAddress,

                  String cityAddress, String stateAddress, String zipcode,

                  boolean liquorStoreLicense, boolean kidsFriendly) {

            this.name = name;

            this.cuisine = cuisine;

            this.streetAddress = streetAddress;

            this.cityAddress = cityAddress;

            this.stateAddress = stateAddress;

            this.zipcode = zipcode;

            this.liquorStoreLicense = liquorStoreLicense;

            this.kidsFriendly = kidsFriendly;

      }

      /**

      * Default constructor

      */

      public Restaurant() {

            // setting default values

            name = "";

            cuisine = "";

            streetAddress = "";

            cityAddress = "";

            stateAddress = "";

            zipcode = "";

            liquorStoreLicense = false;

            kidsFriendly = true;

      }

     

      //getters and setters

      public String getName() {

            return name;

      }

      public void setName(String name) {

            this.name = name;

      }

      public String getCuisine() {

            return cuisine;

      }

      public void setCuisine(String cuisine) {

            this.cuisine = cuisine;

      }

      public String getStreetAddress() {

            return streetAddress;

      }

      public void setStreetAddress(String streetAddress) {

            this.streetAddress = streetAddress;

      }

      public String getCityAddress() {

            return cityAddress;

      }

      public void setCityAddress(String cityAddress) {

            this.cityAddress = cityAddress;

      }

      public String getStateAddress() {

            return stateAddress;

      }

      public void setStateAddress(String stateAddress) {

            this.stateAddress = stateAddress;

      }

      public String getZipcode() {

            return zipcode;

      }

      public void setZipcode(String zipcode) {

            this.zipcode = zipcode;

      }

      public boolean hasLiquorStoreLicense() {

            return liquorStoreLicense;

      }

      public void setLiquorStoreLicense(boolean liquorStoreLicense) {

            this.liquorStoreLicense = liquorStoreLicense;

      }

      public boolean isKidsFriendly() {

            return kidsFriendly;

      }

      public void setKidsFriendly(boolean kidsFriendly) {

            this.kidsFriendly = kidsFriendly;

      }

      @Override

      public String toString() {

            //returning a properly formatted string

            String data = "Name: " + name + " ";

            data += "Cuisine: " + cuisine + " ";

            data += "Address: " + streetAddress + ", " + cityAddress + ", "

                        + stateAddress + ", ZIP: " + zipcode + " ";

            data += "Liquor Store License: " + liquorStoreLicense + " ";

            data += "Kids Friendly: " + kidsFriendly + " ";

            return data;

      }

}

// RestaurantCatalog.java

public class RestaurantCatalog {

      // array of Restaurants

      private Restaurant[] restaurantList;

      // current count of restaurants

      private int count = 0;

      // capcity of array

      private static final int DEFAULT_CAPACITY = 20;

      // default constructor

      public RestaurantCatalog() {

            restaurantList = new Restaurant[DEFAULT_CAPACITY];

            count = 0;

      }

      /**

      * method to add a Restaurant

      *

      * @param r

      *            - Restaurant object to be added

      */

      public void addRestaurant(Restaurant r) {

            // adding if array isnt full

            if (count < restaurantList.length) {

                  restaurantList[count] = r;

                  count++;

            }

      }

      /**

      * method to search a Restaurant by name

      *

      * @param name

      *            name of Restaurant

      * @return Restaurant object if found, else null

      */

      public Restaurant search(String name) {

            for (int i = 0; i < count; i++) {

                  if (restaurantList[i].getName().equalsIgnoreCase(name)) {

                        return restaurantList[i]; // match found

                  }

            }

            return null;// not found

      }

}

// MyApp.java

public class MyApp {

      public static void main(String[] args) {

            // creating a RestaurantCatalog

            RestaurantCatalog catalog = new RestaurantCatalog();

            // creating some restaurants, using constructor

            Restaurant r1 = new Restaurant("Delicious Dishes", "Indian", "123",

                        "Mumbai", "Maharashtra", "223441", false, true);

            Restaurant r2 = new Restaurant("Bonjour", "French", "2nd Street",

                        "Alleppey", "Kerala", "123456", true, false);

            Restaurant r3 = new Restaurant("Taj", "Indian-Chinese",

                        "Hillbill Nagar", "Chennai", "Tamil Nadu", "112233", false,

                        true);

            Restaurant r4 = new Restaurant("Barbecue Nation", "Indian-Thai",

                        "Hobli", "Mysore", "Karnataka", "0445550", true, false);

            // creating one restaurant,setting values using setters

            Restaurant r5 = new Restaurant();

            r5.setName("Amaze");

            r5.setCuisine("Thai");

            r5.setStateAddress("ABC street");

            r5.setCityAddress("Transylvania");

            r5.setStateAddress("KYZ");

            r5.setZipcode("898988");

            r5.setLiquorStoreLicense(true);

            r5.setKidsFriendly(false);

            // adding all restaurants to the catalog

            catalog.addRestaurant(r1);

            catalog.addRestaurant(r2);

            catalog.addRestaurant(r3);

            catalog.addRestaurant(r4);

            catalog.addRestaurant(r5);

            // searching for a restaurant and displaying the results

            Restaurant result = catalog.search("Bonjour");

            System.out.println("Search result for Restaurant named Bonjour: "

                        + result);

      }

}

/*OUTPUT*/

Search result for Restaurant named Bonjour:

Name: Bonjour

Cuisine: French

Address: 2nd Street, Alleppey, Kerala, ZIP: 123456

Liquor Store License: true

Kids Friendly: false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote