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

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...