【发布时间】:2018-07-19 17:24:01
【问题描述】:
我有一个计算机数学课程项目,我们需要输入 3 个系数 (ax^2 + bx + c) 并使用二次公式来计算零点。这对我们来说不会太难,但我们必须将工作分成不同的资源类和一个驱动程序类。
到目前为止,这就是我所拥有的
import java.util.Scanner;
public class coEff
{
public int coEff()
{
int a, b, c;
double root1, root2, root3, d;
Scanner s = new Scanner(System.in);
System.out.print("Enter the A coefficient");
a = s.nextInt();
System.out.print("Enter the B coefficient");
b = s.nextInt();
System.out.print("Enter the C coefficient");
c = s.nextInt();
return coEff();
}
}
二等:
import java.util.Scanner;
public class calcZeroes
{
public int calcZeroes()
{
coEff coEff = new coEff();
coEff.coEff();
int a, b, c;
double root1, root2, root3, d;
return calcZeroes();
}
}
我有计算公式的代码,但它不起作用,因为系数没有初始化。任何帮助将不胜感激:)
【问题讨论】:
-
对此并不完全确定,因为我有一段时间没有使用 java,但我认为您可以为此使用 getter 和 setter。获得数据后,立即在第二类中设置值。或者您可以在第二个类中使用构造函数,其中参数是 3 int,然后在构造函数内部分配值