63 088
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #63473 in Java | JSP | JSF for Scott Royle

Question #63473
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 Main {
public static void main(String[] args) {
Divider d = new Divider();

System.out.println(d.getDivisor());

d.setDivisor(3);

System.out.println(d.getDivisor());

d.setDivisor(0);

System.out.println(d.getDivisor());
}
}

class Divider {
private int divisor;

public Divider() {
divisor = 2;
}

public int getDivisor() {
return divisor;
}

public void setDivisor(int newDivisor) {
if (newDivisor == 0) {
return;
}

divisor = newDivisor;
}
}

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