Question

In: Computer Science

Encapsulation You are tasked with building a BookStore. Your Architect has told you that the BookStore...

Encapsulation

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().

Solutions

Expert Solution

Bookstore:

public class BookStore {
   private long id;
   private String name;
   private Address address;
   private Book book;
   public BookStore(){
      
   }
   public long getId() {
       return id;
   }
   public void setId(long id) {
       this.id = id;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public Address getAddress() {
       return address;
   }
   public void setAddress(Address address) {
       this.address = address;
   }
   public Book getBook() {
       return book;
   }
   public void setBook(Book book) {
       this.book = book;
   }
  

}

Book:

public class Book {
   private String name;
   private String isbn;
   private Author author;
   public Book(){
      
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getIsbn() {
       return isbn;
   }
   public void setIsbn(String isbn) {
       this.isbn = isbn;
   }
   public Author getAuthor() {
       return author;
   }
   public void setAuthor(Author author) {
       this.author = author;
   }
   public String toString(){
       return this.getIsbn()+" "+this.getName()+" "+this.getAuthor().toString();
   }
  
}

Author:

import java.util.Date;

public class Author {
   private String firstName;
   private String lastName;
   private Date dateOfBirth;
   private Address address;
   public Author(){
      
   }
   public String getFirstName() {
       return firstName;
   }
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }
   public String getLastName() {
       return lastName;
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
   public Date getDateOfBirth() {
       return dateOfBirth;
   }
   public void setDateOfBirth(Date dateOfBirth) {
       this.dateOfBirth = dateOfBirth;
   }
   public Address getAddress() {
       return address;
   }
   public void setAddress(Address address) {
       this.address = address;
   }
   public String toString(){
       return this.getFirstName()+" "+this.getLastName()+" "+this.getAddress().toString()+" "+
               this.getDateOfBirth();
              
   }
  
}

Address:

public class Address {

