Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

java - Stuck on creating a Setter method

So at the moment, I've managed to create a getter method with the following code

public int getDivisor() {
  return this.divisor;
}

That will return 2.

I'm stuck on creating a setter method for my project. The question is: Write a public setter method for divisor, which sets divisor to the value of the argument. It cannot be 0, really am stuck on this question. Can anybody help, please? Much appreciated.

I have now added the following method

public void setValue(int number) {
  if (number == 0)
    this.divisor = number;
}

for the setter message.

After entering a message divisor.SetValue(); it comes back the error cannot find symbol - method SetValue(). Am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

setValue() and SetValue() are two different things. Names are case sensitive. That's why compiler couldn't find setValue() since you typed SetValue()!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...