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 String getDescription(int des)

{

des = description;

return description;

}

public String getFunctionChoice()

{

return description;

}

public String toString()

{

return description;

}

im not really sure what im supposed to do

2 Antworten

Relevanz
  • vor 5 Jahren

    The accessor does not take an argument value. It simply returns a value.

    public string getDescription() {

    .... return description;

    }

    public ??? getFunctionChoice() { // replace ??? with the data type of functionChoice

    .... return functionChoice;

    }

    Only a setter uses an argument, and then it doesn't (usually) return a value, so the type will be void:

    void setDescription(String desc) {

    .... this.description = desc;

    }

    Your toString() method looks fine.

    Edit: Okay, I reread the description. You don't say how your description data is stored, but the assignment sounds like it's an array:

    String getDescription(int index) {

    .... return description[index];

    }

    If you some other way of mapping integers to descriptions based on instance fields, you'll do something else.

    If the description field is indeed an array, you won't get a "nice" string from description.toString() to return. One alternative is to import java.util.Arrays and then:

    String toString() {

    .... return Arrays.toString(description); // return "nice" display of description array

    }

    You might want something more print-ready, though. I might try something like:

    StringBuilder result = new StringBuilder();

    line line = 0;

    for (text : description) {

    .... result.append( String.format( "%d : %s\n", ++line, text);

    }

    return result.toString();

  • ?
    Lv 7
    vor 5 Jahren

    I don't think we can know exactly what you are supposed to do without seeing a little more code.

    "The method getDescription takes an integer and returns the description corresponding to the integer. " - Is there an array of descriptions, or something?

    I still really doubt that getFunctionChoice() is supposed to return the description. Is there a functionChoice variable it is supposed to return?

Haben Sie noch Fragen? Jetzt beantworten lassen.