CSE-1020: Introduction to Computer Science I
York University
Midterm Lab Test: FractionDiff
5:00pm Wednesday 21 October 2009
(Lab-05)
  Welcome to the Lab-test Environment

During the test, you will not be able to access your regular home directory, access, receive, or send e-mail, print, or access the Internet.

The lab tests are closed-book and no aids are allowed.

At the end of your test session, this machine will be converted back to a standard, unrestricted Prism Lab machine. At this time, any files written by you during the test, except those that have been submitted, will not be recoverable. Make sure you submit your code before the end of the test. (Instructions to submit your code are below). If you do not submit your work on time, you will receive a grade of zero. (There are no exceptions.)

Instructions

You have the lab period, 80 minutes, to complete this lab test. The computers will automatically shutdown at the end of the time (e.g., 6:20pm), warning you several minutes in advance. No additional time will be provided, so you must submit your work prior to this; otherwise, there will be no way to recover it (it will be lost), and you will receive a grade of zero (no exceptions).

You are encouraged to submit often during the test. Note that newer submissions overwrite older ones.

Your program will be marked for good style, as well as for running correctly (producing correct output in the correct format).

Submitting Your Work

When you submit a file, you should include at the top of the file your name (surname, given name) and your Prism lab login. These should be placed in a comment so that the file will compile. Note that files which do not compile will receive a large penalty when marked, no matter how small the error that prevented compiling.

Submit the class FractionDiff.java before the time deadline. Here is the command to submit your work:

% submit 1020 midtermW5.00 FractionDiff.java

Further details regarding the submit command can also be obtained by typing man submit.

Once again, you are encouraged to submit regularly. Newer submissions simply overwrite older ones.

Unlike eCheck assignments, there is partial credit possible. If you are able to finish all aspects of the program (for example, say, input validation was requested but you did not do this), you should still submit it.

Useful APIs

Here are the common APIs that you may access:

 
  The Task

Write a Java application called FractionDiff.java. It will read in a list of fractions from the user, and compute the difference between each adjacent pair of fractions in the list. It will then print the sum of the differences.

Consider the list of three fractions 1/2, 1/3, and 1/4. The first difference, between 1/2 and 1/3, is 1/6. The second difference, between 1/3 and 1/4, is 1/12. The sum of the differences, 1/6 + 1/12, is 1/4.

Your app should first prompt for the number of fractions to be entered. (You are guaranteed this will be two or more, and less than one hundred.) Then it should prompt for each fraction to be entered as a pair of integers, numerator and denominator. After the second fraction has been entered, your app should report the difference between the first fraction and the second (the first fraction minus the second fraction). After the third fraction has been entered, it should report the difference between the second fraction and the third (the second fraction minus the third fraction). And so forth.

You do not have to do input validation.

After all the fractions have been read, your app should report the sum of the differences. Note that if there were five fractions in the list, there were four differences computed along the way.

Your output should look exactly like that indicated in the sample runs below. Your program should use the Fraction class from type.lib.

Sample Runs

Here are two sample runs of a correctly written program. Note that the text in red is text that the user types. The text in black is what the program types. The '%' represents the prompt from the command-line window (shell).

% java FractionDiff
Number of fractions to enter?
3
Enter fraction #1 (numerator denominator):
1 2
Enter fraction #2 (numerator denominator):
1 3
The difference is 1/6.
Enter fraction #3 (numerator denominator):
1 4
The difference is 1/12.
The sum of the differences is 1/4.
% java FractionDiff

Number of fractions to enter?
5
Enter fraction #1 (numerator denominator):
19 42
Enter fraction #2 (numerator denominator):
3 11
The difference is 83/462.
Enter fraction #3 (numerator denominator):
7 17
The difference is -26/187.
Enter fraction #4 (numerator denominator):
8 9
The difference is -73/153.
Enter fraction #5 (numerator denominator):
1 2
The difference is 7/18.
The sum of the differences is -1/21.
%

Coding

You should use good programming practises as described in the textbook, and your code should conform to the style guide in the textbook. You should comment at least minimally, as by the guidelines.

You should not use any features of Java not covered in the first five chapters of the text. There will be some deduction if you do.