Question

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 average number of paintings per artist for a year.

You should create a test class which creates 2 Art Gallery objects, then calls your set methods, get methods, toString and equals methods and the method to calculate the average paintings per artist for the Art Gallery objects.

please explain the equal methods too. I don't understand the equal method. how to write, why to write, and what does it do. thank you

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

Answer;

class Store
{
private String storeName;
private double taxRate;

public Store(String storeName,double taxRate)// constructor
{
  this.storeName = storeName;
  this.taxRate = taxRate;
}

public String toString()
{
  return "Store Name : "+storeName + " Tax Rate : "+taxRate;
}

public boolean equals(Store s)
{
if(this.getStoreName() == s.getStoreName() && this.taxRate == s.taxRate)
return true;
else
return false;
}

//get and set methods
public String getStoreName()
{
  return storeName;
}
public void setStoreName(String storeName)
{
  this.storeName = storeName;
}
public double getTaxRate()
{
  return taxRate;
}

public void setTaxRate(double taxRate)
{
  this.taxRate = taxRate;
}
}

class BookStore extends Store
{
private int booksSold;
private double avgPrice;

public BookStore(String name,double taxRate,int booksSold,double avgPrice)
{
super(name,taxRate); // call to base class constructor
this.booksSold = booksSold;
this.avgPrice = avgPrice;
}

public String toString()
{
return "Book"+super.toString() + " Number of books sold : "+booksSold +"   Average price per book : $"+avgPrice;

}

//get and set methods
public int getBooksSold()
{
return booksSold;
}

public void setBooksSold(int booksSold)
{
this.booksSold = booksSold;
}
public double getAvgPrice()
{
return avgPrice;
}
public void setAvgPrice(double avgPrice)
{
this.avgPrice = avgPrice;
}
public boolean equals(BookStore b)
{
if(this.getStoreName() == b.getStoreName() && this.getTaxRate() == b.getTaxRate() && this.booksSold == b.booksSold && this.avgPrice == b.avgPrice)
return true;
else
return false;
}

public double avgTaxPerYear()
{
return booksSold * getTaxRate();
}
}
class Test
{
public static void main (String[] args)
{
  Store store = new Store("More",18.5);
  System.out.println(store);
  
  BookStore bs1 = new BookStore("A Novel Idea",4.56,2000,123.65);
  System.out.println(bs1);
  
  BookStore bs2 = new BookStore("BookBerries",3.28,3005,99.45);
  System.out.println(bs2);
  
  System.out.println("Average tax per year : $"+ bs2.avgTaxPerYear());
  
  if(bs1.equals(bs2))
  System.out.println("Both book stores are same");
  else
  System.out.println("Book stores are not same ");
}
}

Output:

Store Name : More Tax Rate : 18.5
BookStore Name : A Novel Idea Tax Rate : 4.56 Number of books sold : 2000   Average price per book : $123.65
BookStore Name : BookBerries Tax Rate : 3.28 Number of books sold : 3005   Average price per book : $99.45
Average tax per year : $9856.4
Book stores are not same

If You Like It Plz Rate

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

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

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

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

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

  • In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now...

    In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which...

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

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

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

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
ADVERTISEMENT