Comp 2243-01 and -91 Spring 2001

Program 5 part 2:
Write a Keyboard2243 class.  Start from the Keyboard  class code given in the book.  Add in a readRational method to read from the keyboard into a Rational object.  The readRational method should be overloaded like the other numerical read methods in the Keyboard class: a version with no parametrs reads a Rational and returns it.  A version with one String parameter uses the parameter as a prompt and then reads and returns a Rational.  A version with a String parameter and two Rational parameters uses the String as a prompt and the Rationals as lower and upper limits.  Your code must catch parse exceptions.  If a parse exception occurs while reading a Rational, the readRational method should let the user keep entering numbers until the read is successful.

Modify your program 5 main program to use the readRational method to get values to be used in testing the Rational class methods.
 

Program 5 part 1:
p 476 # 3, with these additional/changed requirements:
 

X is the larger number
Y is the smaller number
while (Y is not 0)
        R = remainder of X/Y
        X = Y
        Y = R
(when loop ends) X is the GCD

 

Program 4 part 2:
add the following file processing to the part 1 program:

When the program starts:
Prompt the user for the filename
Read the filename
Open the input file and read the 5 product names and initial quantities
Use the input file data to set up the 5 InventoryItem objects
Close the input file

from this point, the program runs exactly as in part 1, until the user chooses the "quit" option

when "quit" is chosen:
Open an output file using the same filename as was used for the input file
Write the 5 product names and ending quantities to the file (this information will replace the old input data)
Close the output file

The idea is that the information is saved when quitting, so that the program can start from that point the next time it is run.

Use the following format for the file:

Each line contains an integer quantity, followed by a space, followed by the product name.

The product name may contain one or more spaces (for example, roller skates)

You may assume there are 5 products in the file.  If the file has more than 5 lines, just ignore the extra lines.  If the file has fewer than 5 lines, that should be treated as an error condition.

The file-related objects (BufferedReader, etc.) will need to be in the InventoryMenu class.  If you choose to write an InventoryItem method to write a product's information to the output file, the PrintWriter should be passed as a parameter to that method.  (The alternative is to have getName and getQuantity methods in InventoryItem, so that InventoryMenu can write to the output file.)

The following must be turned in:


Program 4 Part 1:
page 328 number 2, with these additional requirements:

You must write and use an InventoryItem class - we will discuss in class the instance variables and methods for this class.  Make sure to get notes from someone if you miss the class discussion of the InventoryItem class.

You must write and use an InventoryMenu class to handle the menu processing.  See the Bank Balance example on pages 293 - 299 for an example of a menu handling class.  But since the InventoryMenu is going to handle 5 different products, and since the nice way to handle that isn't going to show up until chapter 8, the run method will be different from the example.  The BankMenu run method takes a BankAccount object as a parameter.  The InventoryMenu run method will create the 5 InventoryItem objects as local variables.  That means the main program will NOT create any InventoryItem objects - it will only create an InventoryMenu object.  (When we get to chapter 8, we'll come back to this problem and look at how it could be handled in a more general way.)

Remember to think about constants - are there any "magic numbers" in this program that should be represented by constants?  (You need to think about this on all your programs - I'm just being nice and reminding you this time!)

Use the most appropriate type of loop statement for each loop in the program.  We will be looking at different types of loop statements in chapter 5.

What needs to be turned in :


 
 

Program 3:
page 193 number 8, with these additional requirements:

you must write a Point class with
    instance variables: x and y, of type int.  These represent the coordinates of the point.

    methods:


What needs to be turned in:

As always, your main program must have a comment block which includes your name, the course and section number, and a short description of the program.  Each class (other than the main program class) needs a comment block with a brief description of the class.  Each method needs a comment describing the method.

Program 2:

page 116 number 24 with these additional requirements:

SmartTurtle must be in its own file (so you'll have 2 .java files)

The program must print the values of the three parameter variables to the screen, with labels, e.g.
Number of sides is 5
Length of a side is 300
Number of polygons is 10

Test results: you must print the turtle window and the screen output for each time you run the program.
Run the program 3 times, with different values used for the parameters each time (you'll have to edit your main program each time to change the parameter values).  So test results will include 3 screen outputs and 3 turtle windows.

What must be turned in:


Program 1:

do either number 3 or number 4 from p 111.

Items to be turned in:

  • diskette with your .java and .class file
  • algorithm for main
  • printouts of your .java file
  • printouts of results from running the program