0

I was wondering if someone could check this for me. Ive to write a loop in words, this is what ive came up with.

while (there are days left in holiday)
if (sunny)
go to beach
else
go to swimming pool
go home

Basically its a program that tells you to go home if your holiday is finished, or if there is holidays left over and its sunny, go to beach else go to the swimming pool.
Thanks for your help, Paul

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by javaAddict
0

The days left can be a static variable. The rest of the code can be put in a method. Every time you call that method reduce that variable by 1. Assuming that each call represents each day that passes. when the days becomes zero, with the help of the if statements , print that "go home" and then exit the program.
If you want to put everything in a while loop you can do this:

int daysLeft = 30;
while (daysLeft>0) {
  ....
  ....

  daysLeft--;
}
System.out.println("Go Home");

The isSunny or not can be obtained by generating a random number (Math.random). It returns a number between 0 and 1.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.