James Swanson

Greenhorn
+ Follow
since Oct 17, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Swanson

ok this is what i have so far.....

import java.util.*;


public class thelotto{


public static void main (String[] args){

boolean done = false;
boolean win = true;
boolean playagain = true;
int rand1, rand2, rand3, rand4, yours1, yours2, yours3, yours4;
Random numberGenerator = new Random();
Scanner scan = new Scanner(System.in);

String playmessage = "Would l you like to play the lotto? (y / n)";
String youlost = "Sorry you did not win, buy another ticket?";
String youwin = "you won the lotto, go quit your job!!!";





System.out.print(playmessage);
if (scan.next().equals("n"))
playagain = false;
else
done = false;


rand1 = numberGenerator.nextInt(9);
rand2 = numberGenerator.nextInt(9);
rand3 = numberGenerator.nextInt(9);
rand4 = numberGenerator.nextInt(9);


yours1 = numberGenerator.nextInt(9);
yours2 = numberGenerator.nextInt(9);
yours3 = numberGenerator.nextInt(9);
yours4 = numberGenerator.nextInt(9);




System.out.println ("The winning Lotto numbers are: " + rand1 + rand2 + rand3 + rand4);
System.out.println ("Your numbers cam up: " + yours1 + yours2 + yours3 + yours4);



if (rand1 != yours1)
done = false;
else if (rand2 != yours2)
done = false;
else if (rand3 != yours3)
done = false;
else if (rand4 != yours4)
done = false;
else
win = true;
}
}

can anyone tell me what i have done wrong with my loop?
i would like the numbers to regenerate until a win
however all i get is the first round displayed with no loop....
thanks for all that have replied so far
19 years ago
for now I plan to regenerate player and draw numbers each time so its like a new game every time. However once I get that to work I am going to try adding switches.


my code looks like this so far

import java.util.*;


public class newprogram{


public static void main (String[] args){

boolean done = false;
boolean playagain = true;
int rand1, rand2, rand3, rand4, yours1, yours2, yours3, yours4;
Random numberGenerator = new Random();
Scanner scan = new Scanner(System.in);

final String playmessage = "Would l you like to play the lotto? (y / n)";
final String youlost = "Sorry you did not win, buy another ticket?";
final String youwin = "you won the lotto, go quit your job!!!";


System.out.println(playmessage);
if (scan.next().equals("n"))
playagain = false;
else
done = false;


rand1 = numberGenerator.nextInt(9);
rand2 = numberGenerator.nextInt(9);
rand3 = numberGenerator.nextInt(9);
rand4 = numberGenerator.nextInt(9);


yours1 = numberGenerator.nextInt(9);
yours2 = numberGenerator.nextInt(9);
yours3 = numberGenerator.nextInt(9);
yours4 = numberGenerator.nextInt(9);


System.out.println ("The winning Lotto numbers are: " + rand1 +rand2 + rand3 + rand4);
System.out.println ("Your numbers cam up: " + yours1 + yours2 + yours3 + yours4);


while (playagain){
if (rand1 == yours1)
done = true;
else if (rand2 == yours2)
done = true;
else if (rand3 == yours3)
done = true;
else if (rand4 == yours4)
done = true;
else
done = false;
}
while (done = false)
System.out.println(youlost);







}
}

what I plan on doing is just make both generators to draw until the numbers match.
and sorry for the lack of info, however I do plan on doing this myself, i am just so new that i think I need to be pointed in a new direction.
also I have never done a for loop and don't understand it very well thats why I am asking.....not to get someone else to do work for me, sorry if I came across that way.

thank you for your reply
19 years ago
OK I am just learning java, and i have a project that is supposed to simulate a lotto game ( like megabucks/powerball or something) right now i am using to different sets of four random number generators and i want to use a for loop to make it play in circles until the plater wins.

rand1 = numberGenerator.nextInt(9);
rand2 = numberGenerator.nextInt(9);
rand3 = numberGenerator.nextInt(9);
rand4 = numberGenerator.nextInt(9);

yours1 = numberGenerator.nextInt(9);
yours2 = numberGenerator.nextInt(9);
yours3 = numberGenerator.nextInt(9);
yours4 = numberGenerator.nextInt(9);

are my generators.....the rand1,2,3,4 are the winning numbers and the yours are the user or players numbers,i don't want the game to end until they match (like the lottorey) if anyone could help it would be great...
if not a for loop any other sugestions are also welcome.

thanks
19 years ago
so sorry..

it should say first

Enter your guess<-1 to quit>:

from there I would like it to say

Sorry, the number you entered is higher than my number.
--back to "Enter guess"
(or)

Sorry, but the number I entered is lower than my number
--back to "Enter guess"
(or)

Congratulations! You guessed my number!
--then to "play again?"

is that what you meant?

i works until the first number is higher or lower but I can't keep the loop going
19 years ago
sorry.....

import java.util.Random;
import java.util.Scanner;

public class HiLoGame{

public static void main(String[] args) {
boolean done = false;
boolean playAgain = true;
Random numberGenerator = new Random();
int randomNumber, numberOfGuesses, userNumber;
Scanner scan = new Scanner(System.in);


final String guessMessage = "Enter your guess (-1 to quit): ";
final String tooHigh = "Sorry, the number you entered is higher than my number.";
final String tooLow = "Sorry, the number you entered is lower than my number.";
final String justRight = "Congratulations! You guessed my number!";
final String playAgainMessage = "Play again?";

while (playAgain) {

randomNumber = numberGenerator.nextInt(10) + 1;


System.out.print(guessMessage);
userNumber = scan.nextInt();
numberOfGuesses = 1;
if (userNumber < randomNumber)
done = false;

else if (userNumber < randomNumber)
System.out.print(tooLow);
else
done = true;

if (userNumber > randomNumber)
done = false;

else if (userNumber > randomNumber)
System.out.print(tooHigh);
else
done = true;





while (userNumber < randomNumber)
done = false;

while (userNumber > randomNumber)
done = false;


while (userNumber == -1)
done = true;


while (userNumber == randomNumber)
done = true;



System.out.print("Would you like to play again? (y/n)? ");
if (scan.next().equals("n"))
playAgain = false;
else
done = false;
}

System.out.println("Thanks for playing! Bye!");

}

}

is that better
19 years ago
um one more thing?

i am trying to make a nested if staement that will return to a scanner...

it looks like this ( ihave tested different ways and can't find my answer on the web)

System.out.print(guessMessage);
userNumber = scan.nextInt();
numberOfGuesses = 1;
if (userNumber < randomNumber)
System.out.print(tooLow);
else if (userNumber < randomNumber)
done = false;
else
done = true;

if (userNumber > randomNumber)
System.out.print(tooLow);;

else if (userNumber > randomNumber)
deon = false;
else
done = true;

what exactly am I doing wrong? it will print my message but not return..
i just stops if I reverse if and else if statements

thank you for any help
19 years ago
tahk you again you are the best!
19 years ago
awsome thak you sooo much!!!

that seemed too easy for me to miss- lol

although i can't get any spaces between my ints and characters

can ya tell me about that?

heres what it looks like now

//
//James Swanson
//ssd-101 intro to Java
//prof. Hufe
//mondays 530
//
//
//99 bottles of beer on the wall
//



public class ninetyninebottlesofbeer {

static int count = 99;
static int range = count - 1;




public static void main(String [] Args) {




while (count >= 1) {

System.out.println (+ count + "Bottles of beer on the wall" + count + "bottles of beer!");
System.out.println ("you take one down and pass it around" + range + "bottles of beer on the wall");
count--;
range--;

}

}
}

also if you know of any other site that can help(not that I don't love this place enough) that would be a great help too

thank you so much again
19 years ago
ok i have just started learning java and i have to make a loop to make the song "play through" so to speak

hear is what I have so far

its not doing what want it to, but it is doing what i told it too lol

can anybody please help?

thank you

public class ninetyninebottlesofbeer {

static int count = 99;
static int range = 1;
static int beer = count - range;



public static void main(String [] Args) {



beer = count - range;

while (count >= 1);{

System.out.println (+ count + "Bottles of beer on the wall" + count + "bottles of beer!");
System.out.println ("you take one down and pass it around" + range + "bottles of beer on the wall");

count++;

}

}
}
19 years ago