代写 Projects for Comprehensive application practice(4)

Projects for Comprehensive application practice(4)
Project 1: The Complex Class
Problem Description:
A complex number is a number of the form EMBED Equation.3 , where a and b are real numbers and i is EMBED Equation.3 . 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:

EMBED Equation.3
EMBED Equation.3
EMBED Equation.3
EMBED Equation.3

You can also obtain the absolute value for a complex number using the following formula:
EMBED Equation.3

(A complex number can be interpreted as a point on a plane by identifying the EMBED Equation.3 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.)

Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, abs for performing complex-number operations, and override toString method for returning a string representation for a complex number. The toString method returns a + bi as a string. If b is 0, it simply returns a.

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 for returning the real and imaginary part of the complex number, respectively.

Your Complex class should also implement the Cloneable interface.
Write a test program that prompts the user to enter two complex numbers and display the result of their addition, subtraction, multiplication, and division. Here is a sample run:


Enter the first complex number: 3.5 5.5
Enter the second complex number: -3.5 1
(3.5 + 5.5i) + (-3.5 + 1.0i) = 0.0 + 6.5i
(3.5 + 5.5i) – (-3.5 + 1.0i) = 7.0 + 4.5i
(3.5 + 5.5i) * (-3.5 + 1.0i) = -17.75 + -15.75i
(3.5 + 5.5i) / (-3.5 + 1.0i) = -0.5094 + -1.7i
|3.5 + 5.5i| = 6.519202405202649

Project 3 : Personnel Information Management System
Problem Description of version1:
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.
Test class Test1 is designed, which requires random generation of different objects and storage of these objects in an array, and printMessages (Person [] persons) are used to output the information of the objects.
Problem Description of version2:
On the basis of the above implementation classes, add a method writeToFile (File f) for each class to serialize the current object to the specified file. Create a new subclass Postgraduate for the Student class, with two new data fields: research direction and tutor name. Write test class Test2, which requires random generation of different objects and serialization of these objects into a specified file, and use the method printMessages (Person [] persons) to output the information of the objects.

PAGE \* MERGEFORMAT 1