-
April 9th, 2007, 02:53 PM
#31
Re: Bagels(fermi,pico,bagels) code help
I may be misunderstanding your problem (if so, I apologize in advance) but the way I see it, you need two separate loops, one nested within the other. The outer loop would allow the user to play multiple games, and the inner loop would allow the user to make multiple guesses within a game. Something like this:
Code:
loop until the user doesn't want to play another game
{
generate a random number
loop until the user guesses the number
{
get guess
evaluate guess
}
ask the user if he wants to play another game
}
Old Unix programmers never die, they just mv to /dev/null
-
April 9th, 2007, 02:57 PM
#32
Re: Bagels(fermi,pico,bagels) code help
Originally Posted by dlorde
I agree that this history is the origin of the phenomenon, but I think that there are enough independent minds appearing in the coding field every year who know that there's negligible practical difference between 'for' or other loop structures these days, that usage would have changed if the alternatives had any other advantage or appeal. Instead, they've pretty well died out. Novices are taught the 'for' loop first because it is essential and can do it all - and once they get familiar with 'for', they soon realise they simply don't need to bother with the others. I think it's an example of evolution in action - the more elegant, descriptive, and specialized (but redundant) loop tools have proven less fit in the coding arena than the cruder, all-purpose functionality of the 'for' loop. Initially it was due to a bad rep, but later just plain human factors.
OK, it's all (melodramatic) speculation, but I like to think there are these kinds of patterns in the development of software tools and languages
Interesting... I've always been taught to use the for loop when you know how many times you're looping (e.g. for iterating over a known number of elements etc.) and the while loop in all other cases and that is what I continue to do when I write code... but it's definitely interesting to see these constructs evolve... perhaps in the next generation of languages there will be only one type of loop, similar to the for...
Old Unix programmers never die, they just mv to /dev/null
-
April 9th, 2007, 05:29 PM
#33
Re: Bagels(fermi,pico,bagels) code help
I think it's an example of evolution in action - the more elegant, descriptive, and specialized (but redundant) loop tools have proven less fit in the coding arena than the cruder, all-purpose functionality of the 'for' loop.
Is this evolution or dumbing down?
Personally speaking I'm with HighCommander4, for loops for a known number of iterations, while loops for 0 to n iterations and do loops for 1 to n iterations.
If we are going to force a single syntax to do everything then lets get rid of the lot of them and bring back goto's
-
April 10th, 2007, 12:20 AM
#34
Re: Bagels(fermi,pico,bagels) code help
I'm having a problem with my code and would really appreciate any assistance that is given. Here is an example of the problem i'm having :
Let say my secNum = 107
user enters= 701(it prints out fermi pico pico) which is fine.Then i enter 701 it says Winner!! Then it asks me if i want to play again i enter Y and it does not generate another secNum .Here i'm posting my code let me know if you can see what i'm doing wrong.Thanks
Code:
public void playGame()
{
Scanner input = new Scanner(System.in);
System.out.println("Do you want to Play ? Type Y for Yes or N for No and press [Enter] ") ;
String answer = input.next() ;
numGen() ;
if(endGame == false)
{
while(answer.equalsIgnoreCase("Y"))
{
getGuess() ;
evalGuess() ;
System.out.println("Do you want to guess again? Type Y for Yes or N for No and press [Enter] " ) ;
answer = input.next() ;
}
}
else
{
do
{
numGen() ;
System.out.println("Do you want to Play again? Type Y for Yes or N for No and press [Enter] ") ;
answer = input.next() ;
}
while(answer.equalsIgnoreCase("Y")) ;
}
}
Last edited by Strobe; April 10th, 2007 at 06:45 AM.
Reason: Found another issue with code
-
April 10th, 2007, 07:46 AM
#35
Re: Bagels(fermi,pico,bagels) code help
I Finally finished the program. I would like to thank all of you for your help.
-
April 10th, 2007, 10:52 AM
#36
Re: Bagels(fermi,pico,bagels) code help
Hello everyone i'm back again. I found another problem with my code and i need help. See my program does everything that you ask of it except that if you enter 3 digits and none match at the beginning of the game it responds correctly with a message that says Bagels!!!But if you do a few entries and win then play again enter some digits that match but not in right place it gives message(pico pico pico) IT then asks me if i would like to play again i say Yes then it generates a new new number but this time after entering 3 digits that don't match it doesn't give you that message (BAGELS!!)
it just asks for the next guess. Here is my code let me know what i'm doing wrong. The assignment is already due and i'm trying to get it finished to turn it in after class .
Code:
// Compares user guess to random number
private void evalGuess ()
{
if(secNum == playGuess)
{
endGame = true ;
System.out.println("WINNER! (The Game is Over)"+ ","+" tries = " + guessCnt + "," +" Wow, you are quite the genius !" ) ;
}
else
{
user1 = (playGuess)/100 ;
user2 = (playGuess%100)/10 ;
user3 = (playGuess%100)%10 ;
if(user1 == user2 || user1 == user3 || user2 == user3)
System.out.println("Try again, no digits may be the same") ;
else
{
if(rand1 == user1)
{
fermiCnt++ ;
System.out.println("Fermi") ;
}
if(rand2 == user2)
{
fermiCnt++ ;
System.out.println("Fermi") ;
}
if(rand3 == user3)
{
fermiCnt++ ;
System.out.println("Fermi") ;
}
if(rand1 == user2)
{
picoCnt++ ;
System.out.println("Pico") ;
}
if(rand1 == user3)
{
picoCnt++ ;
System.out.println("Pico") ;
}
if(rand2 == user1)
{
picoCnt++ ;
System.out.println("Pico") ;
}
if(rand2 == user3)
{
picoCnt++ ;
System.out.println("Pico") ;
}
if(rand3 == user1)
{
picoCnt++ ;
System.out.println("Pico") ;
}
if(rand3 == user2)
{
picoCnt++ ;
System.out.println("Pico") ;
}
endGame = false ;
}
if(fermiCnt == 0 && picoCnt == 0 )
{
System.out.println("BAGELS!!! ") ;
endGame = false ;
}
}
}
// Check wether its the end of game or not
private boolean gameStatus()
{
return endGame;
}
// Plays game
public void playGame()
{
Scanner input = new Scanner(System.in);
System.out.println("Do you want to Play ? Type Y for Yes or N for No and press [Enter] ") ;
String answer = input.next() ;
numGen() ;
if(answer.equalsIgnoreCase("Y"))
{
do
{
if(endGame == false )
{
getGuess() ;
evalGuess() ;
System.out.println("Do you want to Play Again? Type Y for Yes or N for No and press [Enter] " ) ;
answer = input.next() ;
}
else
{
numGen() ;
getGuess() ;
evalGuess() ;
guessCnt = 0 ;
System.out.println("Do you want to Play Again? Type Y for Yes or N for No and press [Enter] " ) ;
answer = input.next() ;
}
}
while(answer.equalsIgnoreCase("Y")) ;
}
else
{
endGame = true ;
System.out.println("You Quit"+ ","+"tries = " + guessCnt + " Was that all you got ? ");
}
}
Last edited by Strobe; April 10th, 2007 at 11:12 AM.
-
April 10th, 2007, 06:32 PM
#37
Re: Bagels(fermi,pico,bagels) code help
Originally Posted by keang
Is this evolution or dumbing down?
Both, I guess. Evolution doesn't care whether things get more complex or simpler...
Personally speaking I'm with HighCommander4, for loops for a known number of iterations, while loops for 0 to n iterations and do loops for 1 to n iterations.
I have no problem with that - I prefer to see all the constructs used appropriately - the one that really irritates me is the for loop with no increment:
Code:
for (Iterator foo = bar.iterator(); foo.hasNext();/*yeuch!*/) { ...
It just feels wrong to deliberately use a partial (mutilated) 'for' loop when there's a far more suitable construct for the job.
If we are going to force a single syntax to do everything then lets get rid of the lot of them and bring back goto's
Assembler was quite fun while it lasted...
Everything should be made as simple as possible, but not simpler...
A. Einstein
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
April 11th, 2007, 09:59 AM
#38
Re: Bagels(fermi,pico,bagels) code help
Personally speaking I'm with HighCommander4, for loops for a known number of iterations, while loops for 0 to n iterations and do loops for 1 to n iterations.
I have no problem with that - I prefer to see all the constructs used appropriately - the one that really irritates me is the for loop with no increment:
I've just realised my comment sounds like it was in contradiction of your statement, it wasn't meant to - sorry, it was badly phrased.
It just feels wrong to deliberately use a partial (mutilated) 'for' loop when there's a far more suitable construct for the job.
Absolutely and IMHO it should be discouraged at every opportunity.
Assembler was quite fun while it lasted...
Now we're getting somewhere, although assembler is for sissies - what's wrong with writing straight machine code.
-
April 11th, 2007, 02:38 PM
#39
Re: Bagels(fermi,pico,bagels) code help
Originally Posted by keang
I've just realised my comment sounds like it was in contradiction of your statement, it wasn't meant to - sorry, it was badly phrased.
No offence taken
... assembler is for sissies - what's wrong with writing straight machine code.
Hmm, I remember toggling bit switches on a minicomputer to boot into its system loader... punching 80-column cards by hand... accidentally wiping a building society's 50MB disk stack while upgrading their system... happy days! Glad they're over
Software gets slower faster than hardware gets faster...
N. Wirth
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
April 11th, 2007, 03:22 PM
#40
Re: Bagels(fermi,pico,bagels) code help
Hmm, I remember toggling bit switches on a minicomputer to boot into its system loader... punching 80-column cards by hand...
Congratulations, you've just proved you're even older than me
-
April 11th, 2007, 04:40 PM
#41
Re: Bagels(fermi,pico,bagels) code help
Originally Posted by dlorde
accidentally wiping a building society's 50MB disk stack while upgrading their system
That beats mine, I was learning to use edlin on the boss's secretary's computer (didn't have one of my own), and somehow overwrote the FAT.
-
April 11th, 2007, 05:06 PM
#42
Re: Bagels(fermi,pico,bagels) code help
Originally Posted by dlorde
accidentally wiping a building society's 50MB disk stack while upgrading their system
Originally Posted by petes1234
learning to use edlin on the boss's secretary's computer (didn't have one of my own), and somehow overwrote the FAT.
I feel truely humbled by the magnitude of your combined ineptitude, well done.
-
April 11th, 2007, 05:10 PM
#43
Re: Bagels(fermi,pico,bagels) code help
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
March 27th, 2013, 11:52 AM
#44
Re: Bagels(fermi,pico,bagels) code help
Hi can you please upload the correct code for the Bagels class! Thank you so muchhh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|