Question

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 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..

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

Please find the code below::

BooksTester.java

package classes1;

class Store{
   private String name;
   private double salesTaxRate;


   public Store() {
       super();
       this.name="";
       this.salesTaxRate = 0;
   }

   public Store(Store s) {
       this.name=s.name;
       this.salesTaxRate = s.salesTaxRate;
   }

   public Store(String name, double salesTaxRate) {
       super();
       this.name = name;
       this.salesTaxRate = salesTaxRate;
   }

   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public double getSalesTaxRate() {
       return salesTaxRate;
   }
   public void setSalesTaxRate(double salesTaxRate) {
       this.salesTaxRate = salesTaxRate;
   }

   @Override
   public String toString() {
       return "Store [name=" + name + ", salesTaxRate=" + salesTaxRate + "]";
   }

   public boolean equals(Store obj) {
       if(name.equals(obj.name) && salesTaxRate==obj.salesTaxRate){
           return true;
       }else{
           return false;
       }
   }

}


class BookStore extends Store{
   private int countOfBookSold;
   private double averagePrice;

   public BookStore(int countOfBookSold, double averagePrice) {
       super();
       this.countOfBookSold = countOfBookSold;
       this.averagePrice = averagePrice;
   }

   public BookStore(Store s,int countOfBookSold, double averagePrice) {
       super(s);
       this.countOfBookSold = countOfBookSold;
       this.averagePrice = averagePrice;
   }

   public int getCountOfBookSold() {
       return countOfBookSold;
   }
   public void setCountOfBookSold(int countOfBookSold) {
       this.countOfBookSold = countOfBookSold;
   }
   public double getAveragePrice() {
       return averagePrice;
   }
   public void setAveragePrice(double averagePrice) {
       this.averagePrice = averagePrice;
   }

   public boolean equals(BookStore obj) {
       if(this.getName().equals(obj.getName()) &&
               this.getSalesTaxRate()==obj.getSalesTaxRate() &&
               this.averagePrice==obj.averagePrice && this.countOfBookSold==obj.countOfBookSold){
           return true;
       }else{
           return false;
       }
   }
  
   double getAverageTaxPerYear(){
       return countOfBookSold*averagePrice*getSalesTaxRate()/100;
   }

   @Override
   public String toString() {
       return "BookStore [ name ="
               + getName() + ",countOfBookSold=" + countOfBookSold + ", averagePrice=" + averagePrice + ",SalesTaxRate =" + getSalesTaxRate();
   }

}
public class BooksTester {
   public static void main(String[] args) {
       Store myStore = new Store("Books & Me", 24);
       System.out.println(myStore);
       BookStore store1 = new BookStore(myStore, 900, 12);
       System.out.println("Store 1 total book sold : "+store1.getCountOfBookSold());
       System.out.println("Store 1 average book price : "+store1.getAveragePrice());
       System.out.println("Store 1 total sale amount : "+store1.getCountOfBookSold()*store1.getAveragePrice());
       System.out.println("Store 1 tax amount : "+store1.getSalesTaxRate());
       System.out.println("Store 1 average taxes per year : "+store1.getAverageTaxPerYear());
      
       BookStore store2 = new BookStore(myStore, 124, 2);
       System.out.println(store2);
   }
}

output:

Add a comment
Know the answer?
Add Answer to:
Create the following program in java please Write a class Store which includes the attributes: store...
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 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 Store which includes the attributes: store name, city. Write another class encapsulating an...

    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 returning the...

  • 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...

  • 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: 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;      }     ...

  • write a class encapsulating the concept of a student assuming that the student has the following...

    write a class encapsulating the concept of a student assuming that the student has the following attributes the name of student the average of the student the rite a class encapsulating the concept of a Student, assuming that the Student has the following attributes: the name of the student, the average of the student, and the student's GPA. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Also include a method returning the...

  • Write a class encapsulating a music store, which inherits from Store. A music store has the...

    Write a class encapsulating a music store, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor and the toString method of the new class. You also need to include a client class (with the main method) to test your code.

  • In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and...

    In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: 1. description - which is a string 2. write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money...

  • Write a class encapsulating the concept of a vendor, if a vendor has the following attributes:...

    Write a class encapsulating the concept of a vendor, if a vendor has the following attributes: company name, id, array of quarterly purchase order totals (4 double elements). Include a constructor, accessor, mutator, and toString methods. Also code the following methods: one returning the total purchase orders (total all array elements) and a method to modify an array element (change the value of an array element). Write a client class to create 2 vendor objects and test all your methods.

  • You will need to first create an object class encapsulating a Trivia Game which INHERITS from...

    You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...

  • Write a class encapsulating the concept of a television set, assuming a television set has the...

    Write a class encapsulating the concept of a television set, assuming a television set has the following attributes: a brand and a price. include a constructor, the accessors and mutators, and methods to string and equals. Write a client class to test all the methods in your class.

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