Answer to Question #63574 in Java | JSP | JSF for scott

Question #63574
1.Create a class called Divider in this project.

2.Declare a private instance variable of type int called divisor, then write a line of code in the constructor to initialise divisor to 2.

3. Write a public getter method for divisor.

4. Write a public setter method for divisor, which sets divisor to the value of the argument, provided the latter is not 0. If it is 0, the method does nothing. (This is because, as its name suggests, divisor is going to be used to divide, so the argument’s value cannot be zero, and the setter must only set it to non-zero values.)

Show an instance of the class to be used in testing, like..

something = something
1
Expert's answer
2016-11-22T12:51:10-0500
public class Divider {
public int divisor;
public Divider() {
setDivisor(2);
}
public int getDivisor() {
return divisor;
}
public void setDivisor(int divisor) {
if(divisor != 0) {
this.divisor = divisor;
}
}
}
public class DividerTest {
public static void main(String[] args) {
Divider d1 = new Divider();
System.out.println("Divisor = " + d1.getDivisor());
d1.setDivisor(4);
System.out.println("Divisor = " + d1.getDivisor());
d1.setDivisor(0);
System.out.println("Divisor = " + d1.getDivisor());
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS