I have some questions about java. There are two questions in the code (I left them as comments). Also what is the purpose of using setting and getting methods? Could you please explain it very briefly. I am a beginner. Thank you :)
public class Die
{
private final int MAX = 6;
private int faceValue;
public Die()
{
faceValue = 1;
//why do you set the faceValue as 1?
}
public int roll()
{
faceValue = (int)(Math.random() * MAX) + 1;
//Why do we use MAX instead of just number 6?
return faceValue;
}
public void setFaceValue (int value)
{
if (value > 0 && value <= MAX)
faceValue = value;
}
public int getFaceValue()
{
return faceValue;
}
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}
}