CS2336 – PROJECT 2 – Whovian Calculator Solved

200.00 $

Description

5/5 - (5 votes)

KEY ITEMS: Key items are marked in red.  Failure to include or complete key items will incur additional deductions as noted beside the item.

Submission and Grading:

  • The pseudocode will be submitted in eLearning as a Word or PDF document and is not accepted late.
  • All project source code will be submitted in Zybooks. o Projects submitted after the due date are subject to the late penalties described in the syllabus. Type your name and netID in the comments at the top of all files submitted. (-5 points)

Objectives:

  • Implement classes using inheritance
  • Implement basic polymorphism concepts

Problem: Somewhere in the time stream, the TARDIS picked up a nasty techno-virus from the Daleks and has become infected. Because of this, the computers onboard the TARDIS are not able to perform the calculations necessary to navigate.  Doctor Who must manually enter the calculations into the TARDIS interface until the virus can be “exterminate”d.  These calculations involve real, imaginary and complex numbers.  As the Doctor’s handy apprentice, you have been asked to create a program that will perform these calculations so that the Doctor can quickly enter the information for the TARDIS.

Pseudocode Information:

  • java o Detail the step-by-step logic of the main function o List other functions you plan to create
    • Determine the parameters
    • Determine the return type
    • Detail the step-by-step logic that the function will perform
  • A list of at least 10 test cases you will check during testing (other than the examples below) o Specific input is not necessary o Describe what you are testing o Examples:
    • Add a real number and a complex number
    • Multiply two complex numbers

Zybooks Information:

  • You will have multiple source files
    • java
    • java – base class o Complex.java – derived class
  • Core implementation has unlimited submissions o This will help you make sure the basic actions of your program are working properly in the environment
  • Final submission is limited to 12 submissions
  • White space will not be checked
  • Displaying the input files is not allowed o Submissions will be randomly checked for this activity
    • If a submission is identified as printing out the input files, a 10 point deduction will be applied

Core Implementation:

  • Read expressions from the file
  • Perform addition, subtraction and multiplication o Operands will be one of the following
    • Both real
    • Both imaginary
    • 1 real and 1 complex/imaginary
  • Display result of calculation
  • You do not have to perform division
  • You do not have to perform comparisons
  • You do not have to handle two complex operands
  • You do not have to handle invalid input
  • You do not have to use polymorphism

Classes:

  • Real number class – java o Base class o Must be comparable o Attributes
    • Real number (double) o Methods
    • Default constructor
    • Overloaded constructor – pass in value for number
    • Accessor
    • Mutator
    • toString (overridden from Object)
    • equals (overridden from Object)
    • compareTo (overridden from Comparable interface)
  • Complex number class – java
    • Extends real number class (-5 points if not) o Must be comparable
    • Attributes:
      • Imaginary number (double) o Methods
      • Default constructor
      • Overloaded Constructor – pass in real and imaginary numbers
    • Call super constructor to assign real value
      • Accessor
      • Mutator
      • toString (overridden from Number)
      • equals (overridden from Number)
      • compareTo (overridden from Number)

Details:

  • A complex number can be described in the form z = a + bi o a is a real number o bi is an imaginary number
  • Read in the entire expression as a string and parse it into the proper objects o a is stored in a real number object o b is stored in a complex number object
  • Use the toString function to display the number when necessary o The Complex toString method should utilize the base class toString
  • Both the real and imaginary parts may be floating point values
  • Validate that each expression contains no invalid characters o The only valid letter in a complex number is a lower case i o Check that each expression contains a valid operator
  • If a line contains invalid data, ignore the line
  • 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 magnitude of each complex number o |𝑧|
  • Functions must be designed to work with a real and complex number o Do not create multiple functions with the same functionality (-10 points if present) o Use polymorphism where necessary by using a base class references for parameters

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

User Interface: Ask the user for a file name that contains the numerical expressions.  All output will be written to the console

Input: 

  • Each line in the file will contain an expression to be evaluated
  • Valid line format: <number><space><operator><space><number><newline>
  • Number formats o Complex number

▪ <real number><+ or -><real number>i

  • Real only
    • <real number>
  • Imaginary only
    • <real number>i
  • Valid operators o + (add) o – (subtract) o * (multiply) o / (divide) o < (less than) o > (greater than) o = (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:

  • Output format:
    • <expression><tab><value>
  • Numerical values will be rounded to 2 decimal places.
  • The value for expressions with relational operators is true or false
  • Each expression will be listed on a separate line
  • WhovianCalculator-2z3ngd.zip