Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image

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.

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions