Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! I need some help regarding creating a complex number calculator program in Java. The program has three classes which follows: Complex ComplexCalculator And ComplexCalculatorTest

Hello! I need some help regarding creating a complex number calculator program in Java. The program has three classes which follows:

Complex

image text in transcribed

image text in transcribed

image text in transcribed

ComplexCalculator

image text in transcribed

image text in transcribed

image text in transcribed

And ComplexCalculatorTest

image text in transcribed

Here is a sample output:

image text in transcribed

I have done most of the TODOs in both Complex and ComplexCalculator but I need help with doing the toString method in both classes. I do not know how to chain them. Also, it would be great if you could pinpoint any errors in the code and explain how I should fix them. Thank you so much for your time.

File Edit Scurce Refatr Navigate Search Preject Rur Winduw Help 11 1 package cst8284.calculator; 3 public class Conplex t 5 private double imaE ; private double real = ; 8 Complex constructor that takes in a single string, r.e. "2-4i 9 public Complex(String eStr th1s(c5tr .split("(?=\\+) | (?:\\-)")); // splits cstr at + or into an array of strings havin to elements - Thr first elrment of thr resultant array wil1 hr the real portion, while the second is the inaginarry por tie This array is passed to the next constructor 13 14 15 16 17 1 public Complex(Sting) Str 19 / Conplex constructor that takes in an array of two strings fron the above constructor TODD: chain the input from this constructor to the next constructor, that is, pass each elrment of thr array to the next ranstructor, whirh has a (String, Strin siEnature 21 this (cStr(aj, cStr[1]); 25 26 // Complex constructor that takes to separate strings as parameters, e.g. "2" and "-4i" public Complex(String-, string i)( //TODO : chain the input from this constructor te the next constructor, which has n (An, Ant) signa Lure Note that this constructor needs to strip the 'i' fron the string storing / thr imaginary nunbrr; it must pass anly an inteeer to the next ranstructor, otherwise an error results this(Integer parseIntr, Integer.porseint(i.replace("i", ))):I 2 and -A 35 // Cmrplex ronstructor that takes in two ints as paranrter9, 36 public Complex(int r, int i) 3/ TODD: chain the input from this constructor to the next constructor, whirh has a (dauhlr, douhl) signature 39 40 this((double), (double)i); 43/ Complex constructor that takes in two ints and stores then as floats, e.g. as 2.8 and-4. Ppublic Conplex (double r, double i 45 this.setReal(); Smart Insert21 1:73

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions