Share
Explore BrainMass

Java driver and fraction class that adds,multiplies,prints

This is the farthest I have gone. Am stuck, where do i go from here?

public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
Fraction c, d, x; // Fraction objects

System.out.println("Enter numerator; then denominator.");
c = new Fraction(stdIn.nextInt(), stdIn.nextInt());
c.print();
...

Solution Preview

Attached are 2 files. The Main.java contains your driver class, while Fraction.java contains the Fraction class.
The Main.java captures user input and creates instances of the Fraction class and then displays the ...

Solution Summary

Solution contains two java source code files. The Main.java contains your driver class, while Fraction.java contains the Fraction class. The Main.java captures user input and creates instances of the Fraction class and then displays the results. This is a simple scenario, in which the user is prompted 3 times to enter numerator and denominator values. It will perform addition and multiplication with the first two entries and prints as double the third entry.

Program in action looks like below:

Enter numerator; then denominator.
200/2
Enter numerator; then denominator.
300/4
Sum:
1400.0/8.0 = 175.0
Product:
60000.0/8.0 = 7500.0
Enter numerator; then denominator.
100/3

$2.19