私が新しいプログラムを作成し、分数クラスと私の本がメインクラスであるドライバークラスと呼んでいるものを持ちたいとしたら、私はこのようなコードを持っています
// 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();
}
}
...
私の分数クラスには、パブリック分数と呼ばれるメソッドがあります。スキャナーユーティリティから入ってくるドライバークラスの分数cからの両方の数値をどのように設定しますか?また、cの値は分数dから入ってくる値に置き換えられますか? 私は Java のクラスを取っていますが、これは理解できない私の宿題の一部です。最終的にこれらの 2 つの分数を加算して乗算する必要があるため、これらの値を分数クラスに渡そうとしています。
// 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?
}
誰でもこれで私を助けることができますか