Lab 2.1 (Year 3 Sem 2)

Lab 2.1 is the second lab in semester 2 of year 3, and the eighteenth lab in the total of year 3. It is a lab for inheritance and polymorphism, and is considered to be moderately easy.

Description
No description was provided for this lab.

Unlocked after completion

 * Star Employee (Score at least 50% for Lab 2.1: Inheritance & Polymorphism)
 * I extends U (Score at least 100% for Lab 2.1: Inheritance & Polymorphism)

Files
[[Media:Chapter+2+-+Inheritance+&+Polymorphism.pdf|Chapter 2 - Inheritance &amp;amp; Polymorphism.pdf]]

Question
You are given a Circle class as defined in Circle.java. You are to create a class named CentredCircle which is a subclass of Circle. An instance of CentredCircle contains colour, radius and a centre which is a 2D point with coordinates of type double. You are to use the class Point2D.Double for the centre. Refer to https://docs.oracle.com/javase/8/docs/api/java/awt/geom/Point2D.Double.html  for more information. A client program TestCentredCircle.java is also given. This program reads data of two circles, creates two objects of CentredCircle, displays their values and compares if they are identical (refer to sample inputs and outputs). Note that if the colour entered is “Default”, then a default yellow circle with radius 10.0 and centre at (0,0) is created. You are not to modify the given programs Circle.java and TestCentredCircle.java. You are to write and submit CentredCircle.java. In this program, you should do the following:  Make CentredCircle a subclass of Circle   Provide two constructors:   <ul style="margin-top: 0cm;" type="circle"> <span style=" font-family: Arial, sans-serif;">A default constructor CentredCircle to create a yellow circle with radius 10.0 and centre at (0, 0)  </li> <span style=" font-family: Arial, sans-serif;">A constructor CentredCircle(String colour, double radius, Point2D.Double centre)  </li> <span style=" font-family: Arial, sans-serif;">You should use super wherever appropriate </li> </ul> </ul> <ul style="margin-top: 0cm;" type="disc"> <span style=" font-family: Arial, sans-serif;">The accessor getCentre and the mutator setCentre(Point2D.Double centre)  </li> <span style=" font-family: Arial, sans-serif;">Overriding methods toString and equals(Object obj)  </li> <ul style="margin-top: 0cm;" type="circle"><span style=" font-family: Arial, sans-serif;">You should use super in the equals(Object obj) method </li></ul> </ul>

Solution
todo

Question
<span style="font-family:&quot;Arial&quot;,sans-serif" lang="EN-GB">Create a class SavingAccount which inherits the BankAccount class. <b><span style=" font-family:&quot;Arial&quot;,sans-serif" lang="EN-GB">BankAccount.java </b><span style="font-family:&quot;Arial&quot;,sans-serif" lang="EN-GB"> is <span style=" font-family: Arial, sans-serif;"> given to you. <span style=" font-family: Arial, sans-serif;">You are to write and submit SavingAccount.java. In this program, you should do the following: <span style="font-family:&quot;Arial&quot;,sans-serif" lang="EN-GB"> <ul style="margin-top:0cm" type="disc"> <span style="    font-family:&quot;Arial&quot;,sans-serif;color:windowtext" lang="EN-GB">A new attribute called interestRate. Set the interestRate to 0.1. </li> <span style="font-family:&quot;Arial&quot;,sans-serif;">Provide two constructors:  </li> <ul style="margin-top:0cm" type="circle"> <span style="font-family:&quot;Arial&quot;,sans-serif;">A constructor SavingAccount(String name)  </li> <span style="font-family:&quot;Arial&quot;,sans-serif;">A constructor SavingAccount(String name,double balance)  </li> <span style="font-family:&quot;Arial&quot;,sans-serif;">You should use super wherever appropriate  </li> </ul> <span style="font-family:    &quot;Arial&quot;,sans-serif" lang="EN-GB">A new addInterest method that adds earned interest to account balance. </li>  <span style=" font-family: Arial, sans-serif;">Overriding method toString <span style="    font-family:&quot;Arial&quot;,sans-serif" lang="EN-GB"> </li> <ul style="margin-top:0cm" type="circle"> <span style="font-family:&quot;Arial&quot;,sans-serif;">You should use super wherever appropriate </li> </ul> </ul> <font face="Arial, sans-serif"> Write your own tester program to test SavingAccount.java.

Solution
todo

Question
Draw the UML Class Diagram for the classes in Question 2. Upload your word document.