I don't understand why it doesn't give a random amount. Please explain.
Thanks :)
my code(learned from tutorial):
public class day5 {
int totalwater = 0;
public day5(){
//default constructor
}
public day5(int wateramount){
totalwater = wateramount;
}
// don't need static in Object. It will be used in other classes.
public void addwater(int amount){
totalwater = totalwater + amount;
}
public void drinkwater(int amount){
totalwater = totalwater - amount;
}
public int getwater(){
return totalwater;
//because we are going to return an integer, public "int" and "return"
}
}
public class day5obtest {
public static void main(String[] args){
day5 waterbottle = new day5(0);
int rand = (int)(Math.random()*100);
waterbottle.addwater(rand);
waterbottle.drinkwater(rand);
System.out.println("The amount of water in your bottle now is: " + waterbottle.getwater());
}
}
Output:
The amount of water in your bottle now is: 0