Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

java programming?

ts telling me to do this.

Define accessor (“getter”) methods called getFunctionChoice and getDescription that return the values of the corresponding fields. The method getDescription takes an integer and returns the description corresponding to the integer. Define the toString() method, which returns the value of the “description” field.

and this is what I have.

public class Function {

private double FUNCTION_CHOICE;

private String description;

public Function(String index)

{

description = index;

}

public void setDescription(String description)

{

this.description = description;

if(description.equals(1))

{

description = "((8x-sqrt(x)/(x^3 - 7x^2 + 15x -9)";

}

else if(description.equals(2))

{

description = "sinx" ;

}

else if(description.equals(3))

{

description = "5/x + 35" ;

}

else if(description.equals(4))

{

description = "sqrt(x^2+16)-4)/x^2" ;

}

else if(description.equals(5))

{

description = "(e^x-1)/x";

}

}

public static int getDescription(int num)

{

return num;

}

public double getFunctionChoice()

{

return FUNCTION_CHOICE;

}

public String toString()

{

return description;

}

}

I have no errors, but its not printing what I want it to, does anyone know why? thanks

1 Antwort

Relevanz
  • ?
    Lv 7
    vor 5 Jahren

    description = "((8x-sqrt(x)/(x^3 - 7x^2 + 15x -9)";

    Here, you are setting the parameter description, not the instance variable description. I think you'd need to do this:

    this.description = "((8x-sqrt(x)/(x^3 - 7x^2 + 15x -9)";

    Or maybe you could call the parameter by some other name, to avoid confusion.

    Also, isn't the parameter supposed to be an int, not a String? You're comparing it to various numbers, after all.

Haben Sie noch Fragen? Jetzt beantworten lassen.