java관련 질문인데요, 여기서 뭐가 잘못된거죠?
하나
다항식의 계산과 관련되서 프로그램 소스를 만드는 중입니다.
숫자간의 곱셈과 덧셈인데, 제가 생각한것처럼 되지않네요.;;;
잘못된 부분을 어떻게 고쳐야하는지 좀 봐주세요(아랫부분에 소스코드있습니다.)public class main {
public static void main(string[] args) {
scanner s = new scanner(system.in);
quadratic q = new quadratic();
system.out.println(type any number to change the coefficients);
system.out.println(input the coefficient of second power of x);
double coef1 = s.nextdouble();
system.out.println(input the coefficient of first power of x);
double coef2 = s.nextdouble();
system.out.println(input the coefficient of zero power of x);
double coef3 = s.nextdouble();
q.change(coef1, coef2, coef3);
q.getcoefficient();
system.out.println(input a number to evaluate the quadratic equation.);
double coef4 = s.nextdouble();
q.evaluate(coef4);
system.out.println(input three coefficients of another quadratic equation in order from second power to zero power.);
double coef5 = s.nextdouble();
double coef6 = s.nextdouble();
double coef7 = s.nextdouble();
q.sum(coef5, coef6, coef7);
q.getcoefficient();
system.out.println(input a multiplier.);
double coef8 = s.nextdouble();
q.scale(coef8);
q.getcoefficient();
}}여기까진 메인이구요===============================================================================================public class quadratic { private double a;
private double b;
private double c; public quadratic() // constructor - set all coefficient equal zero.
{
a = 0;
b = 0;
c = 0;
}
public double change( double input1, double input2, double input3)
{
a = input1;
b = input2;
c = input3; return 0; // does not return anything. it just change the value of a, b, and c.
}
public void getcoefficient() // ??accessor method 이렇게 해도되나? 이렇게 아니고 public int getcoefficient()로 하면
{ // 리턴값이 하나밖에 없지않나? 어떻게 3개의 상수를 return하나??
system.out.println(the current value of coefficient is + a + , + b + , and + c + .);
system.out.println(so, it is + a + x^2 + + b + x + + c + .);
}
public double evaluate(double input4)
{
double result = a * input4 * input4 + b * input4 + c;
return result;
}
public double sum(double input_1, double input_2, double input_3)
{
a = a + input_1;
b = b + input_2;
c = c + input_3; return 0; //does not return anything. it just change the value of a, b, and c.
}
public double scale(double input5)
{
a = a * input5;
b = b * input5;
c = c * input5; return 0; //does not return anything. it just change the value of a, b, and c.
}
}위에 public double evaluate 부분에서요 제가 input으로 1을 집어 넣었더니다음과같이 결과가 뜨네요.input a number to evaluate the quadratic equation.
1
input three coefficients of another quadratic equation in order from second power to zero power.
보시다시피, 1을 넣었을때를 계산하지않고 그냥 넘어가버리는데요, 이게 왜 이런가요??
-
큰솔
return은 말그대로 값을 돌려준다는 겁니다 함수를 호툴한 부분에 값을 돌려주는 거지 화면에 출력하는 명령은 아닙니다.
-
유희
q.Evaluate 하면 return값이 출력되는거 아닌가욤? +_+?
-
지희
계산은 하는데 출력하는부분이 없네요...