Question: In Java, create a complex number calculator using File I/O. I am trying to take data (an equation such as 2 +5i) from an input

In Java, create a complex number calculator using File I/O. I am trying to take data (an equation such as 2 +5i) from an input text file, sort it into the correct objects, calculate the equation and store the result in an output text file. Below are the requirements/guidelines for this. Thanks!

Classes:

---Number class

Attributes

Real number (double)

Methods

Constructor pass in value for number

Accessor

Mutator

toString

equals

---Complex number class :

Extends number class (-5 points)

Attributes:

Imaginary number (double)

Methods

Constructor pass in real and imaginary

Call super constructor

Accessor

Mutator

toString

equals

Read in the entire expression as a string and parse it into the proper objects

Store each part of the in the correct attribute of the object

Use the toString function to display the object when necessary

Both the real and imaginary parts may be floating point values

Validate that each expression contains no invalid characters

The only valid letter in a complex number is i (lower case)

Validate that each expression contains a valid operator

Each number in the expression must be stored in the appropriate object

Real numbers are not to be stored in a complex object

If a line contains invalid data, ignore the line

Numbers may be represented in 3 ways:

Complex (real + imaginary) <+ or ->i

Real only

Imaginary only i

Numbers may be positive or negative

Results for arithmetic operators will be numerical

Results for relational operators will be Boolean

Calculating less/greater than of a complex or imaginary number will be determined by analyzing the modulus (or absolute value) of each complex number

All functions in Main.java that would normally require a real or complex number parameter object must use Object parameters instead (-10 points)

Use the instanceof operator to determine the type of object and perform the proper actions based on the object type

All I/O will be performed with a files Input:

All input will come from a file named expressions.txt.

Each line in the file will contain an expression to be evaluated

Valid line format:

can be real or complex

Valid operators + (add) (subtract) * (multiply) / (divide) < (less than) > (greater than) = (equal) /= (not equal)

There will be a newline at the end of each line except for the last line (which may or may not have a newline)

Output:

All output will be written to a file named results.txt.

Format all output into a table with 2 columns

Column 1: original expression

Use toString to print out the numbers in the expression

Column 2: value

All values in the columns will be left justified Numerical values will be rounded to 2 decimal places. Relational operators should evaluate to true or false Each expression will be listed on separate lines

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!