CS139 Algorithm Development

Software Requirements Specification

Programming Assignment 2

Tools

Due Tuesday, October 11th by 11:00pm

Hardcopy Due Wednesday, October 12th by class time


Introduction

Purpose: You have written enough code now to begin to see some patterns in what you need to do.  For example, when reading in a value from the keyboard, you prompt, read the value and display the new line character.   This program is the start of a toolkit that you can use with any future programming assignments or labs. Some of the String manipulation methods will be used in PA3 (See Chapter 10 for some handy methods).

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites

You have covered the material in Chapter 5 of Gaddis.  

Program Behavior

The driver program, ToolkitTester.java, contains a main method that will create a new Toolkit object, run each of its methods, and produce output that indicates whether your methods conformed to the expected behavior.  Method headers containing the name of the method, input parameters, and return type are found in the file, Toolkit.java.

Toolkit Methods

  1. getInteger - This method will take in a Scanner object and a String prompt, (in that order), display the prompt, read in the value from the keyboard, and output a newline character. This method should consume the newline character.
  2. getDouble - This method will take in a Scanner object and a String prompt, (in that order), display the prompt, read in the value from the keyboard, and output a newline character. This method should consume the newline character. 
  3. getToken - This method will take in a Scanner object and a String prompt, (in that order), display the prompt, read in the value from the keyboard, and output a newline character. This method will read in only the next token (set of characters before a white space character).This method should consume the new line character.
  4. getLine - this method will take in a Scanner object and a String prompt, (in that order), display the prompt, read in a whole line from the keyboard, and output a new line character.
  5. getEID - This method will take in three String objects representing last name, first name, and middle name (in that order) and returns an e-id consisting of the first 6 characters of the last name, the first initial and the middle initial. So for example, if I passed Harris, Nancy, Lea the method would return harrisnl. You can assume that each last name will be equal to or larger than 6 characters. (HINT: See a helpful method lower in the list).
  6. getInit - This method will take in three String objects representing last name, first name, and middle name (in that order) and returns the initials, in first, middle, last order. So if I passed Harris, Nancy, Lea this method would return NLH.
  7. makePluralS - This method will take in a String and return that String with an 's' appended to the end. If I called this method with "textbook", the method would return "textbooks".
  8. makePluralIes - This method will take in a String and return that String with the last letter removed and an 'ies' appended to the end. So for example, if I sent in the String, "body", this method would return "bodies".
  9. capitalize - This method will take in a String and capitalize the first letter of the String. For example, if I sent in the String "penguin", the method would return "Penguin".
  10. makeSmall - this method will take in a String and make the first letter of the String a lower case. For example, if I sent in the String "Penguine", the method would return "penguin".

Examples

Method call (assumes a Toolkit object named bob, and a Scanner named kb) Display Input (for get methods) Return value
bob.getInteger(kb, "Enter an integer: "); Enter an integer:

5 5
bob.getDouble(kb, "Enter a double number: "); Enter a double number: 5.75 5.75
bob.getDouble(kb, "Enter a double number: "); Enter a double number: 5 5.0
bob.getToken(kb, "Enter a word: "); Enter a word: something "something"
bob.getToken(kb, "Enter a word: "); Enter a word: something else entirely "something"
bob.getLine(kb, "Enter a message: "); Enter a message: This is silly "This is silly"
bob.getEID("Bulldog", "Duke", "The"); "bulldodt"
bob.getInit("Bulldog", "Duke", "The"); "DTB"
bob.makePluralS("chair"); "chairs"
bob.makePluralIes("butterfly"); "butterflies"

bob.makePluralIes("chainsaw");

NOTE: this doesn't make sense, but that is what the method should do.

"chainsaies"
bob.capitalize("butterfly"); "Butterflies"
bob.capitalize("CS139"); "CS139"
bob.makeSmall("CS139"); "cS139"
bob.makeSmall("Harris"); "harris"


Output

    The only output you must worry about in this PA is the output of the getInteger(), getDouble(), getToken() and getLine() methods. For these methods, the output should be of the form:

    prompt message where the prompt message is the value passed to the method.

    Following the read from the keyboard, you should output "\n" (a new line).

All other output will be done for you in main. (Cheers all around!)

See the sample output document for what the JGrasp session might look like when running the tester program.

SampleOutput.txt

Error Handling

You do not need to be concerned wtih Error Handling in this PA.

Additional Program Requirements

  1. You must use the method headers as provided in the Toolkit.java file.
  2. Your program must conform to standard Java programming standards and the additional standards for this class. See the Style Guide for your class.
  3. You must create a program called MyTester which will be test each method with at least one value (you will simply need to call the getInteger, etc methods and echo their output, but for the others you should use and print sample data similar to what we do in the ToolkitTester.java program that we provide.  You should display the results of those tests (using a print statement).

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by any student to another student. Authorized help is limited to your textbook, the TAs for any CS139 or CS239 section, and the professor for your section. See collaboration policy.

Grading

        For submissions after:

HINTS