- In place of lecture, today you should attempt to implement the methods from the
Complex
class below that are in italics.
classDiagram
class Complex{
-real: double
-imag: double
-isPolar: boolean$
+Complex()
+Complex(real: double)
+Complex(real: double, imag: double)
+Complex(num: String)
+toString() String
+plus(addend: double) Complex*
+plus(addend: Complex) Complex
+minus(subtrahend: Complex) Complex*
+equals(that: Complex) boolean*
+getMagnitude() double
+getAngle() double
+setPolar() void$*
+setCartesian() void$*
+times(multiplicand: Complex) Complex
+dividedBy(divsor: Complex) Complex
}
Once you have completed each method, check your implementation by watching this video
- More practice... implement the following class. Two students should be equivalent if they have the same ID.
classDiagram
class Student{
-firstname: String
-lastname: String
-id: int
+Student(fullname: String, id: int)
+Student(firstname: String, lastname: String, id: int)
+toString() String
+getFullname() String
+setFirstname(firstname: String) void
+setLastname(lastname: String) void
+equals(that: Student) boolean
+getId() int
}
- More practice... implement the following class. You should ensure that the denominator is always greater than zero.
classDiagram
class Fraction{
-numerator: int
-denominator: int
+Fraction()
+Fraction(num: int)
+Fraction(num: int, den: int)
+toString() String
+plus(addend: Fraction) Fraction
+minus(subtrahend: Fraction) Fraction
+equals(that: Fraction) boolean
+getValue() double
+times(multiplicand: Fraction) Fraction
+dividedBy(divsor: Fraction) Fraction
}