Question: Given the following Java program, answer questions (a) to (d). 1 class Author { 2 3 private String name; private Book [] myBook =

Given the following Java program, answer questions (a) to (d). 1 class


Author { 2 3 private String name; private Book [] myBook =

new Book [10]; 4 private int numOfBook; 5 6 public Author (String

Given the following Java program, answer questions (a) to (d). 1 class Author { 2 3 private String name; private Book [] myBook = new Book [10]; 4 private int numOfBook; 5 6 public Author (String name) { 7 this.name = name; } 8 9 public void write (Book bk) { 10 11 12 13 14 15 16 17 18 19 20 21 } " + public void print () { System.out.println("AUTHOR NAME: " + name); System.out.println("NUMBER OF BOOK (s) WRITTEN: numOfBook); for (int i=0; i < numOfBook; i++) { System.out.print((i+1) + ") "+s.getName()); System.out.printf(" %.2f", s.getPrice()); System.out.println(); }}} 22 23 24 25 26 27 28 29 30 31 32 33 34 35 class Book { private String name; private double price; public Book (String name, double price) { this.name = name; this.price = price; } public String getName() { return name; } public double getPrice() { return price; }} 36 public class BookTest { public static void main(String () args) { 37 38 39 40 41 }} a) Based on the program above, draw the UML class diagram that shows the relationship among classes. b) Write codes for write () method (at line 10 to 11), to add objects from the Book class to a myBook array. The objects added to the array refer to the books written by an author. Answer: c) Write a suitable statement at line 18 to complete the codes for print () method. Answer: d) Write the contents in the body of the main method so that the code compiles successfully and the output printed when the program is executed, will be: AUTHOR NAME: Ismail Kadare NUMBER OF BOOK (s) 1) Kronike ne gur 2) Prilli i thyer WRITTEN: 2 7.5 6.5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!