

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The learning objectives and instructions for program 4 of cs 110 spring 2009. Students are required to expand their fraction class by adding instance methods for addition, subtraction, multiplication, division, and determining if the fraction is proper or improper. The tostring() method should display the fraction type based on the isproperfraction() method. In the fractiondemo main method, users input the numerator and denominator for two fraction objects, display their values, and execute the arithmetic methods.
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


CS 110 Spring 2009
Demonstrate the ability to write a simple Java project that includes a user-defined class : Fraction Demonstrate how to use instance variables and methods in your user-defined class Demonstrate the use of objects in your driver program Understand simple decision making concepts.
This assignment builds on the two .java files you did for Lab4. Begin by copying from your Lab4 folder, the Fraction.java and FractionDemo.java files, to your Program4 folder. Expand your Fraction class from Lab 4 by adding five more instance methods: add, subtract, multiply, divide, and a method to determine if the fraction is a proper or improper fraction. In a proper fraction, the numerator is less than the denominator; in an improper fraction the numerator is greater than or equal to the denominator. Please take note of the isProperFraction( ) method’s return type designated in the UML diagram. Methods add, subtract, multiply, and divide should accept a Fraction argument passed as the parameter and return a Fraction. The toString( ) method of the Fraction class should declare a local boolean variable, which is set to either true or false by calling the isProperFraction( ) method. Inside the toString( ) there will be an if / else decision making process which depends on the value returned from the isProperFraction( ) method. A different String message is returned, depending on which of these if / else statements execute. In your FractionDemo main method, implement the following:
In case you have forgotten your fraction arithmetic, here is a quick crib sheet for addition, subtraction, multiplication, and division. Do not worry about reducing your fractions (e.g. 4 / 8 is fine, do not reduce it to 1 / 2) Fraction
50 points maximum 26 points - Output Correctness o The program reads in the initial values for the two fractions from the user (5) o The program produces the correct result for addition, subtraction, multiplication, and division (5 points each) o The Fraction toString( ) method correctly displays the type of fraction (proper or improper) (1 point) 9 points - Class Definition o The Fraction class is defined correctly with attributes (fields) declared as private (2)