Question

How would you draw a UML chart for Intro to Java Liang (10th edition) Chapter 13...

How would you draw a UML chart for Intro to Java Liang (10th edition) Chapter 13 #17PE? I am confused if you start with the main application then a separate box for the class.

This is the assignment which I have the programming complete but stuck on UML Chart.

Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, and abs for performing complexnumber 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 the Cloneable interface. 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. 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

// Complex.java

public class Complex implements Cloneable {

   private double a;
   private double b;

   public Complex(double a, double b) {
       this.a = a;
       this.b = b;
   }

   public Complex(double a) {
       this.a = a;
       b = 0;
   }

   public Complex() {
       this.a = 0;
       this.b = 0;
   }

   public double getRealPart() {
       return a;
   }

   public double getImaginaryPart() {
       return b;
   }

   @Override
   public String toString() {
       return "(" + a + "+i" + b + "}";
   }

   public Complex add(Complex com1) {

       return new Complex(com1.getRealPart() + a, com1.getImaginaryPart() + b);
   }

   public Complex subtract(Complex com1) {
       return new Complex(com1.getRealPart() - a, com1.getImaginaryPart() - b);
   }

   public Complex multiply(Complex com1) {
       Complex comp = new Complex();
       comp.a = (this.a * com1.a) - (this.b * com1.b);
       comp.b = (this.a * com1.b) + (this.b * com1.a);
       return comp;

   }

   public Complex divide(Complex com1) {
       double denominator = Math.pow(com1.mod(), 2);
       return new Complex(((this.a * com1.a) + (this.b * com1.b)) / denominator, ((this.b * com1.a) - (this.a * com1.b)) / denominator);

   }
   public double mod() {
       if (a != 0 || b != 0) {
       return Math.sqrt(a * a + b * b);
       } else {
       return 0.0;
       }
       }


   public Complex abs() {

       return new Complex(Math.abs(a), Math.abs(b));
   }

   @Override
   protected Object clone() {
       return new Complex(a, b);
   }

}

__________________________

// Test.java

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);
       System.out.print("Enter the second complex number: ");
       double c = input.nextDouble();
       double d = input.nextDouble();
       Complex c2 = new Complex(c, d);
       System.out.println("(" + c1 + ")" + " + " + "(" + c2 + ")" + " = "
               + c1.add(c2));
       System.out.println("(" + c1 + ")" + " - " + "(" + c2 + ")" + " = "
               + c1.subtract(c2));
       System.out.println("(" + c1 + ")" + " * " + "(" + c2 + ")" + " = "
               + c1.multiply(c2));
       System.out.println("(" + c1 + ")" + " / " + "(" + c2 + ")" + " = "
               + c1.divide(c2));
       System.out.println("|" + c1 + "| = " + c1.mod());
       Complex c3 = (Complex) c1.clone();
       System.out.println(c1 == c3);
       System.out.println(c3.getRealPart());
       System.out.println(c3.getImaginaryPart());
   }
}

__________________________

Output:

Enter the first complex number: 3.5 5.5
Enter the second complex number: -3.5 1
((3.5+i5.5}) + ((-3.5+i1.0}) = (0.0+i6.5}
((3.5+i5.5}) - ((-3.5+i1.0}) = (-7.0+i-4.5}
((3.5+i5.5}) * ((-3.5+i1.0}) = (-17.75+i-15.75}
((3.5+i5.5}) / ((-3.5+i1.0}) = (-0.5094339622641509+i-1.7169811320754718}
|(3.5+i5.5}| = 6.519202405202649
false
3.5
5.5

_______________Could you plz rate me well.Thank You

UML Diagram

_________________________

Add a comment
Know the answer?
Add Answer to:
How would you draw a UML chart for Intro to Java Liang (10th edition) Chapter 13...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING A complex number is a number in the form a + bi, where a...

    JAVA PROGRAMMING A complex number is a number in the form a + bi, where a and b are real numbers and i is V-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 formulas: a + bi + c + di = (a + c) + (b + di a + bi - (c +...

  • A complex number is a number in the form a + bi, where a and b...

    A complex number is a number in the form a + bi, where a and b are real numbers and i is sqrt( -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 formulas: a + bi + c + di = (a + c) + (b + d)i a + bi - (c + di)...

  • A complex number is a number of the form a + bi, where a and b...

    A complex number is a number of 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 and the imaginary parts, respectively, of the complex number. The operations addition, subtraction, multiplication, and division for complex num- bers are defined as follows: (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...

  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • Python has the complex class for performing complex number arithmetic. For this assignment, you will design...

    Python has the complex class for performing complex number arithmetic. For this assignment, you will design and implement your own Complex class. Note that the complex class in Python is named in lowercase, while our custom Complex class is named with C in uppercase. A complex number is of 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 the imaginary part...

  • Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...

    Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...

  • The following is for java programming. the classes money date and array list are so I are are pre...

    The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...

  • Java: Create a class called Vehicle with the following features: a. It has three private data...

    Java: Create a class called Vehicle with the following features: a. It has three private data members (instance variables): one is the manufacturer’s name (String manufacturer), the second is the number of cylinders in the engine (int cylinder), and the third is the owner (Person owner). The class Person is described above. b. It has three constructors, a no-argument constructor, a constructor with three parameters, and a copy constructor. The no-argument constructor will set the manufacturer to “None”, cylinder to...

  • How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...

    How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java • Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents person First name Last name app Creates 1 student-athlete object Hometown Retinfo) 1-Displays the complete information about the student-athlete object student New attributes Maior attributes getinfo) method from the superlas person Student-athlete student's rankine Overrides the method from the superclass student Video from Professor Fisher...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT