If i was to make a new program and wanted to have a fraction class and what my book calls a driver class wich is a main class and i have code like this
// Driver class
import java.util.Scanner;
public class DriverClass{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
Fraction c, d;
System.out.println(" Enter a numerator then a denominator:");
c = new Fraction( stdIn.nextInt(), stdIn.nextInt());
c.print();
System.out.println(" Enter a numerator then a denominator:");
d = new Fraction( stdIn.nextInt(), stdIn.nextInt());
d.print();
}
}
...
in my fraction class i have a method called public fraction. How will that set both numbers from fraction c in the driver class wich is coming in from the scanner util and also would this, would the c values be replaced by the values that are coming in from fraction d? I am taking a Java class and this is part the part of my home work I dont understand. I am trying to get these valued passed to the fraction class because in the end i have to add these two fractions together and also multiply them.
// begining of class
public class Fraction{
private int numerator;
private int denominator;
// well this is what my problem is, how do I call for c
// twice in the Fraction class
public int Fraction(int num, int denom){
this.numerator = num;
this.denominator = denom;
}
// is this the right way to recieve the fraction
// from the driver class for both c and d?
}
can any one help me with this one