CSE-1020: Introduction to Computer Science I
York University
Exam Labtest: FractionFilter
  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.

FractionFilter.java

You have about 80 minutes to complete this test. Before the end of the 80 minutes, you must submit your program and log off the machine. Do not leave your machine without logging off, or the next person to use it will have access to your code and could overwrite it. The lab monitors will announce when the 80 minutes are nearly up. Anyone not logged off after 80 minutes will lose marks.

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 FractionFilter.java before the time deadline. Here is the command to submit your work:

% submit 1020 ... FractionFilter.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 FractionFilter.java. It should read in (unprompted) from standard input a series of numerator-denominator pairs. These integer tokens will be separated by whitespace. From these, it must create and, where appropriate, store, type.lib.Fraction instances. You can assume that there is never a numerator without a denominator, i.e. that the number of integers entered is even. The program should store one instance of each unique fraction, i.e. it should not store the same fraction twice or more. (Recall, for example, that the Fraction 2/3 is equal to the Fraction 4/6.)

Your application should, in order,

  • print out "-----" alone on a line (that's 5 dashes)
  • print out a list of the (unique) Fractions entered, one per line and sorted from largest to smallest
  • print out the sum of the 3 largest fractions - also as a type.lib.Fraction object. You may assume that there are always at least 3 different fractions entered.

See the sample run below for the expected output format.

Sample Run

Here is a run of a correctly written program. The 3 largest fractions are 5/1, 1/2 and 1/4. The sum of these is 23/4. The program output begins with the 5 dashes "-----".

% 
% java FractionFilter 
1   2
1  5
10  -3
5 1
1 4
2  31
2 4
2 10
10 2
-----
5/1
1/2
1/4
1/5
2/31
-10/3
23/4
%

Note that there is no blank or other whitespace at the end of lines, except for a newline character automatically printed by println.

Coding

You should use good programming practices as described in the textbook, and your code should conform to the style guide in the textbook. You code must be properly commented. You should use appropriate classes and methods and favour simplicity over convoluted approaches that "somehow" manage to come up with the right answer.