20(Must%20download% Cb Best C++ Formatt... G calculator - optimize.dvi 3/7 110% Question 1. (20 marks) (a)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
20(Must%20download% Cb Best C++ Formatt... G calculator - optimize.dvi 3/7 110% Question 1. (20 marks) (a) [13 marks] Complete the given program according to the explanation below: Consider that: When person X meets Y the first time, X says "Hi [Mr Y's namel/[Ms Y's namel, this is X's name" As a further requirement: When X and Y meet again, each one's saying is "Nice to meet you again!" You are given main() and two classes Male and Female. Please complete the class Person so as to make the program work. The program should give the outputs as shown in the comments within the square brackets [] inside main(). a.sayHiTo (b); //Output [Hi Mr Lee, this is Poon] a. sayHiTo (c); //Output [Hi Ms Johnson, this is Poon] c.sayHiTo (b); //Output [Hi Mr Lee, this is Johnson] c.sayHiTo(d); //Output [Hi Ms Smith, this is Johnson] a. sayHiTo (b); //Output [Nice to meet you again!] b.sayHiTo(a); //Output [Nice to meet you again!] c.sayHiTo(a); //Output [Nice to meet you again!] +1 Note: Do not use the instanceof operator. Otherwise you will get 0 mark for this question. Given code: public class Main ( public static void main (String[] args) ( Person a new Male ("Poon"); Person b= new Male ("Lee"); Person c= new Female("Johnson"); Person d new Female ("Smith"); a.sayHiTo(d); //Output [Hi Ms Smith, this is Poon] d.sayHiTo(a); //Output [Nice to meet you again!] d.sayHiTo (b); //Output [Hi Mr Lee, this is Smith] d. sayHiTo (b); //Output [Nice to meet you again!] A SANDONG public class Male extends Person ( public Male(String n) { super(n); } public String title() { return "Mr"; } public class Female extends Person ( public Female (String n) { super(n); } public String title() { return "Ms"; ) (b) (4 marks) Using any code in part (a), explain the terms (i) Up-casting and (ii) Dynamic Binding. If any of them is not observed in the code, please write "not appear in the code". (c) [3 marks] State 3 reasons for using an abstract class instead of an interface in Java programming. 20(Must%20download% Cb Best C++ Formatt... G calculator - optimize.dvi 3/7 110% Question 1. (20 marks) (a) [13 marks] Complete the given program according to the explanation below: Consider that: When person X meets Y the first time, X says "Hi [Mr Y's namel/[Ms Y's namel, this is X's name" As a further requirement: When X and Y meet again, each one's saying is "Nice to meet you again!" You are given main() and two classes Male and Female. Please complete the class Person so as to make the program work. The program should give the outputs as shown in the comments within the square brackets [] inside main(). a.sayHiTo (b); //Output [Hi Mr Lee, this is Poon] a. sayHiTo (c); //Output [Hi Ms Johnson, this is Poon] c.sayHiTo (b); //Output [Hi Mr Lee, this is Johnson] c.sayHiTo(d); //Output [Hi Ms Smith, this is Johnson] a. sayHiTo (b); //Output [Nice to meet you again!] b.sayHiTo(a); //Output [Nice to meet you again!] c.sayHiTo(a); //Output [Nice to meet you again!] +1 Note: Do not use the instanceof operator. Otherwise you will get 0 mark for this question. Given code: public class Main ( public static void main (String[] args) ( Person a new Male ("Poon"); Person b= new Male ("Lee"); Person c= new Female("Johnson"); Person d new Female ("Smith"); a.sayHiTo(d); //Output [Hi Ms Smith, this is Poon] d.sayHiTo(a); //Output [Nice to meet you again!] d.sayHiTo (b); //Output [Hi Mr Lee, this is Smith] d. sayHiTo (b); //Output [Nice to meet you again!] A SANDONG public class Male extends Person ( public Male(String n) { super(n); } public String title() { return "Mr"; } public class Female extends Person ( public Female (String n) { super(n); } public String title() { return "Ms"; ) (b) (4 marks) Using any code in part (a), explain the terms (i) Up-casting and (ii) Dynamic Binding. If any of them is not observed in the code, please write "not appear in the code". (c) [3 marks] State 3 reasons for using an abstract class instead of an interface in Java programming.
Expert Answer:
Answer rating: 100% (QA)
To complete part a of the question you need to define the Person class and its methods so that the given program works as expected Below is the completed code for part a java public class Main public ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Order check. Write a program that takes three double command-line arguments x, y, and z and prints true if the values are strictly ascending or descending ( x < y < z or x > y > z ), and false...
-
If a company adopted a more conservative approach when estimating expenses, how would this affect the profit -margin ratio?
-
Jake Nguyen runs a nervous hand through his once finely combed hair. He loosens his once perfectly knotted silk tie. And he rubs his sweaty hands across his once immaculately pressed trousers. Today...
-
Have you ever read in the newspapers about the types of people who engage in company misdeeds?
-
On July 31, 2014, Redeker Company had a cash balance per books of $6,140. The statement from Nashota State Bank on that date showed a balance of $7,690.80. A comparison of the bank statement with the...
-
A figure skater spins at the end of her routine and slows down with an angular acceleration of "0.4" A per second squared. If she initially spun with a frequency of 2.35 Hz, how much time does it...
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
I-section, A beam of unsymmetrical made of structural steel has an overall depth of 400 mm. If the flange stresses developed at the top and bottom of the beam are 1200 kg/cm and 300 kg/cm...
-
Discuss what is meant by a stakeholder. In what ways are stakeholders represented in two-tier board structures? How does this differ from companies with a unitary board structure? Use real examples...
-
Many experts suggest that maximizing profit should be the main financial goal of a corporation. Is this a correct view? Explain.
-
The UKs financial markets regulator states that its objectives are to promote efficient, orderly and fair markets, help retail consumers achieve a fair deal, and improve the countrys business...
-
Nakamura has earnings of 10 million and is projected to grow at a constant rate of 5 per cent forever because of the benefits gained from the learning curve. Currently all earnings are paid out as...
-
You are out having dinner with your two colleagues who are also studying finance. John, who loves the IRR method, tells you that ranking projects by IRR is fine as long as each projects cash flows...
-
Complete the following inventory card. (Add the items in the IN column to the balance and subtract the items in the OUT column) DATE IN OUT BALANCE October 10 2875 October 11 693 October 12 500...
-
Solve each equation. x 3 - 6x 2 = -8x
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
Ken paid the following amounts for interest during 2012: Qualified interest on home mortgage...........................................$4,700 Auto loan...
-
Please answer the following questions regarding the taxability of Social Security: a. A 68-year-old taxpayer has $20,000 in Social Security income and $100,000 in tax-free municipal bond income. Does...
-
Go to https://www.youtube.com/watch?v=Fp9m4GNwGng to view a brief video on the Brazilian Jet manufacturer Embraer and their use of Critical Chain Project Management for maintenance services. How has...
-
It is sometimes argued that state revenue generated by lotteries is different from tax revenue because people choose to buy lottery tickets. Compare three state revenue sources cigarette excise...
-
Suppose that the demand for personalized license plates and the marginal cost of production in a state is as shown in Figure 16.1. If all the profits go to the government and the state wants to...
Study smarter with the SolutionInn App