1
Student Name: __________________
Class and Section __________________
Total Points (20 pts) __________________
Due: October 26, 2016 before the class
Project: The Complex Class
CSCI 1302 Advanced Programming Principles
Armstrong State University
Problem Description:
A complex number is a number of the form
bia+
, where a and b are
real numbers and i is
1
. The numbers a and b are known as the
real part and imaginary part of the complex number,
respectively. You can perform addition, subtraction,
multiplication, and division for complex numbers using the
following formula:
You can also obtain the absolute value for a complex number
using the following formula:
(A complex number can be interpreted as a point on a plane
by identifying the
),( ba
values as the coordinates of the
point. The absolute value of the complex number corresponds
to the distance of the point to the origin, as shown in
Figure 13.12b.)
Provide three constructors Complex(a, b), Complex(a), and
Complex(). Complex() creates a Complex object for number 0
and Complex(a) creates a Complex object with 0 for b. Also
provide the getRealPart() and getImaginaryPart() methods
2
for returning the real and imaginary part of the complex
number, respectively.
Your Complex class should also implement the Cloneable
interface.
Design:
Draw the UML class diagram for the Complex class here.
Coding: (Copy and Paste Source Code here. Format your code using Courier 10pts)
Name the class Exercise13_17.
The template for the code is:
3
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print(“Enter the first complex number: “);
double a = input.nextDouble();
double b = input.nextDouble();
Complex c1 = new Complex(a, b);
+ c1.multiply(c2));
System.out.println(“(“ + c1 + “)” + ” / “ + “(“ + c2 + “)” + ” = “
+ c1.divide(c2));
System.out.println(“|” + c1 + “| = “ + c1.abs());
class Complex {
// Write your code
}
Submit the following items:
1. Print this Word file and Submit to me before the class on the due day.
2. Compile, Run, and Submit to LiveLab (you must submit the program regardless
whether it complete or incomplete, correct or incorrect)