Lab 8 (Year 3 Sem 1)

Lab 8 is the ninth lab in semester 1 of year 3, and the ninth lab in the total of year 3. It is a lab for classes, and is considered to be moderately easy.

Description
No description was provided for this lab.

Unlocked after completion

 * OCD (Score at least 60% for Lab 8: Classes and Objects (Part 2))
 * Guru Passer (Score at least 80% for Lab 8: Classes and Objects (Part 2))

Question
Write a class name Author to model a book's author. It contains:  Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'). Please name the variables as stated.  One constructor to initialize the name and gender with the given values. You have to use this.varName syntax to initialize the variables. You will set the default email, which will be name concatenated with "@mybook.com". For example, if the name is Jane, then the email will be Jane@mybook.com  One constructor to initialize the name, email and gender with the given values. You have to use this to invoke the first constructor created.  One copy constructor. public Author(Author a) {...}  You have to use this to invoke the second constructor created.  public getters/setters:  and.  A method that returns a string of the format "Author[name=?,email=?,gender=?]" e.g., "Author[name=Mary,email=Mary@mybook.com,gender=f]"  A static method name  which will validate an input email and return true, if input is of the correct format, false otherwise. All email must be with domain "@mybook.com". The username may only be alphabets or digits. For example: Jane123@mybook.com is valid J$ane#@mybook.com is invalid Jane123@myotherbook.com is invalid Your constructors and setEmail method should call checkEmail to validate the format of the email before updating the email. If an invalid email is passed in, you will set the email to the default email. The default email will be initialize to name concatenated with "@mybook.com".</li> </ul> The following sample output should be obtained when AuthorTester.java is executed: <span style="font-family: &quot;Courier New&quot;;">Author[name=Mary,email=Mary@mybook.com,gender=f] <span style="font-family: &quot;Courier New&quot;;">Author[name=Jane,email=jane123@mybook.com,gender=f]  <span style="font-family: &quot;Courier New&quot;;">Author[name=Jane,email=jane123@mybook.com,gender=f]  <span style="font-family: &quot;Courier New&quot;;">Leon12$_hi@mybook.com is an invalid email. Email not updated. <span style="font-family: &quot;Courier New&quot;;">Author[name=Leon,email=Leon@mybook.com,gender=m] <span style="font-family: &quot;Courier New&quot;;">?%leon@mybook.com is an invalid email. Email not updated. <span style="font-family: &quot;Courier New&quot;;">Leon@mybook.com <ul> </ul>

Solution
todo

Question
Write a class name Book to model a book. It contains: <ul> Five private instance variables: (String),  (String),  (of the class Author you have created in Question 1, assume that a book has one and only one author),   (double), and  (int) bookid is of the format: DDD-CCC DDD is a 3-digit number based on the number of Book objects created. Number to be padded with 0 if it is not 3 digits. CCC is the first 3 characters of the author's name in uppercase. For example, the first book created with Author named "Jenny" will have bookid "001-JEN" ''Hint: To format into 3-digit, you may consider using. Read more here: https://www.javatpoint.com/java-string-format '' </li> A constructor of format </li> A constructor of format </li> public accessors/mutators: <span style="background-color: rgb(255, 255, 0);">You should return a deep copy of the author in getAuthor to prevent memory leak. </li> A  that returns book information of the following format: "Book[id=?,name=?,Author[name=?,email=?,gender=?],price=?,qty=?". For example: <span style="font-family: &quot;Courier New&quot;;">Book[id=001-MAR,name=Java 101,Author[name=Mary,email=Mary@mybook.com,gender=f],price=99.5,qty=0] You should reuse Author's  .</li> </ul> <ul> A method named  which will check if two books has the same author. The method returns true if they have the same authors, false otherwise. Same author refers to both authors having the same name, gender and email address. </li> A method named  which will compare the price of two books (the current book, and the book passed in). This method will return the book object with the higher price.</li> </ul> The following sample output should be obtained when BookTester.java is executed: <font face="Courier New">Book[id=001-MAR, name=Java 101,Author[name=Mary,email=Mary@mybook.com,gender=f],price=99.5,qty=0] <span style="font-family: &quot;Courier New&quot;;">Book[id=001-MAR, name=Java 101,Author[name=Mary,email=maryhasalittlelamb@mybook.com,gender=f],price=99.5,qty=0] <span style="font-family: &quot;Courier New&quot;;">Author[name=Mary,email=someemail@mybook.com,gender=f]  <span style="font-family: &quot;Courier New&quot;;">Book[id=001-MAR, name=Java 101,Author[name=Mary,email=maryhasalittlelamb@mybook.com,gender=f],price=99.5,qty=0]  <span style="font-family: &quot;Courier New&quot;;">Book[id=002-JAN, name=Python for Dummies,Author[name=Jane,email=jane123@mybook.com,gender=f],price=109.5,qty=0]  <span style="font-family: &quot;Courier New&quot;;">Python for Dummies is the more expensive book Note that you should copy and paste the code from Author.java in Question 1 here. <ul> </ul>

Solution
todo