Question: Java Object-Oriented Programming Short Questions 2. (20 marks) Based on what we have learnt in our course with our course materials, answer the following questions.

Java Object-Oriented Programming Short QuestionsJava Object-Oriented Programming Short Questions 2. (20 marks) Based on what wehave learnt in our course with our course materials, answer the followingquestions. public class City { // modelling a city protected String cName;

2. (20 marks) Based on what we have learnt in our course with our course materials, answer the following questions. public class City { // modelling a city protected String cName; // name of the city private int cArea; // area of the city public City (String cName) { // TO BE COMPLETED } void setc (String n) { cName = n; } void setc (int a) { cArea = a; } public int getA () { return cArea; } } Based on the program code of a given class City above, answer the following questions. a) Draw the class diagram, only related to the given program code above. [7 marks/ 2 b) Only related to the given program code above, answer the following questions: i. Write a statement to only declare a variable of the class above, with your surname as the variable name. ii. Write a statement to create a object of the class with your surname the name of the city, and assign it to the above variable. iii. Write a statement to declare a variable, and assign it with the area value of the object created above. iv. To complete the given constructor, only write two statements for the body of the one-argument constructor, which: o assigns the field of city name with the value of the input parameter, and then o sets the field of area with value of your student ID number, using assignment operator. 18 marks/ c) Write an overloading constructor, which accepts two arguments for setting the corresponding fields. The body of this constructor first properly calls another constructor, and then sets another field without using assignment operator. This constructor is for internal usage, within the class itself. (5 marks]

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 Databases Questions!