CPE 102

Winter 2008

Program 1

 

Due Date

 

You must turn in a functionally correct program to receive any credit.  The grade you receive will be based on when you turn it in minus any deductions for the quality of your implementation and/or multiple submissions.  There is no deduction for the first submission and a 5% deduction for each additional submission, if any.  Programs will be checked for correctness once a day and you will be notified by email if your submission is not functionally correct.  Programs will be graded after the last due date and the results will be emailed to you within a few days of that date.

 

100% (minus any deductions) by 9:00pm Monday, 1/14/07

90% (minus any deductions) by 9:00pm Tuesday, 1/15/07

80% (minus any deductions) by 9:00pm Wednesday, 1/16/07

70% (minus any deductions) by 9:00pm Thursday, 1/17/07

 

Errata:

 

 None so far

 

Objectives

 

 

Resources

 

  1. Your text.
  2. Your instructor.
  3. Tutoring sessions provided by the Computer Science Department (Sun-Thurs 7-9:00pm).
  4. The Java Standard Library documentation
  5. The Handin Reference
  6. The javadocs for the Fraction class.
  7. The provided JUnit tests (FractionTest.java).
  8. The provided JUnit test driver (AllTests.java).
  9. The provided architecture test (P1ArchTest.java).

 

Ground Rules

 

1.       Your program must be an individual and original effort.  Except for any situations explicitly identified in this assignment, you may only receive assistance from your instructor or tutors provided by the Computer Science department (Sun-Thurs 7-9:00pm).  See the course syllabus for the significant consequences for plagiarism.

 

Orientation

 

You will be writing a Java class that represents a fraction.  This class will always store the fraction in reduced form regardless of the data provided to the constructors.  For example, the fraction 3/9 would be stored as 1/3.  The class will have three constructors, and a variety of other methods, including methods to add, subtract, multiply, and divide fractions.

 

Suggestions

 

1.       Read the javadocs for the Fraction class carefully – if you don’t know how to interpret the documentation you will not be able to implement the code.  You may ask your instructor or other students in the class to help you read the javadocs but remember that other students may not help you with your code.

 

2.       Develop incrementally.  Once you understand the documentation you should write a “stub-class” for the Fraction class.  Recall that a stub-class has the minimum necessary code to compile.  In this case, all methods should be implemented as stubs.  Once you have done this you should compile your Fraction class and run the JUnit tests on it (the tests should all fail).  Fix any compiler errors before moving on.

 

3.       For each method, read the javadoc specification and test method in FractionTest.java to help you understand what the method should do before implementing it.

 

4.       Keep track of your hours worked as you go, so you don’t have to guess when you hand in your assignment (see handin section below for information on time.txt).

 

Specification

 

  1. Implement the Fraction class to match its javadoc specification.

 

  1. Be sure all instance variables maintain encapsulation - this means you must make them private.

 

  1. The constructor that accepts both a numerator and a denominator must throw an exception if the denominator is 0 or negative (the numerator may be 0 or negative).  We will discuss exceptions in greater detail later in the quarter but, for now, here is the java code to throw the required exception (you must write the code to that determines when to throw it):

 

throw new IllegalArgumentException();

 

  1. Include the following comment block at the beginning of all of your source files:

 

/**

 * Provide a brief description of what the source file is/does

 *

 * @author Your Name Here      (do the obvious)

 * @version Program X               (replace the X with the actual program number)

 * @version CPE102-X               (replace the X with your section number)

 * @version Winter 2008

 */

 

Testing With the Provided Tests

 

  1. Your code must be 100% correct to recieve credit.  Correctness will be determined using the provided JUnit tests and the provided architecture tests.  Run the JUnit tests using FractionTest.java and AllTests.java in the same way you did in Lab 1 (see Lab 1 for more detailed instructions).

  2. Once you have a complete version of Fraction.java ready, you can run the architecture tests on your code.  This is used as an acceptance test to ensure the structure of your program meets the specifications.  You will not be expected to understand this test code or ever write any yourself.  This is accomplished in a different way in different IDEs.  If you can’t figure out how to add a file to your project you may ask your instructor or another student for help.  Compile the project (containing your Fraction.java and the provided P1ArchTest.java) and run it.  The console output will display the results of the test.
  1. Ask your instructor for assistance if you are not able to run these tests on your own.

 

Handing in Your Source Electronically…

 

  1. Create a plain text file called time.txt to log the amount of time spent on the assignment.  The file will contain only three lines with the following information on each line: name, project number, hours spent.

Example time.txt file:

 

    Sally Student

    Program 1

    7.5 hours


  1. Move the necessary file(s) to your vogon account using your favorite FTP client program.
  1. Log on to vogon using your favorite Shell client program.
  1. Change directory (cd-command) to the directory containing the file(s) to hand in.
  2. Use the following handin command being sure to replace the x below with the correct maximum score you can earn based on the due date, i.e., replace the x with 100 if you are handing in by Monday's deadline, 90 for Tuesday, 80 for Wednesday, or 70 for Thursday.  For example, Program1-100 for Monday, Program1-90 for Tuesday, et cetera.

 

12:01pm vogon ~$ handin graderkm Program1-x  Fraction.java time.txt