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;
}
/**
* Gets the store name
* @return store name
*/
public String getName()
{
return name;
}
/**
* Sets the store name
* @param newName
*/
public void setName(String newName)
{
name = newName;
}
/**
* Overrides the Object toString method
*/
public String toString()
{
return("Name: " + name);
}
}
Write a class WebStore, which inherits from Store. A web store has the following additional attributes: an Internet address and the programming language in which the website was written. Code the constructor, getter and setter methods for each instance variable and the toString method of the new class. Both the constructor and toString methods should call the constructor and toString method of the Store class.
Write a class MusicStore, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor, getter and setter methods for each instance variable and the toString method of the new class. Both the constructor and toString methods should call the constructor and toString method of the Store class.
Write a class 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, getter and setter methods for each instance variable and the toString method of the new class. In addition, code a method that returns the average overall taxes per year. Both the constructor and toString methods should call the constructor and toString method of the Store class.
Create a class named StoreTester that tests all of the constructors and methods. The tester program should create 2 Store, WebStore, MusicStore, and Restaurant objects.
Here is the required code you asked. Everything is implemented as needed, explained using comments. In case if you have any doubts, drop a comment, Thanks.
// Store.java
/**
*
* 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;
}
/**
*
* Gets the store name
*
* @return store name
*/
public String getName()
{
return name;
}
/**
*
* Sets the store name
*
* @param newName
*/
public void setName(String newName)
{
name = newName;
}
/**
*
* Overrides the Object toString method
*/
public String toString()
{
return ("Name: " + name);
}
}
// WebStore.java
public class WebStore extends Store {
// additional attributes
private String internetAddress;
private String programmingLanguage;
// constructor
public WebStore(String newName, String internetAddress,
String programmingLanguage) {
//passing name to super class
super(newName);
this.internetAddress = internetAddress;
this.programmingLanguage = programmingLanguage;
}
//getters and setters
public String getInternetAddress() {
return internetAddress;
}
public void setInternetAddress(String internetAddress) {
this.internetAddress = internetAddress;
}
public String getProgrammingLanguage() {
return programmingLanguage;
}
public void setProgrammingLanguage(String programmingLanguage) {
this.programmingLanguage = programmingLanguage;
}
@Override
public String toString() {
//appending additional details and returning the super class String
return super.toString() + ", Internet Address: " + internetAddress
+ ", Language used: " + programmingLanguage;
}
}
// MusicStore.java
public class MusicStore extends Store {
// additional attributes
private int numTitles;
private String address;
// constructor
public MusicStore(String newName, int numTitles, String address) {
//passing name to super class
super(newName);
this.numTitles = numTitles;
this.address = address;
}
//getters and setters
public int getNumTitles() {
return numTitles;
}
public void setNumTitles(int numTitles) {
this.numTitles = numTitles;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
//appending additional details and returning the super class String
return super.toString() + ", number of titles: " + numTitles
+ ", address: " + address;
}
}
// Restaurant.java
public class Restaurant extends Store {
//additional attributes
private int peopleServedEveryYear;
private double averagePricePerPerson;
// constructor
public Restaurant(String newName, int peopleServedEveryYear,
double averagePricePerPerson) {
//passing name to super class
super(newName);
this.peopleServedEveryYear = peopleServedEveryYear;
this.averagePricePerPerson = averagePricePerPerson;
}
//getters and setters
public int getPeopleServedEveryYear() {
return peopleServedEveryYear;
}
public void setPeopleServedEveryYear(int peopleServedEveryYear) {
this.peopleServedEveryYear = peopleServedEveryYear;
}
public double getAveragePricePerPerson() {
return averagePricePerPerson;
}
public void setAveragePricePerPerson(double averagePricePerPerson) {
this.averagePricePerPerson = averagePricePerPerson;
}
/**
* calculates and returns the average amount of tax paid per year
*/
public double averageTaxPerYear() {
double averagePricePerYear = averagePricePerPerson
* peopleServedEveryYear;
double averageTaxPerYear = averagePricePerYear * SALES_TAX_RATE;
return averageTaxPerYear;
}
@Override
public String toString() {
//appending additional details and returning the super class String
return super.toString() + ", People served every year: "
+ peopleServedEveryYear + ", Average price per person: $"
+ averagePricePerPerson;
}
}
// StoreTester.java
public class StoreTester {
public static void main(String[] args) {
/**
* Defining two objects of each classes and display the details
*/
Store store1 = new Store("An ordinary store");
Store store2 = new Store("Another ordinary store");
WebStore webStore1 = new WebStore("Flipkart", "flipkart.com",
"PHP & HTML5");
WebStore webStore2 = new WebStore("MyStore", "mystore.com", "ASP.NET");
MusicStore musicStore1 = new MusicStore("Alice's ", 390,
"22nd building, Wall street");
MusicStore musicStore2 = new MusicStore("Vibe", 441,
"5- Raymond, Washington DC");
Restaurant restaurant1 = new Restaurant("Dad's cafe", 15000, 2.5);
Restaurant restaurant2 = new Restaurant("Foodland", 26789, 1.78);
System.out.println(store1);
System.out.println(store2);
System.out.println(webStore1);
System.out.println(webStore2);
System.out.println(musicStore1);
System.out.println(musicStore2);
System.out.println(restaurant1);
System.out.println("Average tax per year: $"
+ restaurant1.averageTaxPerYear());
System.out.println(restaurant2);
System.out.println("Average tax per year: $"
+ restaurant2.averageTaxPerYear());
}
}
//output
Name: An ordinary store
Name: Another ordinary store
Name: Flipkart, Internet Address: flipkart.com, Language used: PHP & HTML5
Name: MyStore, Internet Address: mystore.com, Language used: ASP.NET
Name: Alice's , number of titles: 390, address: 22nd building, Wall street
Name: Vibe, number of titles: 441, address: 5- Raymond, Washington DC
Name: Dad's cafe, People served every year: 15000, Average price per person: $2.5
Average tax per year: $2250.0
Name: Foodland, People served every year: 26789, Average price per person: $1.78
Average tax per year: $2861.0652
Here is a sample run of the tester program: Make sure your program follows the Java...
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...
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...
Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....
In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...
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...
Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...
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...
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* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...