1). Write a programme which asks the user for their date of birth and then 
tells them how old they are.
Hint: 
Having input the user's date of birth, you will have three integers day, month, 
and year from the user and three integers from the system. You then subtract 
this year from the year entered by the user and then subtract one if the month 
entered by the user is after this month or the months are the same and the day 
entered by the user is after today's day.
 
 
2). Write a programme that tries to guess the number thought of by the user. 
The number is between 0 and 1000. If the computer's guess is too high, the user 
should enter 2. If the computer's guess is too low, the user should enter1. If 
the computer's guess is correct, the user should enter any integer except 1 and 
2. Print out how many guesses it took the computer. Also print out if the user 
cheated.
Hint:
You need a loop. You can use a boolean variable finished to get out the loop. 
Before you enter the loop set finished to false. The loop should look like this;
 
while(!finished)
{
 
}
 
When the game is over, set finished to true. Then the loop will terminate. 
Store the lowest and highest possible values. Each time choose half way in 
between. Use integer division by two to achieve this. Half way in between will 
be (highest + lowest)/2. Depending on whether the user enters 1 or 2 there will 
either be a new highest or a new lowest. If the computer doesnot guess by 
chance, eventually the highest and the lowest will become the same value. If 
this is not the right answer then the user must have cheated!
 
 
Thank you as you help me to solve these problems.
Regards,
Emmanuel.


      
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to