Hi I have the following three class's:
public class Book { String bookTitle; //attributes String author; double price; int isbn; public Book(){ } //empty constructor public Book(String bookTitle, String author, double price, int isbn){ //constructor that takes parameters this.bookTitle=bookTitle; this.author=author; this.price=price; this.isbn=isbn; } public String getBookTitle(){ //get method that returns the book title return bookTitle; } public String getAuthor(){ //get method that returns the author return author; } public double getPrice(){ //set method to alter the attribute of price return price; } public int getIsbn(){ //get method that returns the isbn number return isbn; } public void setBookTitle(String bookTitle){ //set method that alters the book attribute this.bookTitle=bookTitle; } public void setPrice(double price){ //set method that allows the price attribute to be changed this.price=price; } }
public class TestBook { public static void main(String[] args) { Book book1= new Book("how to blar","tad blar",50,456789); Book book2= new Book("how to pass programming","David Rayner",20,567824); //method to create objects Book book3= new Book("How to fail programming","ivan blar",30,577437); book1.setBookTitle("blar allot"); //code to alter name of the book book1.setPrice(70); //code to alter price of book System.out.println(book1.getBookTitle()+" "+ book1.getAuthor()+" "+ //code to display each attributes of each object book1.getPrice()+" "+ book1.getIsbn()); System.out.println(book2.getBookTitle()+" "+ book2.getAuthor()+" "+ book2.getPrice()+" "+ book2.getIsbn()); System.out.println(book3.getBookTitle()+" "+ book3.getAuthor()+" "+ book3.getPrice()+" "+ book3.getIsbn()); } }
public class author { String firstName; String lastName; String nationality; author(){} author(String firstName, String lastName, String nationality){ this.firstName=firstName; this.lastName=lastName; this.nationality=nationality; } public String getFistName(){ return firstName; } public String getLastName(){ return lastName; } public String getNationality(){ return nationality; } public void setFirstname(String firstName){ this.firstName=firstName; } public void setLastName(String lastName){ this.lastName=lastName; } public void setNationality(String nationality){ this.nationality=nationality; } }
Now my task is the following:
Now design (using a class diagram) and build an Author class to contain information about an Author, for example the firstname, lastname and nationality. Then modify the Book class so that a book contains a single author object.
Modify your original book test class to make sure book and author now work together properly.
The problem i'm having is modifying the Book class so it contains a single author object, I just can't seem to figure out what i need to put and where I need to put it in the book class, i'm sure its probably something simple as it always turns out to be, but if someone could give me a piont in the right direction, i would greatly appriciate any help.
Thankyou in advance