Question

Java assignment: You are tasked with building a BookStore. Your Architect has told you that the...

Java assignment:

You are tasked with building a BookStore. Your Architect has told you that the BookStore class has the following members :

long id;

String name;

Address address;

Book book;

The Address class has the following attributes :

String streetName;

String houseNumber;

String apartmentNumber;

String zipCode;

The book class has the following members

String name;

String isbn;

Author author;

The Author class within the book class has the following member :

String firstName;

String lastName;

Date dateOfBirth;

Address address; //Address class has already been created

You have to create your BookStore class. You have to use encapsulation to make sure all the variables of the bookstore class are protected.

For the classes that are within the bookstore class (Address and Book and Author within book) you have to use encapsulation as well for the member variables.

Now you need to create another class that will have a main method. Call this class App. Populate your variables with data using the setter methods and then print them out using System.out.println().

Homework Answers

Answer #1

class Address
{
private String streetName;

private String houseNumber;

private String apartmentNumber;

private String zipCode;
Address(){}
Address(String s,String h,String a,String z){
this.apartmentNumber=a;this.houseNumber=h;this.streetName=s;this.zipCode=z;}
//getters and setters
String getStreetName()
{
return this.streetName;
}
String getHouseNumber()
{
return this.houseNumber;
}
String getApartmentNumber()
{
return this.apartmentNumber;
}
String getZipCode()
{
return this.zipCode;
}
void getStreetName(String s)
{
this.streetName=s;
}
void getHouseNumber(String s)
{
this.houseNumber=s;
}
void getApartmentNumber(String s)
{
this.apartmentNumber=s;
}
void getZipCode(String s)
{
this.zipCode=s;
}

}
//class book
class Book
{
private String name;

private String isbn;
private Author author;
Book(){}
Book(String n,String i,Author a){
name=n;isbn=i;author =a;
}
  
//getters and setters
String getName()
{
return name;
}
String getIsbn()
{
return isbn;
}
Author getAuthor()
{
return author;
}
void setName(String s)
{
name =s;
}
void setIsbn(String s)
{
isbn = s;
}
}
class Date{
private int day,month,year;
Date()
{
  
}
Date(int d,int m,int y)
{
day=d;month=m;year=y;
}
//getters
String getDate()
{
return Integer.toString(day)+"/"+Integer.toString(month)+"/"+Integer.toString(year);
}
}
class Author
{
private String firstName;

private String lastName;

private Date dateOfBirth;
Author(){}
Author(String f,String l,Date d){
firstName=f;lastName=l;dateOfBirth=d;}
//getters and setters
String getFirstName()
{
return this.firstName;
}
String getLastName()
{
return this.lastName;
}
Date getDOB()
{
return this.dateOfBirth;
}
void setFirstName(String s)
{
this.firstName=s;
}
void setLastName(String s)
{
this.lastName=s;
}
void setDOB(Date d)
{
this.dateOfBirth=d;
}
}
class BookStore
{
private long id;

private String name;

private Address address;

private Book book;

BookStore(){}
BookStore(long i,String n,Address a,Book b){
id=i;name=n;address=a;book=b;
}
//getters and setters
long getId()
{
return id;
}
String getName()
{
return name;
}
Address getAddress()
{
return address;
}
Book getBook()
{
return book;
}
}
public class BookStoreTester {
  
public static void main(String argv[])
{
//initializing and testing methods
  
Book b = new Book("TOC","1895", new Author("Surya","S",new Date(1,5,1994)));
Address a = new Address("RC center","12-17/1","57","530003");
BookStore B = new BookStore(14567,"George BB STORE",a,b);
  
//displaying output
System.out.println("Book store id: "+B.getId());
System.out.println("Book store name: "+B.getName());
System.out.println("Address: street:"+B.getAddress().getStreetName()+",house no:"+B.getAddress().getHouseNumber()+",apartment no:"+B.getAddress().getApartmentNumber()+",Zip:"+B.getAddress().getZipCode());
System.out.println("Book name:"+B.getBook().getName());
System.out.println("Book isbn:"+B.getBook().getIsbn());
System.out.println("Book Author name:"+B.getBook().getAuthor().getFirstName()+" "+B.getBook().getAuthor().getLastName()+",DOB:"+B.getBook().getAuthor().getDOB().getDate());
  
}
}

output:

run:
Book store id: 14567
Book store name: George BB STORE
Address: street:RC center,house no:12-17/1,apartment no:57,Zip:530003
Book name:TOC
Book isbn:1895
Book Author name:Surya S,DOB:1/5/1994
BUILD SUCCESSFUL (total time: 0 seconds)

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
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
You have to create a Library Borrowing System based on the following requirements: When new books...
You have to create a Library Borrowing System based on the following requirements: When new books arrive, these books must be cataloged into the system by a librarian (i.e., entered in the system). Information on a book should include book ID, title, author ID, ISBN, and edition. The system should capture author names so that users can search for an author. The library may carry multiple books by the same author, and an author can have multiple books in the...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also define...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show all the classes, their attributes, and the relationships between the classes. All the associations must have proper multiplicity constraints indicated. Note that class methods and attribute types are not required.                                                                                                               Domain classes and their attributes Order [date/time, total price, status] Account [full name, address, phone, email] SellerAccount (no attributes) BuyerAccount [credit card] Book [title, ISBN, author, publisher, asking price] BookOnOrder [quantity] Dispute [reason]...
Question 2 The questions in this section are all based on the “Online Book Exchange System...
Question 2 The questions in this section are all based on the “Online Book Exchange System (EyesHaveIt.com)” Case Study on the last page of this document. Read the case study carefully before answering these questions. b) An analyst has identified all the domain classes and their attributes required for the system, as listed below. Use ONLY the classes in this list to draw a Class diagram. The diagram must show all the classes, their attributes, and the relationships between the...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
the coding language is java The start of Polymorphism Assignment Outcome: Student will demonstrate the ability...
the coding language is java The start of Polymorphism Assignment Outcome: Student will demonstrate the ability to apply polymorphism in a Java program. Program Specifications: Design the following program: A person has a name, and age. An Employee is a person. An Employee has a company and position. A SoftwareEngineer is an employee and a person. A SoftwareEngineer has a rank (Junior, Middle, and Senior) A SoftwareEngineer either C programmer, Jave programmer or both. A Manager is an Employee and...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with a Program class and write the following two methods (headers provided) as described below: - A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number...
C++ 5a)We have the following class: class Banana { private:      string s;      int y;...
C++ 5a)We have the following class: class Banana { private:      string s;      int y; public: bool theMemberFunc (string); void setterForS(string); // setter for s string getterForS(); // getter for s }; Instantiate a static object of Banana named co. a)int Banana; b)co.Banana = new; c)Banana = new class; d)Banana co; 5b)Code a call to function aNonclassFunction passing co. a)aNonclassFunction (co); b)aNonclassFunction (* co); c)aNonclassFunction (aGoodClass.co); d)aNonclassFunction (aGoodClass); 5c)Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT