Algorithm Development - CS 239

 

 

 

 

Software Requirements Specification

Programming Assignment 2

Part 1 Due – Wednesday February 23rd   (by 8 am) – 30%

Part 2 Due – Tuesday March 1st (10pm) – 70%

Introduction

Purpose: A (very) simple calculator

Background

 

          General Information:  You must develop a simple calculator application.   Your

application must be able to get input from either a command line interface or a graphical

user interface (depending on the switches used when it is started).

 

Existing Components: Your classes must work with the following classes:

 

            NumericKeypad.class

     NumericKeypad$OutputStreamMonitor.class

 

These classes make use of the following image:

 

            icon.gif

 

You should download the two .class files and the .gif file into your working directory.  

You will only need to use the NumericKeypad class  ( the NumericKeypad$OutputStreamMonitor class  and the icon.gif are used by the NumericKeypad class).

 

New Components:  You must develop the following three (3) classes

 

            Calculator

     Controller

     Driver

 

These classes must not be in a package.  Detailed requirements for each of these classes

are given below.

 

Details

 

       Valid Expressions:

 

1.      Only integer operands (that correspond to valid int values) are valid.

 

2.      Only the following binary operators are valid:  ‘%’ (remainder), ‘/’ (integer division),  ‘x’ (multiplication), ‘-‘ (subtraction),  and ‘+’ (addition).

 

3.      An expression is valie if and only if it consists of a valid operand followed by a valid operator followed by a valid operand.

 

 

The Calculator class must:

 

1.      contain a default constructor.  (Note:  You must write the default constructor.  Do not rely on the compiler providing one).

 

2.      contain a public method named calculate that:

 

a.       is passed a String containing the expression to be evaluated;

 

b.      returns an int containing the result (i.e., the evaluated expression);

 

c.       throws an appropriate predefined java exception if the expression does not contain an operand followed by a valid operator followed by an operand;

 

d.       throws an appropriate predefined java exception if either operand is not a valid int;

 

e.       throws an appropriate predefined java exception if the expression can not be evaluated (e.g., if evaluating the expression would cause a run-time error).

 

This class may contain other methods and attributes as well.

 

           

            The Controller class must:

 

1.       contain an explicit value constructor (i.e., a constructor with parameters) that  is passed an InputStream object and an OutputStream object.   The explicit value constructor must

 

a.       construct a Calculator object;

 

b.      construct apporpriate “reader” and “writer” objects from the InputStream and OutputStream objects (remember that the Scanner is a  “reader” and that PrintWriter is a “writer”.

 

2.      contain a void method named run with no parameters that repeatedly reads input using the “reader”, uses the Calculator to evaluate the expression, and writes output using the “writer”.

 

a.       If the input is null then the application must terminate (think about when this happens) after outputting “Done”

 

b.      If the input is not null, then the input must be “echoed”.

 

c.       If the input contains a valid expresssion, then the output must contain the correct result.

 

d.      If the input is not a valid expression,then the output must contain an appropriate error message.

 

e.       All lines of output must be terminated by a newline (i.e., ‘\’) character.

 

This class may contain other methods and attributes as well.

 

 

            The Driver class must:

 

1.      have a method with the following header:  public static void main (String [] args) which must:

 

a.       determine whether the application was started with the –gui switch

 

b.      get the appropriate InputStream and Output Stream objects

 

                                                                                       i.      by default, this class must read from System.in and write to System.out

 

                                                                                     ii.      when the –gui option is specified this class must construct a NumericKeypad object and get InputStream and OutputStream objects from its getInputStream() and getOutputStream() methods.

 

c.       construct a Controller object and call its run method

 

d.      call System.exit (int)  (passing it a value of  0) before terminating.

 

 

Executing the application:

 

            Testers must be able to execute the application from the command line by typing

either of the following commands

 

                                    java Driver

              java Driver -gui

 

      The  gui option must cause the application to run using a graphical user interface.

 

 

            Sample Execution:

 

When the application is executed without any options, it will look something like what is shown in the box below

           

Ready...

5+3

Echo of Input: 5+3

8

9x6

Echo of Input: 9x6

54

10-2a

Echo of Input: 10-2a

Not an int:  For input string:  “2a”

 

 

Deliverables      

       Part 1 – due Wednesday, February 23rd by 8am via Blackboard

1.      A test plan listing:

a.       A description of the test condition

b.      The specific input that you will test

c.       The specific output that you expect to see for each test

2.      Contents below should all contain  appropropriate javadocs:

a.        Stubbed out Calculator class

b.        Stubbed out Controller class

c.        Stubbed out Driver class  and

d.        an implementation of the Driver class which handles the –gui switch properly and constructs and “runs” the stubbed-out Controller properly.

 

       Part 2 – due Tuesday, March 1st by 10 pm (submission details to be provided)

1.      Working program with appropriate javadocs.

2.       Note that you should follow the steps below in going from Part 1 to Part 2

a.        Implement a version of the Controller class that contains “hard-coded” calls to the Calculator.

b.        Implement the Calculator and test it completely using the “hard-coded” Controller.

c.        Implement the “full” Controller class and test it using the “full” Driver.

d.        Test the complete application (i.e., go through the specification requirement-by-requirement and make sure your implementation properly satisfies each one.