Java program: Fraction Class
Imagine that the company you work for is going to create a lot of tutorials on Fractions. You are to create a robust Fraction class that will have all of the following (all examples are for a fraction half that has a numerator of 1 and a denominator of 2):
- Private integers numerator and denominator ;
- All public getter and setter functions for the numerator and denominator;
- Safeguard that the denominator will NEVER become 0!
- a default constructor with no arguments;
- a constructor that accepts both the numerator and denominator;
- a toDecimal method that returns the decimal value of the fraction, example: 1/2 will be 0.5;
- a toString method that will return the fraction as a string, , example: 1/2 will be "1/2";
- a reduce method that will change the numerator and denominator by finding a common denominator and reducing the fraction. Example 3/12 becomes 1/4;
Submit the following as part of this assignment:
- A word document with source code for all files
- Screen shots showing several different fractions and an example where the user tried to assign 0 to the denominator. Your output should show all of the methods listed above.
A class should not interact with the user. If an invalid value is received it simple does not accept it. It does not display a message, it does not exit. It is up to the calling program to check if the value was accepted and display an appropriate message.
Grading Rubric
Rubric |
Points |
Program works correctly, no errors |
5 |
Comments, good names, indented |
1 |
Code is efficient |
2 |
Word document and Java File |
1 |
Screen shots show good test data |
1 |
Standards
- Your program must start with comments giving your name and the name of the assignment.
- If there are any variables your program must use good variable names.
- All input (if any) must have a good prompt so that the user knows what to enter.
- All output must clearly describe what is output.
- The program must be your own work.
- All assignments for this class must be submitted in Blackboard.
- You must submit one word document that includes the source code, and screen shots of good test data.
- Assignments may be submitted up until midnight on the due date.
- You may use the assignment submission page to ask for help, but make sure that you clearly indicate that you are asking for help and not submitting for grading.
If you do not receive a perfect score you may resubmit it as long as it is resubmitted within 3 days.
Assignment IndexThis web site, and all pages therein, are the sole property and responsibility of Zebra0.com.
It is not endorsed, sponsored, or provided by or on behalf of Montgomery College.