
help with assignment
import hsa.Console;
public class FractionTester
{
static Console c;
public static void main (String [] args)
{
Fraction A = new Fraction(); // default 0/1
Fraction B = new Fraction(3,4); // 3/4
Fraction X = new Fraction(A); // copy A to X (can’t do X=A – aliasing)
}
}
// The Fraction class 1.0
class Fraction
{
protected int numerator, denominator; // protected gives access to subclass (5.3)
// default constructor is automatically defined, setting all fields to 0 or null
// unless you create your own, which you should generally do
public Fraction ()
{
numerator = 0;
denominator = 1; // makes more sense than 0/0
}
// copy constructor creates a distinct duplicate of an object by copying data;
// can’t simply assign one object to another because two names will now point
// to the same memory address (called aliasing) meaning that when one is changed,
// the other one is too because they are the same object – usually not desirable
public Fraction (Fraction F)
{
numerator = F.numerator;
denominator = F.denominator;
}
// alternate constructor (there may be several to initialize object)
public Fraction (int num, int den)
{
numerator = num;
denominator = den;
}
public String toString ()
{
return numerator + "/" + denominator;
}
}
i need to add the following to the fraction class:
Improve the read method so that it reads a fraction in as a string without prompt messages and does errorchecking to ensure valid input.

Re: help with assignment
You need a lot more than that to make it a useful class; but for starters: read an integer number, it must be the numerator. Next, if you can read the '/' character, another integer number should follow, it is the denominator, otherwise the denominator equals 1. The method should be static because you don't have a Fraction object yet (it is constructed by that method).
Tip: find a greatest common divisor method (google is your friend); you'll need it.
kind regards,
Jos