Question: ITCS 1213 Lab 7 Purpose: To practice designing a class that is useful for many applications. To create an object in a method. To write

ITCS 1213 Lab 7 Purpose: To practice designing a class that is useful for many applications. To create an object in a method. To write a method that returns a reference. To practice writing a test driver to test all the methods of a class. This is a lab requiring logic and Java skills. We suggest you do this lab with a lab partner. Use the Linear Measure class and Driver we went over in lecture this week. Step 1. You will be writing a class to hold data and perform operations on fractions. You will then test this class by writing a Driver class that tests each of the methods as you write them. Before you write any code, perform each of these operations, taking notes with your lab partner of what you are doing at each step. You must show this completed document to your TA before starting to write any code. 1. Simplify: Original Simplified Notes 8/16 6/15 8/12 14/24 9/21 2. Add and express sum in simplest form: Problem Answer Notes 3/5 + 1/5 3/8 + 5/12 5/6 + 1/5 4/9 + 3. Multiply and express product in simplest form: Problem Answer Notes * 2/3 1/5 * 3/7 2/5 * 4. Divide and express each quotient in simplest form: Problem Answer Notes 4/5 / 4/9 / 15/20 3/8 / 5/6 12/5 / 20/12 5. Compare these fractions: answer in form of > 0r 5/8 < 7/8 Problem Answer Notes 2/5 to 1/3 3/7 to 4/9 5/6 to 4/7 4/5 to 7/8 Step 2: Write a class to hold data and methods for a Fraction. The integer fields will hold the values for the numerator and denominator of a fraction. Each time you write a method, test that method in your driver class. Do not wait until you have written every method before testing. TEST AS YOU WRITE. In addition to the overloaded constructor methods write methods that will perform the following eight operations. When you create the Fraction do not accept zero as a value for the denominator. add two fractions, returning new Fraction reference that is the sum in lowest terms parameter: a reference to another Fraction return type: reference to a new Fraction subtract two fractions- returning a new Fraction reference that is difference in lowest terms (simplify) parameter: a reference to another Fraction return type: a reference to a new Fraction multiply two fractions-returning the product in lowest terms parameter: a reference to another Fraction, return type a reference to new Fraction that is the product of the two Fractions divide two fractions-returning the quotient in lowest terms parameter: a reference to another Fraction, return type: a reference to a new Fraction that is the quotient of the two Fractions compareTo( ) method parameter: a reference to a Fraction equals( ) method parameter: a reference to a Fraction a method to determine and return the decimal value of a fraction no parameters, return type: a double a static method to generate and return a reference to a random fraction that is between 0 and 1. (this means the numerator is less than the denominator) toString( ) method that returns a reference to a String in the form of a/b Here is a simple way to find the greatest common divisor of two numbers: Start with the smaller of the two numbers. Determine if this number goes into the larger of the two numbers evenly. If it does, this is the greatest common divisor, if not; repeatedly subtract 1 from the value of the smallest number until you find a value that goes into both numbers evenly. Step 3: Write a driver class with the main( ) method that tests each of the methods of the class. Be sure to print the output for each test case. Create a project named Fraction Driver using the previous class. In this class code the main method that performs these tasks. Write the code to ask the user if he/she wants to practice with adding, subtracting, multiplying or dividing fractions. Once the user chooses an option, present five problems using the fraction methods to create two random fractions. Present the problem to the user. Read the user answer (numerator and denominator) then use your equals method to determine if the user answer is correct. Display a message stating whether the user answer is correct or not. If it is not correct, print the correct answer. Once the five questions are complete, repeat the menu. Continue repeating until the user indicates he/she is finished.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!