Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help modifying this code for assignment 11. Look at assignment 13 below Assignment 11: class Complex_Operation { private float real,imag; Complex_Operation() { real=0;

I need help modifying this code for assignment 11. Look at assignment 13 below

Assignment 11:

class Complex_Operation

{ private float real,imag; Complex_Operation() { real=0; imag=0; } Complex_Operation(float Comp1,float Comp2) { real=Comp1; imag=Comp2; } void AddNumbers(Complex_Operation C1,Complex_Operation C2) { float real,imag; this.real = (C1.real + C2.real); this.imag = (C1.imag + C2.imag); System.out.println("Answer is:("+this.real+") + ("+this.imag+")i" ); } void SubtractNumbers(Complex_Operation C1,Complex_Operation C2) { float real,imag; this.real = (C1.real - C2.real); this.imag = (C1.imag - C2.imag); System.out.println("Answer is:("+this.real+") + ("+this.imag+")i" ); } void MultiplyNumbers(Complex_Operation C1,Complex_Operation C2) { float real,imag; this.real = (C1.real*C2.real - C1.imag*C2.imag); this.imag = (C1.real*C2.imag + C2.real*C1.imag); System.out.println("Answer is:("+this.real+") + ("+this.imag+")i" ); } void DivideNumbers(Complex_Operation C1,Complex_Operation C2) { float real,imag,deno; deno = (C2.real*C2.real + C2.imag*C2.imag); this.real = (C1.real*C2.real + C1.imag*C2.imag)/deno; this.imag = (C2.real*C1.imag - C1.real*C2.imag)/deno; System.out.println("Answer is:("+this.real+") + ("+this.imag+")i" ); } }

mport java.io.*; import java.util.*; public class Complex { public static void main(String args[]) { int ch=0; float num1,num2,answer; Complex_Operation cal = new Complex_Operation() ; Scanner input = new Scanner(System.in); System.out.print("Enter the first Number "); System.out.print("Real Part:"); num1 = input.nextInt(); System.out.print("Imaginary Part:"); num2 = input.nextInt(); Complex_Operation Object1 = new Complex_Operation(num1,num2); System.out.print("Enter the Second Number "); System.out.print("Real Part:"); num1 = input.nextInt(); System.out.print("Imaginary Part:"); num2 = input.nextInt(); Complex_Operation Object2 = new Complex_Operation(num1,num2); do { System.out.println("1.Add"); System.out.println("2.Subtract"); System.out.println("3.Multiplication"); System.out.println("4.Division"); System.out.println("5.Exit"); System.out.print("Choose ur choice:"); ch = input.nextInt(); switch(ch) { case 1: cal.AddNumbers(Object1,Object2); break; case 2: cal.SubtractNumbers(Object1,Object2); break; case 3: cal.MultiplyNumbers(Object1,Object2); break; case 4: cal.DivideNumbers(Object1,Object2); break; case 5: break; } }while(ch!=5); 
 } }

Assignment 13:

Starting with Assignment 11.

Modify your class so that it creates random complex fractions

Store the complex fractions in an array

Create a complex fraction method that calculates the magnitude of a complex number

Print off the array, and the magnitude of each complex fraction. Using the format below. System.out.printf

Sort the array in both ascending and descending order, by magnitude.

You can use any sorting algorithm you wish, or you can.

implements Comparable write a int CompareTo (Object o) method

Use Arrays.sort() note, this method is overloaded

Sort the Complex fractions by their real part. Once again, you can use any sorting algorithm you wish, or you can take advantage of the fact that the Arrays.sort method takes a second argument of a Comparator interface. Note that the Comparator interface is generic Arrays.sort (complexFraction, new Comparator() {

Enter the maximum numerator and denominator magnitudes:

10

How many complex fractions do you want to generate?

10

(-2/3 - 2/3i) 0.942809

-4 4.000000

(1 1/3 + 1/5i) 1.348250

3/7 0.428571

-3i 3.000000

(-1/3 + 2/3i) 0.745356

(-1/3 + 1 1/4i) 1.293681

(1 - 1 2/3i) 1.943651

(3/4 + 1/5i) 0.776209

(-1 - 3i) 3.162278

sorted:

3/7 0.428571

(-1/3 + 2/3i) 0.745356

(3/4 + 1/5i) 0.776209

(-2/3 - 2/3i) 0.942809

(-1/3 + 1 1/4i) 1.293681

(1 1/3 + 1/5i) 1.348250

(1 - 1 2/3i) 1.943651

-3i 3.000000

(-1 - 3i) 3.162278

-4 4.000000

descending:

-4 4.000000

(-1 - 3i) 3.162278

-3i 3.000000

(1 - 1 2/3i) 1.943651

(1 1/3 + 1/5i) 1.348250

(-1/3 + 1 1/4i) 1.293681

(-2/3 - 2/3i) 0.942809

(3/4 + 1/5i) 0.776209

(-1/3 + 2/3i) 0.745356

3/7 0.428571

by real part:

-4

(-1 - 3i)

(-2/3 - 2/3i)

(-1/3 + 1 1/4i)

(-1/3 + 2/3i)

-3i

3/7

(3/4 + 1/5i)

(1 - 1 2/3i)

(1 1/3 + 1/5i)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago