Create 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:<BR>
* Allows client to set beginning value for name
* This constructor takes one parameter<BR>
* Calls mutator method setName to set the name of the store
* @param name the name of the store
*/
/** getName method
* @return a String, the name of the store
*/
/**
* Mutator method setName:<BR>
* Allows client to set value of name
* @param name the new name for the store
*/
/**
* toString()
* @return a string representation of the store
*/
========================
Create another class called GroceryStore which extends the parent class Store with below member variables, methods and constructor –
Member variables
double annualRevenues;
boolean chain;
/**
* Constructor:<BR>
* Allows client to set beginning value for annualRevenues and chain
* This constructor takes three parameters<BR>
* Calls super constructor to set store name
* Calls mutator methods to set annual revenue and chain
* @param name the new name for the store
* @param annualRevenues the new annual revenues
* @param chain the new value of whether the store is part of a chain
*/
/** getAnnualRevenues method
* @return a double, the annual revenues
*/
/** getChain method
* @return a boolean, true if the store is part of a chain, false otherwise
*/
/**
* Mutator method:<BR>
* Allows client to set value of annualRevenues
* @param annualRevenues the new annual revenues
* if annualRevenues is negative, then annualRevenues is not changed
*/
/**
* Mutator method:<BR>
* Allows client to set value of chain
* @param chain the new 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
*/
================================
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 );
Call the annualTaxes() method on each of the GroceryStore instances to print the annual taxes paid by each stores
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
//Store.java
public class Store {
//final sales tax amount
protected static final double SALES_TAX_RATE = 0.06;
//name of store
private String name;
//constructor
public Store(String name) {
setName(name);
}
//getter and setter for name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//returns a String containing store info
public String toString() {
return "Store [name=" + name + "]";
}
}
//GroceryStore.java extended from Store
public class GroceryStore extends Store {
private double annualRevenues;
private boolean chain;
//constructor
public GroceryStore(String name, double annualRevenues, boolean chain) {
//passing name to super class constructor
super(name);
setAnnualRevenues(annualRevenues);
setChain(chain);
}
//getters and setters
public double getAnnualRevenues() {
return annualRevenues;
}
public boolean getChain() {
return chain;
}
public void setAnnualRevenues(double annualRevenues) {
//updating annualRevenues if parameter is positive
if (annualRevenues >= 0)
this.annualRevenues = annualRevenues;
}
public void setChain(boolean chain) {
this.chain = chain;
}
public String toString() {
return "GroceryStore [name=" + getName() + ", annualRevenues="
+ annualRevenues + ", chain=" + chain + "]";
}
//calculates and returns the tax amount
public double annualTaxes() {
return annualRevenues * SALES_TAX_RATE;
}
}
//Main.java
public class Main {
public static void main(String[] args) {
// creating GroceryStore objects
GroceryStore gs1 = new GroceryStore("Eddie's", 3523450.45, false);
GroceryStore gs2 = new GroceryStore("Giant 43", 4321090.65, true);
// displaying each (using toString) and printing annual taxes
System.out.println(gs1);
System.out.println("Annual taxes: " + gs1.annualTaxes());
System.out.println(gs2);
System.out.println("Annual taxes: " + gs2.annualTaxes());
}
}
/*OUTPUT*/
GroceryStore [name=Eddie's, annualRevenues=3523450.45, chain=false]
Annual taxes: 211407.027
GroceryStore [name=Giant 43, annualRevenues=4321090.65, chain=true]
Annual taxes: 259265.439
Create a super class called Store which will have below member variables, constructor, and methods Member...
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...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...
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...
C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
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; } ...
JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...
public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; } /** * gets the name * @return name name of item */ public String getName() { return name; } /** * gets price of item * @return price price of item */...
Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...