# Fractions

• January 29th, 2013, 05:57 PM
ps3lover3
Fractions
I need help with an assignment I have for school. I'm a sophomore in high school in Computer Science 1. We use Eclipse (Java) for our programs.

Here is the PDF for the assignment:
Classes

I uploaded my Classes project too. Here is what I have so far The class is called "FractionClass" and "FractionClassTester".
Fraction Class Assignment.pdf

• January 29th, 2013, 06:01 PM
Norm
Re: Fractions

Post everything here on the forum. No links.
• January 29th, 2013, 06:16 PM
ps3lover3
Re: Fractions
Assignment:
You will create a class to represent fractions. The requirements below will establish how this class should be structured.
Part 1
* The class should store a numerator and denominator
(remember, data members should be private at this point in your programs) * The class should have both a default and non*default constructor
* Do not make any set() accessor methods
Part 2
* The class should have the following methods:
+ Fraction subtract(Fraction other)
+ Fraction multiply(Fraction other)
+ Fraction divide(Fraction other)
+ print() : print the fraction to the screen [as a fraction]
** NOTE: none of the arithmetic methods should modify the values of either operand; they should simply return the result of the calculation.
Part 3
The main method in your tester class should have the following...
* 10 different Fraction variables initialized with different values
* 1 additional Fraction variable to store the result of the calculations
* 5 calls to the addition method, print out the results [not within the add method]
* 5 calls to the subtraction method, print out the results [not within the subtract method] * 5 calls to the multiply method, print out the results [not within the multiply method]
* 5 calls to the divide method, print out the results [not within the divide method]

For some reason my code won't open in Eclipse from my USB. But all I had was part one down.

--- Update ---

Please use the link for the Classes. I can't open it for some reason.
• January 29th, 2013, 06:31 PM
Norm
Re: Fractions
• January 29th, 2013, 06:37 PM
ps3lover3
Re: Fractions
FractionClass:

public class FractionClass {
private int numerator;
private int denominator;

public FractionClass()
{
numerator = 1;
denominator = 2;
}

public FractionClass(int num, int den)
{
numerator = num;
if (den == 0)
den =1;
denominator = den;
}

{

return null;
}

public FractionClass subtract(FractionClass other)
{
return null;
}

public FractionClass multiply(FractionClass other)
{
int num = numerator * other.numerator;
int den = denominator * other.denominator;

return new FractionClass(num, den);
}

public FractionClass divide(FractionClass other)
{
int num = numerator * other.denominator;
int den = denominator * other.numerator;

return new FractionClass(num, den);
}

public void printFractionClass()
{
// Print values as a fraction

}
}

FractionClassTester:

public class FractionClassTester {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}
• January 29th, 2013, 08:10 PM
ps3lover3
Re: Fractions
FractionClass:

public class FractionClass {
private int numerator;
private int denominator;

public FractionClass()
{
numerator = 1;
denominator = 2;
}

public FractionClass(int num, int den)
{
numerator = num;
if (den == 0)
den =1;
denominator = den;
}

{

return null;
}

public FractionClass subtract(FractionClass other)
{
return null;
}

public FractionClass multiply(FractionClass other)
{
int num = numerator * other.numerator;
int den = denominator * other.denominator;

return new FractionClass(num, den);
}

public FractionClass divide(FractionClass other)
{
int num = numerator * other.denominator;
int den = denominator * other.numerator;

return new FractionClass(num, den);
}

public void printFractionClass()
{
// Print values as a fraction

}
}

FractionClassTester:

public class FractionClassTester {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}