60 403
Assignments Done
98,2%
Successfully Done
In April 2018

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
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions