Question

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

Here is a sample run of the tester program:

output

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Here is a sample run of the tester program: Make sure your program follows the Java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, 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...

  • How to solve this problem? Consider the following class : public class Store Public final double...

    How to solve this problem? Consider the following class : public class Store Public final double SALES TAX_RATE = 0.063B private String name; public Store(String newName) setName ( newName); public String getName () { return name; public void setName (String newName) { name = newName; public String toString() return "name: “ + name; Write a class encapsulating a web store, which inherits from Store. A web store has the following additional attributes: an Internet Address and the programming language in...

  • Create the following program in java please Write a class Store which includes the attributes: store...

    Create the following program in java please Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a...

  • JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you...

    JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student...

    Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”. Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also...

  • Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java.   Create two child classes...

    Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java.   Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods.   In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT