Please write in Java ONLY Write a class encapsulating a rest

Please write in Java ONLY!

Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass.

Code for Store below(Super class aka Parent class)

public class Store
{
public final double SALES_TAX_RATE = 0.06;
private String name;

/**
* Overloaded constructor:<BR>
* Allows client to set beginning value for name
* This constructor takes one parameter<BR>
* Calls mutator method
* @param newName the name of the store
*/
public Store( String newName )
{
setName( newName );
}

/** getName method
* @return a String, the name of the store
*/
public String getName( )
{
return name;
}

/**
* Mutator method:<BR>
* Allows client to set value of name
* @param newName the new name for the store
*/
public void setName( String newName )
{
name = newName;
}

/**
* @return a string representation of the store
*/
public String toString( )
{
return( \"name: \" + name );
}

/**
* equals method
* Compares two Store objects for the same field value
* @param o another Store object
* @return a boolean, true if this object
* has the same field value as the parameter s
*/
public boolean equals( Object o )
{
if ( ! ( o instanceof Store ) )
return false;
else
{
Store s = (Store) o;
return ( name.equalsIgnoreCase( s.name ) );
}//end else

}//end equals method


}//end class

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

public class Restaurant extends Store{

    private int peopleServed;
    private double avgPricePerPerson;
  
    public Restaurant(String newName,int peopleServed,double avgPricePerPerson) {
        super(newName);
        this.peopleServed = peopleServed;
        this.avgPricePerPerson = avgPricePerPerson;
    }
  
    public int getPeopleServedPerYear()
    {
        return peopleServed;
    }
  
    public double getAvgPricePerPerson()
    {
        return avgPricePerPerson;
    }
  
    public void setPeopleServedPerYear()
    {
        this.peopleServed = peopleServed;
    }
  
    public void setAvgPricePerPerson()
    {
        this.avgPricePerPerson = avgPricePerPerson;
    }
  
    public double getAvgTaxPerYear()
    {
        return SALES_TAX_RATE*peopleServed*avgPricePerPerson;
    }
  
    public String toString()
    {
        return \"Restuarant \" + super.toString() + \".We serve \" + peopleServed + \" number of people per year.\";
    }
  
    public boolean equals( Object o )
    {
        if ( ! ( o instanceof Restaurant ) )
            return false;
        else
        {
            Restaurant s = (Restaurant) o;
            return ( this.getName().equalsIgnoreCase( s.getName() ) );
        }//end else

    }//end equals method

  
  
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;


public class TestRestaturant {

  
    public static void main(String[] args)
    {
        Store s = new Store(\"Burger King\");
        System.out.println(s.getName());
      
        Restaurant r = new Restaurant(\"McDonald\", 100, 120.00);
        System.out.println(r);
        System.out.println(\"Avg tax per year is : \"+r.getAvgTaxPerYear());
    }
}

OUTPUT:

run:
Burger King
Restuarant name: McDonald.We serve 100 number of people per year.
Avg tax per year is : 720.0
BUILD SUCCESSFUL (total time: 0 seconds)

Please write in Java ONLY! Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many pe
Please write in Java ONLY! Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many pe
Please write in Java ONLY! Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many pe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site