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
Write a Java Program You are being tasked with creating a bike store. You need to...
Write a Java Program You are being tasked with creating a bike store. You need to create the following classes following the principles of encapsulation : 1. BikeStore -- This class will contain the following variables : String name, Address address, int numberOfBikes 2. Address -- This class will contain the following variables : String streetName, String city, String state, String zipCode 3. App -- This class will contain the main method and will print out the Bike store name...
Book(bookID, ISBN, title, author, publish-year, category) Member(memberID, lastname, firstname, address, phone-number, limit) CurrentLoan(memberID, bookID, loan-date, due-date)...
Book(bookID, ISBN, title, author, publish-year, category) Member(memberID, lastname, firstname, address, phone-number, limit) CurrentLoan(memberID, bookID, loan-date, due-date) History(memberID, bookID, loan-date, return-date) Members can borrow books from the library. The number of books they can borrow is limited by the “limit” field of the Member relation. The category of a book includes fiction, non-fiction, children’s and reference. The CurrentLoan table represents the information about books that are currently checked out. When the book is returned to the library, the record will be...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
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 this assignment, you will be building upon the work that you did in Lab #5A...
In this assignment, you will be building upon the work that you did in Lab #5A by expanding the original classes that you implemented to represent circles and simple polygons. Assuming that you have completed Lab #5A (and do not move on to this assignment unless you have!), copy your Circle, Rectangle, and Triangle classes from that assignment into a new NetBeans project, then make the following changes: Create a new Point class containing X and Y coordinates as its...
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]...
****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...
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...