Given the following Java program, answer questions (a) to (d). 1 class Author { 2 3...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Note: It is recommended that you save your response as you complete each question. Question 33 (3.4 points) The best way to study the relationship of the components within a financial statement is to...
-
Lead nitrate solution is added to a test tube containing potassium iodide solution. (a) Write the name and colour of the compound precipitated. (b) Write the balanced chemical equation for the...
-
Suppose f is differentiable on R. Let F(x) = f(ex) and G(x) = ef(x). Find expressions for (a) F'(x) (b) G'(x).
-
The following table contains financial information for Dillon Incorporated before closing entries: Cash Supplies $ 12,000 4,500 Prepaid Rent 2,000 Salaries Expense 4,500 Equipment 65,000 Service...
-
Figure P5.75 shows a sharp-edged splitter plate used to control the flow of a liquid jet \(W\) units wide by \(H_{1}\) units high. Write expressions for the deflection angle \(\theta\) and the force...
-
Cameron Jones, CPA, is verifying that all sales made by Hicks Company to customers on account are properly approved by credit personnel. Hicks has established the following control related to this...
-
Why are there such discrepancies in the view of performance by the manager and the employees? Is this a good place for 360 feedback? How much should the manager be influenced by employee opinions?...
-
A large city in the Eastern US is plagued with higher and higher rents. The average rent in the largest rental neighborhood is $2,000 per month. This neighborhood largely serves new residents to the...
-
Write a shell script which prints out the command line arguments as follows: $ ./script x y z $1 = x $2= y $3= Z
-
A bank is in the process of renegotiating an $100 million loan. If liquidated, it expects to receive $96 million. The new loan will lower interest rates to 6.5% and extend the maturity to seven...
-
what ways do protein-protein interactions within the cellular signaling pathways influence the cellular response to extracellular stimuli, and how do disruptions in these pathways lead to aberrant...
-
Phillips Curve: = E 0.5(u 6) Expected inflation: E = 0.71 + 0.32 Okun's Law: (Y Y1)/Y1 = 3.0 2.0(ut ut1) Economy begins at natural rate of unemployment with inflation stable at 5%. What is...
-
Let x = {a,b,c} and P(x) be the power set of x. A relation R is defined on P(x) as follows: For all A, B = P(x), ARB the number of elements in A is not equal to the number of elements in B. [Note:...
-
1. On January 1, year 1, Flop Co. purchased a machine for $528,000 and depreciated it by the straight-line method using an estimated useful life of eight years with no salvage value. On January 1,...
-
Portal Manufacturing has total fixed costs of $520,000. A unit of product sells for $15 and variable costs per unit are $11. a). Prepare a contribution margin income statement showing predicted net...
-
A university is deciding between two meal plans. One plan charges a fixed fee of \($600\) per semester and allows students to eat as much as they want. The other plan charges a fee based on the...
-
Evaluate this statement: You are a natural athlete, an attractive person who learns easily and communicates well. Clearly, you can do everything better than your friends and acquaintances. As a...
-
In elementary school and through middle school, most students have the same teacher throughout the day and for the entire school year. Then, beginning in high school, different subjects are taught by...
Study smarter with the SolutionInn App