Question: Suppose the following setter method exists in a class with an instance variable named percent. Which of the following implementations of the setter method correctly

Suppose the following setter method exists in a class with an instance variable
named percent.
Which of the following implementations of the setter method correctly sets the
value of the instance variable and prevents the percent variable from being set to a
negative value or a value over 100?
public void setPercent(double percent)
{
if(percent >100.0
percent =100.0;
else if(percent 0.0)
percent =0.0;
percent = percent;
}
public void setPercent(double percent)
{
if(percent >100.0
percent =100.0;
else if(percent 0.0)
percent =0.0;
this.percent = percent;
}
 Suppose the following setter method exists in a class with an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!