Question

In: Computer Science

Write a class Store which includes the attributes: store name and sales tax rate. Write another...

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 method returning the average taxes per year.

You should create a test class which creates 1 Store object and 2 Book Store objects, then calls your set methods, get methods, toString and equals methods and average taxes per year for the Book Store objects..

Solutions

Expert Solution

Since you have not mentioned the language of your preference, I am providing the code in Java.

CODE

Store.java

public class Store {

protected String storeName;

protected double salesTaxRate;

public Store(String storeName, double salesTaxRate) {

this.storeName = storeName;

this.salesTaxRate = salesTaxRate;

}

public String getStoreName() {

return storeName;

}

public void setStoreName(String storeName) {

this.storeName = storeName;

}

public double getSalesTaxRate() {

return salesTaxRate;

}

public void setSalesTaxRate(double salesTaxRate) {

this.salesTaxRate = salesTaxRate;

}

@Override

public String toString() {

return "Store [storeName=" + storeName + ", salesTaxRate=" + salesTaxRate + "]";

}

}

BookStore.java

public class BookStore extends Store {

private int sold;

private double avgPricePerBook;

public BookStore(String storeName, double salesTaxRate, int sold, double avgPricePerBook) {

super(storeName, salesTaxRate);

this.sold = sold;

this.avgPricePerBook = avgPricePerBook;

}

public int getSold() {

return sold;

}

public void setSold(int sold) {

this.sold = sold;

}

public double getAvgPricePerBook() {

return avgPricePerBook;

}

public void setAvgPricePerBook(double avgPricePerBook) {

this.avgPricePerBook = avgPricePerBook;

}

public double getAverageTaxPerYear() {

return avgPricePerBook * sold * salesTaxRate;

}

@Override

public String toString() {

return "BookStore [sold=" + sold + ", avgPricePerBook=" + avgPricePerBook + "]";

}

}

Main.java

public class Main {

public static void main(String[] args) {

Store s1 = new Store("Store1", 0.15);

System.out.println(s1);

BookStore bs1 = new BookStore("Store1", 0.15, 15, 67.99);

System.out.println(bs1);

System.out.println("Average tax per year for Book store 1: $" + bs1.getAverageTaxPerYear());

BookStore bs2 = new BookStore("Store1", 0.15, 20, 70.99);

bs2.setStoreName("Store2");

bs2.setSalesTaxRate(19);

bs2.setSold(20);

bs2.setAvgPricePerBook(99.99);

System.out.println(bs2);

System.out.println("Average tax per year for Book store 2: $" + bs2.getAverageTaxPerYear());

}

}


Related Solutions

IN JAVA!   Write a class Store which includes the attributes: store name, city. Write another class...
IN JAVA!   Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Write a class Car that contains the following attributes: The name of car The direction of...
Write a class Car that contains the following attributes: The name of car The direction of car (E, W, N, S) The position of car (from imaginary zero point) The class has the following member functions: A constructor to initialize the attributes. Turn function to change the direction of car to one step right side (e.g. if the direction is to E,it should be changed to S and so on.) Overload the Turn function to change the direction to any...
Write a Python class to represent a Salik account. The account has three attributes, a name,...
Write a Python class to represent a Salik account. The account has three attributes, a name, id, and the balance. The balance is a private attribute. The class has extra functions to add to the balance and reduce the balance. Both, these functions should return the current balance and if the balance is below AED 50.0 print the message “Note: Balance Below 50”. Your class must work for the code given below. #Test myCar = SalikAccount() myCar.setName("John") myCar.setID("190300300333") myCar.setBal(20.0) yourCar...
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
Write a Java class. The class name must be ShapeMetrics, which means the file name must...
Write a Java class. The class name must be ShapeMetrics, which means the file name must be ShapeMetrics.java. Provide the following functions: 1. getAreaOfRectangle(), with two float arguments, width and height, in that order, returning a float value which is the area of the rectangle with that width and height. 2. getSpaceDiagonalOfRectangularCuboid (), with three float arguments, width, height, and depth, in that order, returning a float value which is the length of the diagonal line which bisects the cuboid....
Write a Python program that creates a class which represents a Student Grade. The class includes...
Write a Python program that creates a class which represents a Student Grade. The class includes a function that reads a text file called Course_Score.txt. A sample of the file is provided below. Each row in the file corresponds to the Last Name, First Name, ClassWork score (100), Mid-Term score (100), and Final-Exam score (100). Also include the the following functions to process the content read from the file. a. getData(): This method reads the data from a file and...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class should add private attributes for years of experience and the annual salary. This class should also provide...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT