Computer Science 202
Introduction to Programming
Fall 2012, The College of Saint Rose
For your first programming project, you will write a Java program that adds fractions.
Ground Rules
You must work individually on this program. While you may ask for help from your instructor or from the tutors in the Academic Support Center, that help will be more limited than for regular lab assignments. Additionally, any help you receive must be clearly documented in the comment at the top of your program (i.e., who helped you and exactly what that help was).
Program Requirements
Read these directions carefully and follow them precisely. Part of your grade will depend on you formatting prompts and printouts as described.
Enter the numerator and denominator for a fraction:
Enter the numerator and denominator for another fraction:
For example, if you entered 2 and 3 for the first number (meaning your
fraction is 2/3, though you should not type the /
nor should
your program expect it), and 3 and 5 for the second (for a fraction of
3/5), your answer would have a 19 for the numerator and 15 for the
denominator, or 19/15, which is the right answer in this case.
The sum of 2/3 and 3/5 is 19/15.
Again, if this fraction is not in lowest terms (i.e., it can be reduced), don't worry about that.
That's 1.2666666666666666 in decimal notation.
Or 1 4/15 as a mixed number.
Again, do not worry about reducing the leftover fractional part to lowest terms. Also, if there is no fractional part left, you can still print out in the same format just with a 0 in the numerator.
Here are two more example inputs and outputs.
If your input fractions are 1/3 and 5/6, the output should be:
The sum of 1/3 and 5/6 is 21/18. That's 1.1666666666666667 in decimal notation. Or 1 3/18 as a mixed number.
If your input fractions are 3/4 and 10/8, the output should be:
The sum of 3/4 and 10/8 is 64/32. That's 2.0 in decimal notation. Or 2 0/32 as a mixed number.
Can I Do This?
Rest assured that we have seen every Java feature you need to use in class examples and labs. If you find yourself thinking that there is something you don't know how to do, look over the class examples for something similar. You should not need, nor should you use, any Java constructs we have not yet covered in class.
Style and Documentation Reminders
Before you submit your program, make sure it conforms to our guidelines for style and documentation.
In particular, you should have a comment at the top of your class that describes your program and has your name, the course number and section (02 for 11:15, E1 for 4:10). You should have comments throughout your programs describing your variables and any non-obvious Java statements or groups of statements.
All identifiers (class names and variable names) should be meaningful and conform to Java's naming conventions.
Your code should be nicely formatted, with new lines after any
{
or }
, and indented as done in class examples.
Bonus Opportunity
For a few bonus points, you may extend your program to work for a sum of three fractions.
Submitting Your Work
Before 11:59 PM, Wednesday, September 26, 2012, submit your Java program to Blackboard for grading. Please upload your Java source file (Fractions.java - upload the one with the .java file extension, not the .class, .ctxt, package.bluej or README files).
Grading
This assignment is worth 50 points, which are distributed as follows:
> Feature | Value | Score |
Scanner construction | 5 | |
Correct prompts | 5 | |
Read and store inputs | 5 | |
Computing improper fraction | 6 | |
Computing decimal result | 6 | |
Computing mixed number result | 6 | |
Output formatting | 5 | |
Comments | 5 | |
Naming conventions | 5 | |
Formatting | 2 | |
Bonus | up to 2 | |
Total | 50 | |