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)
Question 1 a Completing the Given Program Youre given a program with a main method and two classes Male and Female The task is to complete the Person class to make the program work as described in the ... 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
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
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...
-
Identify the ratio(s) that should be used to help answer each of these questions. (a) How efficient is the company in using its assets to produce sales? (b) How near to sale is the inventory on hand?...
-
Explain the output of the following code snippet: HashMap map = new HashMap (); map.put("LA", "Los Angeles" ); map.put("NJ", "New Jersey"); map.put("LA", "Louisiana"); map.put("NY", "New York");...
-
A 1.2-lb kite with an area of \(6 \mathrm{ft}^{2}\) flies in a \(20-\mathrm{ft} / \mathrm{s}\) wind such that the weightless string makes an angle of \(55^{\circ}\) relative to the horizontal. If the...
-
Your manager is trying to determine what forecasting method to use. Based upon the fol-lowing historical data, calculate the following forecast and specify what procedure you would utilize. Month...
-
Galaxy Sports Inc. manufactures and sells two styles of All Terrain Vehicles (ATVS), the Conquistador and Hurricane, from a single manufacturing facility. The manufacturing facility operates at 100%...
-
Overview The milestone for Project One involves applying accounting principles and methods to long-term liabilities and equity. You will also evaluate these financial statement components for...
-
Some tumor cells characteristically re-express antigens found only early in normal development of that cell type. One example of this is which of the following protein/tumor pairs? A. CD20 and B cell...
-
West End theater, London, is considered to represent one of the highest levels of commercial theater in the Englishspeaking world. The theater land contains approximately 50 venues, attracting more...
-
What are the various types of acquisitions?
-
What are the ways in which synergies can be created in acquisitions?
-
What are the possible motives for acquisitions?
-
Why would firms use acquisitions rather than create a new business internally?
-
Parameters relevant for pricing an option on the EURUSD exchange rate are as follows: Spot price = 1.225 USD per Euro. Volatility = 7% per year, USD LIBOR = 1.8% per year, Euro LIBOR = 0.2% per year,...
-
For the data in Exercise 17-19, use the FIFO method to summarize total costs to account for, and assign these costs to units completed and transferred out, and to units in ending work in process....
-
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...
-
Consider the situation illustrated in Figure 25. 11. A positively charged particle is lifted against the uniform electric field of a negatively charged plate. Ignoring any gravitational interactions,...
-
A positively charged particle is moved from point A to point B in the electric field of the massive, stationary, positively charged object in Figure 25. 12. (a) Is the electrostatic work done on the...
-
Figure 25. 13 shows both the electric field lines and the equipotentials associated with the given charge distribution. (a) Is the potential at point A higher than, lower than, or the same as the...
Study smarter with the SolutionInn App