/*
* 問題:FunctionSet02クラスを継承して,関数f(x, z,w) = ax2 + bz2 + cw2を
* メソッドとして実装したFunctionSet04クラスを作成せよ
* また,f(x, z,w) = ax2 + bz2 + cw2 の実装は,メソッドのオーバーロードにあたるかオーバーライドにあたるかを
* コメント「//...」として付記せよ
* さらに,上で作成したメソッドを実行するためのメインメソッドをFunctionMain08クラスに作成し実行せよ.
* ただし,引数としてx = 2.0, z = 4.0,w = 1.0 を代入し,a = 1.0, b = 2.0, c = 3.0としたインスタンスメソッドと
* a = 3.0, b = 5.0, c = 7.0 としたインスタンスメソッドの2 つを実行するようにせよ.
*/
class FunctionSet02 {
double a;
double b;
//コンストラクタ
FunctionSet02() {
this.a = 1.0;
this.b = 0.0;
}
//コンストラクタのオーバーロード
FunctionSet02(double a, double b) {
this.a = a;
this.b = b;
}
//メソッド
double f(double x) {
return a * x + b;
}
}
class FunctionSet04 extends FunctionSet02 {
double c;
FunctionSet04(double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
// メソッドのオーバーロード
double f(double x, double z, double w) {
return a
* Math.
pow(x,
2) + b
* Math.
pow(z,
2) + c
* Math.
pow(w,
2); }
}
class FunctionMain08 {
public static void main
(String[] args
) { FunctionSet04 fs04_1 = new FunctionSet04(1.0, 2.0, 3.0);
double f1 = fs04_1.f(2.0, 4.0, 1.0);
FunctionSet04 fs04_2 = new FunctionSet04(3.0, 5.0, 7.0);
double f2 = fs04_2.f(2.0, 4.0, 1.0);
System.
out.
printf("f1 = %f, f2 = %f", f1, f2
); }
}
LyoKICog5ZWP6aGM77yaRnVuY3Rpb25TZXQwMuOCr+ODqeOCueOCkue2meaJv+OBl+OBpu+8jOmWouaVsGYoeCwgeix3KSA9IGF4MiArIGJ6MiArIGN3MuOCkgogKiDjg6Hjgr3jg4Pjg4njgajjgZfjgablrp/oo4XjgZfjgZ9GdW5jdGlvblNldDA044Kv44Op44K544KS5L2c5oiQ44Gb44KICiAqIOOBvuOBn++8jGYoeCwgeix3KSA9IGF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