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

Create a Java NetBeans project named RestaurantClient with the main class named

ID: 3851466 • Letter: C

Question

Create a Java NetBeans project named RestaurantClient with the main class named RestaurantClient, Add two service classes to the project, a superclass named Store and a subclass named Restaurant which will encapsulate a restaurant and inherit from class Store. Data encapsulated in class Store will be the restaurant name and a constant tax rate, Data encapsulated in class Restaurant will be the number of people served yearly and the average price per person. Code the appropriate constructor, mutator, accessor, toString and equals methods for both service classes. Code a method in the Restaurant class to return the average taxes per year. In the client application class you will instantiate Restaurant class objects and write statements (method calls) to test the methods in your student service classes. Download and follow the instructions in the attached file above to complete Programming Exercise 4. After successfully compiling and executing your exercise upload the zipped project folder to Programming Exercise 4.

Explanation / Answer

package restaurantclient;

import java.util.Objects;


/**
*
* @author Sam
*/
class Store {
    String name;
    double taxRate;

    public Store(String name) {
        setName(name);
        taxRate = 14.5;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Store{" + "name=" + name + ", taxRate=" + taxRate + '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Store other = (Store) obj;
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (Double.doubleToLongBits(this.taxRate) != Double.doubleToLongBits(other.taxRate)) {
            return false;
        }
        return true;
    }

  
}


class Restaurant extends Store {
    int peopleServed;
    double averagePrice;

    public Restaurant(int customerServed, double avgPrice, String name) {
        super(name);
        setPeopleServed(customerServed);
        setAveragePrice(avgPrice);
    }

    public int getPeopleServed() {
        return peopleServed;
    }

    public void setPeopleServed(int customerServed) {
        if (customerServed < 0) {
            System.err.println("Customer serverd cannot be less than zero");
            return;
        }
        this.peopleServed = customerServed;
    }

    public double getAveragePrice() {
        return averagePrice;
    }

    public void setAveragePrice(double averagePrice) {
        if (averagePrice < 0) {
            System.err.println("Average price cannot be less than zero");
            return;
        }
        this.averagePrice = averagePrice;
    }

    @Override
    public String toString() {
        return "Restaurant{" + "peopleServed=" + peopleServed + ", averagePrice=" + averagePrice + '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Restaurant other = (Restaurant) obj;
        if (this.peopleServed != other.peopleServed) {
            return false;
        }
        if (Double.doubleToLongBits(this.averagePrice) != Double.doubleToLongBits(other.averagePrice)) {
            return false;
        }
      
        if (!super.getName().equals(other.getName()))
            return false;
        return true;
    }

    public double averageTaxes() {
        return taxRate / 100 * averagePrice * peopleServed;
    }
  
}


/**
*
* @author Sam
*/
public class RestaurantClient {
    public static void main(String[] args) {
        Restaurant r1, r2;
        r1 = new Restaurant(400, 20, "Alpha");
        r2 = new Restaurant(600, 22, "Beta");
      
        System.out.println(r1);
        System.out.println(r2);
      
        r2.setAveragePrice(20);
        r2.setPeopleServed(400);
      
        System.out.println("r1 = r2? " + r1.equals(r2));
      
        r2.setName("Alpha");
      
        System.out.println("r1 = r2? " + r1.equals(r2));
      
        System.out.println("Avg of restauran 1 is " + r1.getAveragePrice());
    }
}

Please chk the answer. I hope you will love it!