Question
In Java, create a complex number calculator with File I/O: Classes: ---Number class Attributes Real number (double) Methods Constructor pass in value for number Accessor
In Java, create a complex number calculator with File I/O:
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)
Real only
Imaginary only
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:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started