   private String streetName;
   private String houseNumber;
   private String apartmentNumber;
   private String zipCode;
   public Address(){
      
   }
   public String getStreetName() {
       return streetName;
   }
   public void setStreetName(String streetName) {
       this.streetName = streetName;
   }
   public String getHouseNumber() {
       return houseNumber;
   }
   public void setHouseNumber(String houseNumber) {
       this.houseNumber = houseNumber;
   }
   public String getApartmentNumber() {
       return apartmentNumber;
   }
   public void setApartmentNumber(String apartmentNumber) {
       this.apartmentNumber = apartmentNumber;
   }
   public String getZipCode() {
       return zipCode;
   }
   public void setZipCode(String zipCode) {
       this.zipCode = zipCode;
   }
   public String toString(){
       return this.getApartmentNumber()+" "+this.getHouseNumber()+" "+this.getStreetName()+" "+
               this.getZipCode();
   }

}

App:

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class App {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       BookStore bookStore=new BookStore();//creating new bookstore object
       Book b1=new Book();//creating book 1
       Author a=new Author();//creating author for book object
       a.setFirstName("kalam");
       a.setLastName("apj");
       SimpleDateFormat datefrmt = new SimpleDateFormat("dd-MM-yyyy");
       java.util.Date dob = null;
       try {
           dob = datefrmt.parse("15-10-1931");
       } catch (ParseException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       a.setDateOfBirth(dob);
       Address address=new Address();//creating address for author
       address.setApartmentNumber("A-122");
       address.setHouseNumber("1-5");
       address.setStreetName("Oak street");
       address.setZipCode("500000");
       a.setAddress(address);
       b1.setName("wings of fire");
       b1.setAuthor(a);
       b1.setIsbn("1245");
       bookStore.setId(1);
       bookStore.setBook(b1);
       bookStore.setName("Royal BookStore");
       bookStore.setAddress(address);
       //Displaying the bookstore information
       System.out.println(bookStore.getId());
       System.out.println(bookStore.getName());
       System.out.println(bookStore.getAddress().toString());
       //displaying book information
       System.out.println(bookStore.getBook().toString());
       //displaying author information
       System.out.println(bookStore.getBook().getAuthor().toString());
      
   }

}

Expected output:


Related Solutions

Encapsulation You are tasked with building a BookStore. Your Architect has told you that the BookStore...
Encapsulation 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...
An architect wants to determine the relationship between the heights (in feet) of a building and...
An architect wants to determine the relationship between the heights (in feet) of a building and the number of stories in the building. The data for a sample of 10 buildings are shown. Stories (x) 64 54 40 31 45 38 42 41 37 40 Height (y) 841 725 635 616 615 582 535 520 511 485 Is there a significant linear correlation between the two variables ? Use α = .05 What would be the best predicted Height of...
Your mortgage loan has been approved and started on a Tuesday, and you were told your...
Your mortgage loan has been approved and started on a Tuesday, and you were told your first payment is due in 90 calendar days. What is the day of week of your first payment day? Write down your calculation process, the arithmetic expression you use, as well as your answer. No java coding is needed. If you only provide the answer without the other details to explain the process, you will not receive credit on this question.
Your manager has told you that capital budgeting is a waste of time. How would you...
Your manager has told you that capital budgeting is a waste of time. How would you respond to your manager? Include a discussion of the screening decision calculations available for use in making the appropriate decisions.
Your boss has told you that you need to process a full 55 gallon drum of...
Your boss has told you that you need to process a full 55 gallon drum of 1-butene that is stored at 15 atm and ambient temperature. You are going to combust this material with the stoichiometric amount of air at 1 atm and the product gasses will emerge at 579 oF with a conversion of 97%. You have a metal gas sphere that is 55 feet in diameter at ambient temperature that contains the air you are feeding in. You...
Your company has decided to investment in the stock market. Management has tasked you to conduct...
Your company has decided to investment in the stock market. Management has tasked you to conduct and assessment of the two stocks listed below Year Stock A Ra Stock B Rb 2014 (18%) (14,50%) 2015 33 21,8 2016 15 30,5 2017 (0,5) (7,6) 2018 27 26,3 1.1 Calculate the average rate of return for each stock during the period 2014 through 2018. 1.2 Assume that someone held a portfolio consisting of 50% of Stock A and 50% of Stock B....
Problem: An electric company has committed to building a solar power plant. An engineer tasked with...
Problem: An electric company has committed to building a solar power plant. An engineer tasked with the company has been tasked with evaluating three solar power generation technologies. The power company uses an interest rate of 10% and a 20-year planning horizon for choosing the project that best fits its budgetary and financial goals. Design 1: Flat Solar Panels: A field of flat solar panels angled to best catch the incident solar radiation wis expected to yield a power of...
You are a software development employee at a startup company. Your HR department has tasked the...
You are a software development employee at a startup company. Your HR department has tasked the IT department with developing a simple application (Windows Form Application) to load and display employee records. Your application will need to do the following: Create an Employee Class with the following properties: First Name Last Name Street Address City State Zip Create a sub class for Managers which inherits from the Employee Class. The Manager class will have the following additional properties: Cost Center...
Your company has tasked you with the evaluation of two projects for investments, Project X and...
Your company has tasked you with the evaluation of two projects for investments, Project X and Project Y. Each project has a cost of capital of R10,000 and the required return of 12 percent. The projects’ expected cash flows (in Rands) are listed below: Year Project X Project Y 0 (10,000.00) (10,000.00) 1 6,500.00 4,000.00 2 3,000.00 4,000.00 3 3,000.00 4,000.00 4 2,000.00 4,000.00 Required: 11.1. Calculate each project’s payback period, net present value (NPV and profitability index (PI). 11.2....
You are working as an assistant to your cousin, who is an architect. She is currently...
You are working as an assistant to your cousin, who is an architect. She is currently designing the lobby for a new luxury hotel. The lobby will include a walkway suspended above the main level. Her design will include the following features. Above the walkway, attached at various points along its length, will be vertical steel cables of diameter 1.27 cm and unstressed length 5.45 m. These cables will run upward from the walkway and be attached to a rigid...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT