Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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) <+ 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

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

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

1. Outline the listening process and styles of listening

Answered: 1 week ago

Question

4. Explain key barriers to competent intercultural communication

Answered: 1 week ago