-
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
}
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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 :rolleyes:
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...
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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 :D
-
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")) ;
}
}
-
Re: Bagels(fermi,pico,bagels) code help
I Finally finished the program. I would like to thank all of you for your help.
-
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 ? ");
}
}
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
Originally Posted by keang
Is this evolution or dumbing down?
Both, I guess. Evolution doesn't care whether things get more complex or simpler...
Quote:
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.
Quote:
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 :D
Assembler was quite fun while it lasted...:p
Everything should be made as simple as possible, but not simpler...
A. Einstein
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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.
Quote:
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.
Quote:
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. ;)
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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 ;)
Quote:
... 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 :rolleyes:
Software gets slower faster than hardware gets faster...
N. Wirth
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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 :)
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
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.
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
Originally Posted by dlorde
accidentally wiping a building society's 50MB disk stack while upgrading their system
Quote:
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. :)
-
Re: Bagels(fermi,pico,bagels) code help
Quote:
Originally Posted by petes1234
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.
:eek: ROFL!! we've all been there one way or another! :D
Lucky for me, the BS had a two-day-old backup and lots of paper records, so they didn't sue - but I bet the secretary had no backup!
OMG... It's the worst feeling in the world when you slowly realise what just happened, and then you break out in a cold sweat that suddenly turns hot... :confused: :eek: :sick: :blush: :o :cry: :mad:
Learning is never done without errors and defeat...
V. Lenin
-
Re: Bagels(fermi,pico,bagels) code help
Hi can you please upload the correct code for the Bagels class! Thank you so muchhh