Transcribed TextTranscribed Text

1.A complex number is a number in the form a+bi, 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 complexnumbers using the following formulas: (12 points) a + bi + c + di = (a + c) + (b + d)i a + bi − (c + di) = (a − c) + (b − d)i (a + bi) * (c + di) = (ac − bd) + (bc + ad)i (a + bi)/(c + di) = (ac + bd)/(c2 + d2) + (bc − ad)i/(c2 + d2) You can also obtain the absolute value for a complex number using the following formula: |a + bi| = √𝑎𝑎2+𝑏𝑏2 (A complex number can be interpreted as a point on a plane by identifying the (a,b) 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 the figure below.) Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, and 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. Your Complex class should also implement Cloneable and Comparable. Compare two complex numbers using their absolute values. 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 part and the imaginary part of the complex number, respectively. Write a test program that prompts the user to enter two complex numbers and displays the result of their addition, subtraction, multiplication, division, and absolute value. 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 2. A polygon is convex if it contains any line segments that connects two points of the polygon. Write a program that prompts the user to enter the number of points in a convex polygon, enter the points clockwise, then displays the area of the polygon. For the formula for computing the area of a polygon. Here is a sample run of the program: (8 points) Enter the number of points: 7 Enter the coordinates of the points: −12 0 −8.5 10 0 11.4 5.5 7.8 6 -5.5 0 −7 −3.5 −13.5 The total area is 292.575

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Scanner;
import java.lang.Math;

class Complex implements Comparable<Complex>, Cloneable {
    private double real;
    private double imag;

    public Complex() {
       real = 0;
       imag = 0;

    public Complex(double a) {
       real = a;
       imag = 0;

    public Complex(double a, double b) {
       real = a;
       imag = b;

    public String toString() {
       String retVal = "";
       if(imag == 0) {
            retVal += real;
       else {
            retVal += "(";
            retVal += real;
            retVal += " + ";
            retVal += imag;
            retVal += "i)";
       return retVal;

    public double getRealPart() {
       return real;

    public double getImaginaryPart() {
       return imag;

    public Complex add(Complex other...

By purchasing this solution you'll be able to access the following files: and

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats