Question: 1. Store class a super class called Store which will have below member variables, constructor, and methods. Member variables: a final variable - SALES_TAX_RATE =

1. Storeclass

a super class called Store which will have below member variables, constructor, and methods.

Member variables:

  • a final variable - SALES_TAX_RATE = 0.06
  • String name;

Constructor:

  • Takes one parameter for name and calls mutator method setName to set the name of the store

setName method:

  • to set the name fields value

getName method:

  • to return a String, the name of the store

toString method:

  • to return a string representation of the store

2. GroceryStoreclass

another class called GroceryStore which extends the parent class Store with below member variables, methods and constructor -

Member variables

  • double annualRevenues;
  • boolean chain;

Constructor:

  • Takes 3 parameters. It allows client to set beginning value for annualRevenues and chain by calling the setter methods. Also calls super constructor to set value for name.

getAnnualRevenues method:

  • return a double, the annual revenues

getChain method:

  • return a boolean, true if the store is part of a chain, false otherwise

setAnnualRevenues method:

- allows client to set value of annualRevenues

- condition: if annualRevenues is negative, then annualRevenues is not changed

setChain method:

  • allows client to set value of chain

toString method:

  • return a string representation of the grocery store

annualTaxes method: Computes the annual taxes paid by the store. It is SALES_TAX_RATE times Annual Revenues. Return a double, the annual taxes paid by the store.

public double annualTaxes( )

{

return ( SALES_TAX_RATE * annualRevenues );

}

3. Mainclass

Instantiate the GroceryStore class from a client (Main) application with below values. Print the store details by calling the toString() method, to the console

GroceryStore gs1 = new GroceryStore( "Eddie's", 3523450.45, false );

GroceryStore gs2 = new GroceryStore( "Giant 43", 4321090.65, true );

System.out.println( gs1.toString() );

System.out.println( gs2.toString() );

Call the annualTaxes() method on each of the GroceryStore instances to print the annual taxes paid by each stores

gs1. annualTaxes();

gs2.annualTaxes();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!