View Single Post
Old Apr 13th, 2008, 12:04 PM   #14
manny85
Newbie
 
manny85's Avatar
 
Join Date: Apr 2008
Location: Ft Meade MD
Posts: 6
Rep Power: 0 manny85 is on a distinguished road
Re: Random "Letter" Generator

I believe this pseudo code should work for you. You are on the right track with the input validation (making sure users enter uppercase letters and numbers). I've also added that into the pseudo code so you can have some idea where it could go. I tried to bracket some of the code off to prevent confusion but let me know if you're having issues. If anyone else sees any holes or improvements in the pseudo code feel free to comment.

import java.lang*
import java.util.*;
import javax.swing.JOptionPane;

Declare your variables
Tell user to enter A for random letter or 1 for for random number.
if input = A then
{
	while (attempts < 3 && !done)
	{
	rndGuess = Letter(rndNum (0-9))
	ask user to pick a letter between A-J
	if user input.isUpperCase() then
		if rndGuess.CompareTo(userInputStr) < 0 then
			guessed to low
		else 
		{
			if rndGuess.CompareTo(userInputStr) > 0 then
				guessed too high
			Else
				guessed too correctly
				done = true
		}
		attempts = attempts + 1
	else
		tell user to input only uppercase letters
	if attempts > 3 then
		tell user the correct number
	} // end while
}
else
{
	if input.isNumeric() then
		userInputInt = Integer.parseInt(input)
		if userInputInt == 1 then
		while (attempts < 3 && !done)
		{
			generate rndNum(1-10)
			ask user to pick a number between 1-10
			if user input.isNumeric()
				userInputInt = Integer.parseInt(userInputInt)
				if userInputInt < rndGuess then
					guessed too low.
				else
				{
					if userInputInt > rndGuess then
						guessed to high
					else
						guessed correctly
						done = true
				}
			
				attempts = attempts + 1
			Else
				tell user to enter only numbers.
			if attempts > 3 then
				tell user the correct letter.
		} // end while
	else
		tell user to enter to either A (letters) or 1 (numbers) only
}

http://java.sun.com/j2se/1.3/docs/ap...pperCase(char)
__________________
98% of the teenage population will try, does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signature
manny85 is offline   Reply With Quote