Question

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

in JAVA

Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein.

Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn 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 Yarn Store objects, then calls your set methods, get methods, toString and equals methods and average taxes per year for the Yarn Store objects.

Homework Answers

Answer #1

Store.java

public class Store {
private String name;
private double salesTaxRate;
  
public Store()
{
this.name = "";
this.salesTaxRate = 0;
}

public Store(String name, double salesTaxRate) {
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 boolean equals(Object other)
{
if(other instanceof Store)
{
if(this.name.equals(((Store) other).name) && this.salesTaxRate == ((Store) other).salesTaxRate)
return true;
}
return false;
}
  
@Override
public String toString()
{
return("Store Name: " + this.name + "\nSales Tax Rate: " + this.salesTaxRate + "%");
}
}

YarnStore.java

public class YarnStore extends Store{
private int nSkeinsOfYarnSoldPerYear;
private double avgPricePerSkein;
  
public YarnStore()
{
super();
this.nSkeinsOfYarnSoldPerYear = 0;
this.avgPricePerSkein = 0;
}
  
public YarnStore(String name, double salesTaxRate, int nSkeinsOfYarnSoldPerYear, double avgPricePerSkein)
{
super(name, salesTaxRate);
this.nSkeinsOfYarnSoldPerYear = nSkeinsOfYarnSoldPerYear;
this.avgPricePerSkein = avgPricePerSkein;
}

public int getnSkeinsOfYarnSoldPerYear() {
return nSkeinsOfYarnSoldPerYear;
}

public void setnSkeinsOfYarnSoldPerYear(int nSkeinsOfYarnSoldPerYear) {
this.nSkeinsOfYarnSoldPerYear = nSkeinsOfYarnSoldPerYear;
}

public double getAvgPricePerSkein() {
return avgPricePerSkein;
}

public void setAvgPricePerSkein(double avgPricePerSkein) {
this.avgPricePerSkein = avgPricePerSkein;
}
  
@Override
public boolean equals(Object other)
{
if(super.equals(other))
{
if(other instanceof YarnStore)
{
if(this.nSkeinsOfYarnSoldPerYear == ((YarnStore) other).nSkeinsOfYarnSoldPerYear
&& this.avgPricePerSkein == ((YarnStore) other).avgPricePerSkein)
return true;
}
}
return false;
}
  
public double averageTaxPerYear()
{
return ((super.getSalesTaxRate() / 100) * this.nSkeinsOfYarnSoldPerYear * this.avgPricePerSkein);
}
  
@Override
public String toString()
{
return(super.toString() + "\nAverage number of skeins of yarn sold per year: " + this.nSkeinsOfYarnSoldPerYear
+ "\nAverage price per skein of yarn: $" + String.format("%.2f", this.avgPricePerSkein)
+ "\nAverage tax per year: $" + String.format("%.2f", averageTaxPerYear()));
}
}

YarnStoreTest.java (Driver class)

public class YarnStoreTest {
  
public static void main(String[] args)
{
Store store = new Store("XYZ Stores", 12.5);
  
YarnStore ys1 = new YarnStore();
ys1.setName("ABC Stores");
ys1.setSalesTaxRate(store.getSalesTaxRate());
ys1.setnSkeinsOfYarnSoldPerYear(340);
ys1.setAvgPricePerSkein(56.5);
  
YarnStore ys2 = new YarnStore();
ys2.setName("DEF Stores");
ys2.setSalesTaxRate(store.getSalesTaxRate());
ys2.setnSkeinsOfYarnSoldPerYear(500);
ys2.setAvgPricePerSkein(100);
  
System.out.println("Displaying the Store object details...\n" + store.toString());
  
System.out.println("\nDisplaying the First YarnStore object details...\n" + ys1.toString());
  
System.out.println("\nDisplaying the Second YarnStore object details...\n" + ys2.toString());
  
System.out.println("\nYarnStore 1 equals YarnStore 2: " + ys1.equals(ys2) + "\n");
}
}

***************************************************************** SCREENSHOT **********************************************************

Know the answer?
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
Similar Questions
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....
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of...
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of type String, custName of type String and checkingBalance of type double and savingBalance of type double 2)Write the constructor for CustomerAccount class. The constructor takes parameters to initialize custID, custName, checkingBalance and savingBalance. 3)Write the mutator method for all attributes of the class CustomerAccount. then Write the toString method for class CustomerAccount.
Java: Write a class Cow with attributes name (string) and numLegs (int). Do not make the...
Java: Write a class Cow with attributes name (string) and numLegs (int). Do not make the attributes private. Make a constructor with two parameters to instantiate the attributes, and a toString method that prints only the name, a comma, a space, and the number of legs (e.g. Bossie, 3). Add a main method that makes two cows, Bossie with 3 legs and Elsie with 4 legs, and puts them into an ArrayList. Print the ArrayList, one element per line, using...
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
JAVA Write a Student class with a String name and double gpa class members. Write a...
JAVA Write a Student class with a String name and double gpa class members. Write a constructor, get and set methods, and a toString method.
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT