CSE-1020: Introduction to Computer Science I
York University
Midterm Labtest
FractionStatistics
2:30pm Wednesday 22 October 2008
(Lab-04)
  Welcome to the Labtest 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.

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).

Time Limit

You have about 80 minutes to complete this test (regular lab time). The computers will automatically shutdown at the end of the lab (e.g., 3:50pm), 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. Newer submissions overwrite older ones.

Submitting Your Work

When you submit a file, you must 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 FractionStatistics.java before the time deadline. Here is the command to submit your work:

% submit 1020 midtermW2.30 FractionStatistics.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 check it in.

Useful APIs

Here are the common APIs that you may access:

 
  The Task

Write a Java application called FractionStatistics.java. It should prompt for, and then read in, at the console multiple numerator denominator pairs and use them to create fractions, using the type.lib.Fraction class.

The input and output here are standard I/O, i.e., unless redirected, input comes from the keyboard and output goes to the screen. To signal end of file or no more input on a Unix system, just type <ctrl>d (control key and letter d at the same time) at the start of a line. (In the sample output below, the <ctrl>d typed by the user is not shown.)

After reading all the input, it should output information about the number of fractions read and the minimum, maximum and average fraction values, as shown in the sample output below. The fractions should be output as "proper fractions", e.g. "1 3/5" instead of 8/5.

If no fractions are entered the program should just output "No fractions.", as shown in the sample output.

The input will be of the form numerator denominator numerator denominator .... You can assume (i.e. do not have to check) that the input never includes a numerator entry without a following denominator.

You should use the Fraction class from package TYPE and the appropriate methods in it. You will lose marks for implementing functionality yourself if an appropriate Fraction method could have been used easily instead.

Sample Runs

Here are three sample runs of a correctly written program. Anything typed by the user is shown in red.


% java FractionStatistics
Enter numerator and denominator pairs for fractions.
 1  2   1  4
Number of fractions is 2
Minimum fraction is "1/4"
Maximum fraction is "1/2"
Average fraction is "3/8"
%
% java FractionStatistics
Enter numerator and denominator pairs for fractions.
3  4   5  4   7  4
Number of fractions is 2
Minimum fraction is "3/4"
Maximum fraction is "1 3/4"
Average fraction is "1 1/4"
%
% java FractionStatistics
Enter numerator and denominator pairs for fractions.


No fractions.
%
%

Coding

You should use good programming practices as described in the textbook, and your code should conform to the style guide in the textbook. Your code should be adequately commented.