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

Here is a sample run of the tester program: Make sure your program follows the J

ID: 3715962 • Letter: H

Question

Here is a sample run of the tester program:

Make sure your program follows the Java Coding Guidelines.

Consider the following class:

/**

* A store superclass with a Name and Sales Tax Rate

*/

public class Store

{

     public final double SALES_TAX_RATE = 0.06;

     private String name;

    

     /**

     * Constructor to create a new store

     * @param newName

     */

     public Store(String newName)

     {

          name = newName;

     }

    

     /**

     * Gets the store name

     * @return store name

     */

     public String getName()

     {

          return name;

     }

    

     /**

     * Sets the store name

     * @param newName

     */

     public void setName(String newName)

     {

          name = newName;

     }

    

     /**

     * Overrides the Object toString method

     */

     public String toString()

     {

          return("Name: " + name);

     }

}

Write a class WebStore, which inherits from Store. A web store has the following additional attributes: an Internet address and the programming language in which the website was written. Code the constructor, getter and setter methods for each instance variable and the toString method of the new class. Both the constructor and toString methods should call the constructor and toString method of the Store class.

Write a class MusicStore, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor, getter and setter methods for each instance variable and the toString method of the new class. Both the constructor and toString methods should call the constructor and toString method of the Store class.

Write a class 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, getter and setter methods for each instance variable and the toString method of the new class. In addition, code a method that returns the average overall taxes per year. Both the constructor and toString methods should call the constructor and toString method of the Store class.

Create a class named StoreTester that tests all of the constructors and methods. The tester program should create 2 Store, WebStore, MusicStore, and Restaurant objects.

Explanation / Answer

Here is the required code you asked. Everything is implemented as needed, explained using comments. In case if you have any doubts, drop a comment, Thanks.

// Store.java

/**

*

* A store superclass with a Name and Sales Tax Rate

*/

public class Store

{

                public final double SALES_TAX_RATE = 0.06;

                private String name;

                /**

                *

                * Constructor to create a new store

                *

                * @param newName

                */

                public Store(String newName)

                {

                                name = newName;

                }

                /**

                *

                * Gets the store name

                *

                * @return store name

                */

                public String getName()

                {

                                return name;

                }

                /**

                *

                * Sets the store name

                *

                * @param newName

                */

                public void setName(String newName)

                {

                                name = newName;

                }

                /**

                *

                * Overrides the Object toString method

                */

                public String toString()

                {

                                return ("Name: " + name);

                }

}

// WebStore.java

public class WebStore extends Store {

                // additional attributes

                private String internetAddress;

                private String programmingLanguage;

                // constructor

                public WebStore(String newName, String internetAddress,

                                                String programmingLanguage) {

                                //passing name to super class

                                super(newName);

                                this.internetAddress = internetAddress;

                                this.programmingLanguage = programmingLanguage;

                }

               

                //getters and setters

               

                public String getInternetAddress() {

                                return internetAddress;

                }

                public void setInternetAddress(String internetAddress) {

                                this.internetAddress = internetAddress;

                }

                public String getProgrammingLanguage() {

                                return programmingLanguage;

                }

                public void setProgrammingLanguage(String programmingLanguage) {

                                this.programmingLanguage = programmingLanguage;

                }

                @Override

                public String toString() {

                                //appending additional details and returning the super class String

                                return super.toString() + ", Internet Address: " + internetAddress

                                                                + ", Language used: " + programmingLanguage;

                }

}

// MusicStore.java

public class MusicStore extends Store {

                // additional attributes

                private int numTitles;

                private String address;

                // constructor

                public MusicStore(String newName, int numTitles, String address) {

                                //passing name to super class

                                super(newName);

                                this.numTitles = numTitles;

                                this.address = address;

                }

               

                //getters and setters

               

                public int getNumTitles() {

                                return numTitles;

                }

                public void setNumTitles(int numTitles) {

                                this.numTitles = numTitles;

                }

                public String getAddress() {

                                return address;

                }

                public void setAddress(String address) {

                                this.address = address;

                }

                @Override

                public String toString() {

                                //appending additional details and returning the super class String

                                return super.toString() + ", number of titles: " + numTitles

                                                                + ", address: " + address;

                }

}

// Restaurant.java

public class Restaurant extends Store {

                //additional attributes

                private int peopleServedEveryYear;

                private double averagePricePerPerson;

                // constructor

                public Restaurant(String newName, int peopleServedEveryYear,

                                                double averagePricePerPerson) {

                                //passing name to super class

                                super(newName);

                                this.peopleServedEveryYear = peopleServedEveryYear;

                                this.averagePricePerPerson = averagePricePerPerson;

                }

               

                //getters and setters

               

                public int getPeopleServedEveryYear() {

                                return peopleServedEveryYear;

                }

                public void setPeopleServedEveryYear(int peopleServedEveryYear) {

                                this.peopleServedEveryYear = peopleServedEveryYear;

                }

                public double getAveragePricePerPerson() {

                                return averagePricePerPerson;

                }

                public void setAveragePricePerPerson(double averagePricePerPerson) {

                                this.averagePricePerPerson = averagePricePerPerson;

                }

                /**

                * calculates and returns the average amount of tax paid per year

                */

                public double averageTaxPerYear() {

                                double averagePricePerYear = averagePricePerPerson

                                                                * peopleServedEveryYear;

                                double averageTaxPerYear = averagePricePerYear * SALES_TAX_RATE;

                                return averageTaxPerYear;

                }

                @Override

                public String toString() {

                                //appending additional details and returning the super class String

                                return super.toString() + ", People served every year: "

                                                                + peopleServedEveryYear + ", Average price per person: $"

                                                                + averagePricePerPerson;

                }

}

// StoreTester.java

public class StoreTester {

                public static void main(String[] args) {

                                /**

                                * Defining two objects of each classes and display the details

                                */

                                Store store1 = new Store("An ordinary store");

                                Store store2 = new Store("Another ordinary store");

                                WebStore webStore1 = new WebStore("Flipkart", "flipkart.com",

                                                                "PHP & HTML5");

                                WebStore webStore2 = new WebStore("MyStore", "mystore.com", "ASP.NET");

                                MusicStore musicStore1 = new MusicStore("Alice's ", 390,

                                                                "22nd building, Wall street");

                                MusicStore musicStore2 = new MusicStore("Vibe", 441,

                                                                "5- Raymond, Washington DC");

                                Restaurant restaurant1 = new Restaurant("Dad's cafe", 15000, 2.5);

                                Restaurant restaurant2 = new Restaurant("Foodland", 26789, 1.78);

                                System.out.println(store1);

                                System.out.println(store2);

                                System.out.println(webStore1);

                                System.out.println(webStore2);

                                System.out.println(musicStore1);

                                System.out.println(musicStore2);

                                System.out.println(restaurant1);

                                System.out.println("Average tax per year: $"

                                                                + restaurant1.averageTaxPerYear());

                                System.out.println(restaurant2);

                                System.out.println("Average tax per year: $"

                                                                + restaurant2.averageTaxPerYear());

                }

}

//output

Name: An ordinary store

Name: Another ordinary store

Name: Flipkart, Internet Address: flipkart.com, Language used: PHP & HTML5

Name: MyStore, Internet Address: mystore.com, Language used: ASP.NET

Name: Alice's , number of titles: 390, address: 22nd building, Wall street

Name: Vibe, number of titles: 441, address: 5- Raymond, Washington DC

Name: Dad's cafe, People served every year: 15000, Average price per person: $2.5

Average tax per year: $2250.0

Name: Foodland, People served every year: 26789, Average price per person: $1.78

Average tax per year: $2861.0652

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