I am somewhat new to Java still and have a lab that needs to simulate a lottery game that generates a number between 1-10. It first asks the user how many tickets do they want to purchase and then asks them if they want the computer to generate the guesses for them, if yes then it will generate the guesses and reveal the winning numbers. If the user says no, then the user will input the guesses themselves and will show the winning numbers.
I am having a problem figuring out how to do the code for when someone enters yes or no. Should I do a do while loop?
Here is what I have as code right now.
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double TICKET_PRICE = 2.00;
System.out.println("Welcome to the State of Florida Play10 Lottery Game. Ticket Price: $" + TICKET_PRICE);
System.out.println("How many tickets would you like to purchase?");
int ticketsPurchased = input.nextInt();
System.out.print("Please enter " + (ticketsPurchased) + " to confirm your credit carde charge: ");
int creditCardCharge = input.nextInt();
if (ticketsPurchased != creditCardCharge) {
System.out.println("Wrong number, please enter again: ");
return;
}
if (ticketsPurchased == creditCardCharge) {
System.out.println("Thank you. Your credit card will be charged $" + (ticketsPurchased * 2));
}
int min = 1;
int max = 10;
int winner;
winner = min + (int)(Math.random() * ((max - min) + 1));
System.out.print("Would you like the computer to generate your guesses? Enter 'Y' or 'N': ");
String computerGeneratedGuess = input.nextLine();
int guess = 0;
int winCtr = 0;
String output = "";
}
Here is the algorithm:
1. Get number of tickets to purchase,
calculate and confirm credit card charge.
2. Generate random winning integer and
either generate random guesses or prompt
user for guesses.
3. Report the winning number, the winning
tickets, total winnings, total losses, and
allowable deduction
Here is the lab its self:
Lab05 Lottery game
Generally a boolean is convenient to control a loop like this. Something like:
boolean gameOver = false;
int theGuess = 0;
while (!gameOver) {
if (computerGeneratedGuess == 'Y') {
theGuess = //code to generate a random number
}
else {
theGuess = //code to for user to enter a guess
}
if (theGuess == winner) {
gameOver = true;
}
Related
I am having a problem with my program. When I compile and run my program everything runs great until it's time to display the guesses back to the user. when that happens the last guess always gets displayed as 0.
My assignment is to develop a program that simulates the high-low game. For each execution of the program, the game will generate a random number in the inclusive range of 1 to 100. The user will have up to 10 chances to guess the value. The program will keep track of all the user’s guesses in an array. For each guess, the program will tell the user if his/her guess was too high or too low. If the user is successful, the program will stop asking for guesses, display the list of guesses, and show a congratulatory message stating how many guesses he/she took. If the user does not guess the correct answer within 10 tries, the program will display the list of guesses and show him/her the correct value with a message stating that he/she was not successful. Regardless of the outcome, the program will give the user a chance to run the program again with a new random number.
This is what I have so far:
import java.util.Random;
import java.util.Scanner;
/**
*
* #author jose
*/
public class Assignment7
{
/*
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int number;
String again = "y";
while (again.equalsIgnoreCase("y"))
{
int[] guesses = new int[10];
int tries = 0;
number = GetRandomNumber(1, 100);
System.out.println(number); // delete before submitting
int userGuess = GetUserGuess(1,100);
while (userGuess != number && tries < guesses.length - 1 )
{
guesses[tries] = userGuess;
LowOrHigh(number, userGuess);
userGuess = GetUserGuess(1, 100);
tries++;
}
if (tries != 10)
{
userGuess = guesses[tries];
tries++;
System.out.println("Congratulations! You were able to guess the correct number");
}
else
{
System.out.println("Sorry! You were not able to guess the correct number");
}
if (tries == 10)
{
System.out.println("Your guesses were incorrect");
System.out.print("You guessed: ");
for ( int i = 0; i < 10 ; i++)
{
System.out.print(guesses[i] + ", ");
}
System.out.println("The random number generated was " + number);
}
else
{
System.out.println("Well done! You were able to guess the "
+ "correct number in under 10 tries");
System.out.print("You guessed: ");
for ( int i = 0; i < tries; i++)
{
System.out.print(guesses[i] + " ");
}
System.out.println("The random number generated was "
+ number + ", it only took you " + tries + " tries.");
}
System.out.println("");
System.out.print("Do you wish to try again with a different "
+ "number? (Enter y or n ): ");
again = input.next();
System.out.println("");
}
}
/*
METHOD 1
Description
A method that generates the random number to be guessed returns the
random number to main. Two parameters are the two numbers needed to generate
the random number (1 and 100 in this case).
*/
public static int GetRandomNumber (int rangeLow, int rangeHigh)
{
Random gen = new Random();
int number;
number = gen.nextInt(rangeHigh) + rangeLow;
return number;
}
/*
METHOD 2
This method tells the user if the guess is too low or too high. It will have
2 parameters one for the random number and the second is the user guess.
*/
public static void LowOrHigh (int number, int userGuess )
{
if (userGuess > number )
{
System.out.println("The value that you guessed is too high, "
+"Try guessing a lower number. ");
System.out.println("");
}
else if (userGuess < number )
{
System.out.println("The value that you guessed is too low, "
+"Try guessing a higher number. ");
System.out.println("");
}
}
/*
METHOD 3
This method will get the user guess. It has 2 parameters which will be the
valid range the user should guess between (in this case 1 and 100). It will
return the users guess as an integer. This method should validate that the
users guess is between the two parameters.
*/
public static int GetUserGuess(int rangeLow, int rangeHigh)
{
Scanner scan = new Scanner(System.in);
int userGuess;
System.out.print("Enter a number between " + rangeLow + " and " + rangeHigh + ": ");
userGuess = scan.nextInt();
while (userGuess > rangeHigh || userGuess < rangeLow)
{
System.out.println("The number given was not within the range, Try again ");
System.out.println("");
System.out.print("Enter a number between " + rangeLow + " and " + rangeHigh + ": ");
userGuess = scan.nextInt();
}
return userGuess;
}
}
I'm sorry if its obvious im still pretty new to programming.
Whenever you store a guess, you always store it in guesses[tries], and then immediately afterwards, you increment tries. Your while condition then checks if tries is less than guess.length - 1.
More generally, to program you need to know how to debug. Debugging is generally the act of following along with the code and checking what it actually does vs. what you wanted it to do. You can use a debugger for this, alternatively, you can add a boatload of System.out statements to follow along.
Do that, and you'll find the error in your logic. I've already given you quite a sizable hint in the first paragraph ;)
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 5 years ago.
It looks like the Scanner is being used correctly here and being assigned to a variable correctly but I Cannot figure out what is going on. When I play this game in the code, the INT gets pulled in just fine. The strings will not get pulled in for some reason and even if I hardcode "yes" for the string it still exits the code.
package testTraining;
import java.util.Scanner;
public class GuessingGame {
static int gamesPlayed; // The number of games played.
static int gamesWon; // The number of games won.
public static void main(String[] args) {
gamesPlayed = 0;
gamesWon = 0; // This is actually redundant, since 0 is
// the default initial value.
System.out.println("Let's play a game. I'll pick a number between");
System.out.println("1 and 100, and you try to guess it.");
String yesno = "yes";
Scanner yesScan = new Scanner(System.in);
do {
playGame(); // call subroutine to play one game
System.out.print("Would you like to play again? ");
yesno = yesScan.next();
} while (yesno == "yes");
System.out.println();
System.out.println("You played " + gamesPlayed + " games,");
System.out.println("and you won " + gamesWon + " of those games.");
System.out.println("Thanks for playing. Goodbye.");
} // end of main()
static void playGame() {
Scanner guessScan = new Scanner(System.in);
int computersNumber; // A random number picked by the computer.
int usersGuess; // A number entered by user as a guess.
int guessCount; // Number of guesses the user has made.
gamesPlayed++; // Count this game.
computersNumber = (int)(100 * Math.random()) + 1;
// The value assigned to computersNumber is a randomly
// chosen integer between 1 and 100, inclusive.
guessCount = 0;
System.out.println();
System.out.print("What is your first guess? ");
while (true) {
usersGuess = guessScan.nextInt(); // Get the user's guess.
guessCount++;
if (usersGuess == computersNumber) {
System.out.println("You got it in " + guessCount
+ " guesses! My number was " + computersNumber);
gamesWon++; // Count this win.
break; // The game is over; the user has won.
}
if (guessCount == 6) {
System.out.println("You didn't get the number in 6 guesses.");
System.out.println("You lose. My number was " + computersNumber);
break; // The game is over; the user has lost.
}
// If we get to this point, the game continues.
// Tell the user if the guess was too high or too low.
if (usersGuess < computersNumber)
System.out.print("That's too low. Try again: ");
else if (usersGuess > computersNumber)
System.out.print("That's too high. Try again: ");
}
System.out.println();
} // end of playGame()
} // end of class GuessingGame
You need to compare strings with .equals("yes") instead of == "yes"
I am working on this project from the Java Programming book by Joyce Farrell, and I am having an issue with the Randomly Generated number and the user's guesses not being checked correctly. For example the user has 3 guesses, lets say their first guess it 2 and the first randomly generated number is 2 the program will print out You lose. When the guess is actually correct. Please help me. I have added the details of the program plus what I have done so far.
Create a lottery game application. Generate three random numbers (see Appendix D for help in
doing so), each between 0 and 9. Allow the user to guess three numbers. Compare each of the
user's guesses to the three random numbers and display a message that includes the user's
guess, the randomly determined three-digit number, and the amount of money the user has
won as follows.
Matching Numbers Award($)
Any one matching 10
Two matching 100
Three matching, not in order 1000
Three matching, in exact order 1,000,000
No match 0
Make certain that your application accommodates repeating digits. For example, if a user
guesses 1, 2, and 3, and the randomly generated digits are 1, 1, and 1, do not give the user
credit for three correct guesses - just one. Save the file as Lottery.
My Source Code
// Filename: Lottery.java
// Written by: Andy A
// Written on: 14 January 2015
import java.util.Scanner;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Random ranNum = new Random();
// LIMIT Contains The Numbers From 0 - 9
// TIMES Contains The Number of Time ranNum Should Run
final int LIMIT = 9;
final int TIMES = 3;
// Users Guesses
int usersFirstGuess;
int usersSecondGuess;
int usersThirdGuess;
// Randomly Generated Numbers
final int GenFirst = ranNum.nextInt(LIMIT);
final int GenSecond = ranNum.nextInt(LIMIT);
final int GenThird = ranNum.nextInt(LIMIT);
// User is asked for 3 guesses
System.out.println("Please enter your first guess: ");
usersFirstGuess = userInput.nextInt();
System.out.println("Please enter your second guess: ");
usersSecondGuess = userInput.nextInt();
System.out.println("Please enter your third and final guess: ");
usersThirdGuess = userInput.nextInt();
// Winning Amounts
final double WinTen = 10;
final double WinHun = 100;
final double WinThund = 1000;
final double WinMillion = 1000000;
final int WinZero = 0;
// Shows the randomly generated numbers
for(int x = 0; x < TIMES; ++x)
System.out.print(ranNum.nextInt(LIMIT) + " ");
System.out.println();
// First Generated
if(GenFirst == usersFirstGuess ) {
System.out.println("You have won: $" + WinTen);
}
else if(GenSecond == usersSecondGuess) {
System.out.println("You have won: $" + WinTen);
}
else if(GenThird == usersThirdGuess) {
System.out.println("You have won: $" + WinTen);
}
}
}
You are printing newly generated numbers with ranNum.nextInt(LIMIT), however you are comparing the user input with the numbers stored in the GenXXX variables.
Solution: Print the variables instead.
System.out.println(GenFirst + " " + GenSecond + " " + GenThird);
If you still want to use a loop for printing you can store the numbers in an array.
// generate
final int[] generated = new int[TIMES];
for (int x = 0; x < TIMES; x++)
generated[x] = ranNum.nextInt(LIMIT);
// print
for (int x = 0; x < TIMES; x++)
System.out.print(generated[x] + " ");
This should do the trick.
// Filename: Lottery.java
// Written by: Andy A
// Written on: 14 January 2015
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Random ranNum = new Random();
// LIMIT Contains The Numbers From 0 - 9
// TIMES Contains The Number of Time ranNum Should Run
final int LIMIT = 9;
final int TIMES = 3;
// Users Guesses
int usersFirstGuess;
int usersSecondGuess;
int usersThirdGuess;
List<Integer> guesses = new ArrayList<>();
// Randomly Generated Numbers
final int GenFirst = ranNum.nextInt(LIMIT);
final int GenSecond = ranNum.nextInt(LIMIT);
final int GenThird = ranNum.nextInt(LIMIT);
// User is asked for 3 guesses
System.out.println("Please enter your first guess: ");
usersFirstGuess = userInput.nextInt();
guesses.add(usersFirstGuess);
System.out.println("Please enter your second guess: ");
usersSecondGuess = userInput.nextInt();
guesses.add(usersSecondGuess);
System.out.println("Please enter your third and final guess: ");
usersThirdGuess = userInput.nextInt();
guesses.add(usersThirdGuess);
// Winning Amounts
final double WinTen = 10;
final double WinHun = 100;
final double WinThund = 1000;
final double WinMillion = 1000000;
final int WinZero = 0;
// Shows the randomly generated numbers
System.out.println(GenFirst + " " + GenSecond + " " + GenThird);
List<Integer> lottery = new ArrayList<>();
lottery.add(GenFirst);
lottery.add(GenSecond);
lottery.add(GenThird);
if (guesses.equals(lottery)) {
System.out.println("You have won: $" + WinMillion);
} else {
int matchCount = 0;
for (Integer guessValue : guesses) {
if (lottery.contains(guessValue)) {
matchCount++;
lottery.remove(guessValue);
}
}
switch (matchCount) {
case 0:
System.out.println("You have won: $" + WinZero);
break;
case 1:
System.out.println("You have won: $" + WinTen);
break;
case 2:
System.out.println("You have won: $" + WinHun);
break;
case 3:
System.out.println("You have won: $" + WinThund);
break;
}
}
}
}
Exactly,
why are you printing
System.out.print(ranNum.nextInt(LIMIT) + " ");
when you should be just printing
System.out.print(GenThird + " ");
System.out.print(GenSecond + " ");
System.out.print(GenFirst + " ");
This is not the problem of the randomly generated numbers, but if your way of showing them to the user.
Before your if / else if statements, in the for-loop you are generating new random numbers. That means, the number compared to the users input (genFirst) can be 3, but the number shown to the user in the for loop is a new random number, for example 2.
To fix this problem, you should display the generated numbers like that:
for (int ranInt : new int[] { GenFirst, GenSecond, GenThird}) {
System.out.println(ranInt);
}
This piece of code creates an array of the generated numbers and loops through them printing them. Obviously, you can also print GenFirst, then print GenSecond and then print GenThird.
I hope this helps!
Maybe this will help!
import java.util.Scanner;
import java.util.Random;
public class Qellonumrat {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Random rand=new Random();
int random_integer=(int) rand.nextInt(10);
System.out.println("Guess the number: ");
int number=sc.nextInt();
while(true){
if(number == random_integer){
random_integer++;
System.out.println("Congrats you won!!!");
break;
}
else{
System.out.println("Try again");
break;
}
}
}
}
I'm writing a program used to calculate the total sales of employees in a small business, and am trying to figure out how to restart the program based on a user input of y/n. I know that loops are what I need to use here, but need a push in the right direction.
Code:
import java.util.Scanner;
public class calcMain {
public static void main(String[]args){
double totalPay = 0, itemOne = 239.99, itemTwo = 129.75, itemThree = 99.95, itemFour = 350.89, commission;
int weeklyBonus = 200, numSold;
String employee1, employee2, employee3, employee4, yn;
Scanner kb = new Scanner(System.in);
System.out.println("Please enter the salesperson's name: ");
employee1 = kb.nextLine();
System.out.println("Please enter the number of Item 1 sold: ");
numSold = kb.nextInt();
totalPay += (itemOne * numSold);
System.out.println("Please enter the number of Item 2 sold: ");
numSold = kb.nextInt();
totalPay += (itemTwo * numSold);
System.out.println("Please enter the number of item 3 sold: ");
numSold = kb.nextInt();
totalPay += (itemThree * numSold);
System.out.println("Please enter the number of item 4 sold: ");
numSold = kb.nextInt();
totalPay += (itemFour * numSold);
System.out.println("The total weekly earnings for " +employee1+ " are: " +totalPay);
System.out.println("Would you like to input the sales of another employee? (y/n)");
yn = kb.next();
}
}
Put all the code inside a while loop that says while (yn.equalsIgnoreCase("y"))
Don't forget to initialize yn to y!
Second solution:
Modify the code so that it returns a string, and if the user inputs y, return y, or if the user inputs n, return n.
Put all that code inside a method (lets call it method x for now)
public static void main(String[] args) {
while(x().equalsIgnoreCase("y")){}
}
Using a do-while loop (while loop should have the same effect) and ask for (y/n) at the end.
Like this:
String yn;
do
{
// Your code here
// Ask for confirmation
}
while (yn.equals("y"));
I am supposed to write a program that selects a random number between user given constraints, and asks the user to input guesses as to what this number is. The program gives feedback to the user as to whether or not the number is higher or lower than the user's guesses. The number of guesses, the number of games, the total guesses used throughout all of the games, and the lowest number of guesses used in one game are recorded.
These results are printed. The functions that responsible for running the game (playGame()) and the functions responsible for printing these results (getGameResults()) must be in two separate methods.
My problem is, I am not sure how to get the local variables that are modified throughout the course of the method playGame() to the getGameResults() method.
getGameResults() is intended to be called in another method, continuePlayTest(), which tests the user's input to determine whether or not they wish to continue playing the game, so I don't think that calling getGameResults() will work, otherwise this test will not work either. Unless I call continuePlayTest() in playGame(), but continuePlayTest() calls playGame() in its code so that would complicate things.
We can use ONLY the concepts that we've learned. We cannot use any concepts ahead.
So far, we've learned how to use static methods, for loops, while loops, if/else statements and variables. Global variables are bad style, so they cannot be used.
CODE:
public class Guess {
public static int MAXIMUM = 100;
public static void main(String[] args) {
boolean whileTest = false;
gameIntroduction();
Scanner console = new Scanner(System.in);
playGame(console);
}
// Prints the instructions for the game.
public static void gameIntroduction() {
System.out.println("This process allows you to play a guessing game.");
System.out.println("I will think of a number between 1 and");
System.out.println(MAXIMUM + " and will allow you to guess until");
System.out.println("you get it. For each guess, I will tell you");
System.out.println("whether the right answer is higher or lower");
System.out.println("than your guess.");
System.out.println();
}
//Takes the user's input and compares it to a randomly selected number.
public static void playGame(Scanner console) {
int guesses = 0;
boolean playTest = false;
boolean gameTest = false;
int lastGameGuesses = guesses;
int numberGuess = 0;
int totalGuesses = 0;
int bestGame = 0;
int games = 0;
guesses = 0;
games++;
System.out.println("I'm thinking of a number between 1 and " + MAXIMUM + "...");
Random number = new Random();
int randomNumber = number.nextInt(MAXIMUM) + 1;
while (!(gameTest)){
System.out.print("Your guess? ");
numberGuess = console.nextInt();
guesses++;
if (randomNumber < numberGuess){
System.out.println("It's lower.");
} else if (randomNumber > numberGuess){
System.out.println("It's higher.");
} else {
gameTest = true;
}
bestGame = guesses;
if (guesses < lastGameGuesses) {
bestGame = guesses;
}
}
System.out.println("You got it right in " + guesses + " guesses");
totalGuesses += guesses;
continueTest(playTest, console, games, totalGuesses, guesses, bestGame);
}
public static void continueTest(boolean test, Scanner console, int games, int totalGuesses, int guesses, int bestGame) {
while (!(test)){
System.out.print("Do you want to play again? ");
String inputTest = (console.next()).toUpperCase();
if (inputTest.contains("Y")){
playGame(console);
} else if (inputTest.contains("N")){
test = true;
}
}
getGameResults(games, totalGuesses, guesses, bestGame);
}
// Prints the results of the game, in terms of the total number
// of games, total guesses, average guesses per game and best game.
public static void getGameResults(int games, int totalGuesses, int guesses, int bestGame) {
System.out.println("Overall results:");
System.out.println("\ttotal games = " + games);
System.out.println("\ttotal guesses = " + totalGuesses);
System.out.println("\tguesses/games = " + ((double)Math.round(guesses/games) * 100)/100);
System.out.println("\tbest game = " + bestGame);
}
}
If you cannot use "global" variables, I guess your only option is passing parameters when calling the method. If you don't know how to declare and use methods with parameters, I don't know another answer.
EDIT/ADD
After you specified your question, circumstances and posted your code I got a working solution including comments.
public class Guess {
public static int MAXIMUM = 100;
public static void main(String[] args) {
boolean play = true; // true while we want to play, gets false when we quit
int totalGuesses = 0; // how many guesses at all
int bestGame = Integer.MAX_VALUE; // the best games gets the maximum value. so every game would be better than this
int totalGames = 0; // how many games played in total
Scanner console = new Scanner(System.in); // our scanner which we pass
gameIntroduction(); // show the instructions
while (play) { // while we want to play
int lastGame = playGame(console); // run playGame(console) which returns the guesses needed in that round
totalGames++; // We played a game, so we increase our counter
if (lastGame < bestGame) bestGame = lastGame; // if we needed less guesses last round than in our best game we have a new bestgame
totalGuesses += lastGame; // our last guesses are added to totalGuesses (totalGuesses += lastGame equals totalGuesses + totalGuesses + lastGame)
play = checkPlayNextGame(console); // play saves if we want to play another round or not, whats "calculated" and returned by checkPlayNextGame(console)
}
getGameResults(totalGames, totalGuesses, bestGame); // print our final results when we are done
}
// Prints the instructions for the game.
public static void gameIntroduction() {
System.out.println("This process allows you to play a guessing game.");
System.out.println("I will think of a number between 1 and");
System.out.println(MAXIMUM + " and will allow you to guess until");
System.out.println("you get it. For each guess, I will tell you");
System.out.println("whether the right answer is higher or lower");
System.out.println("than your guess.");
System.out.println();
}
// Takes the user's input and compares it to a randomly selected number.
public static int playGame(Scanner console) {
int guesses = 0; // how many guesses we needed
int guess = 0; // make it zero, so it cant be automatic correct
System.out.println("I'm thinking of a number between 1 and " + MAXIMUM + "...");
int randomNumber = (int) (Math.random() * MAXIMUM + 1); // make our random number. we don't need the Random class with its object for that task
while (guess != randomNumber) { // while the guess isnt the random number we ask for new guesses
System.out.print("Your guess? ");
guess = console.nextInt(); // read the guess
guesses++; // increase guesses
// check if the guess is lower or higher than the number
if (randomNumber < guess)
System.out.println("It's lower.");
else if (randomNumber > guess)
System.out.println("It's higher.");
}
System.out.println("You got it right in " + guesses + " guesses"); // Say how much guesses we needed
return guesses; // this round is over, we return the number of guesses needed
}
public static boolean checkPlayNextGame(Scanner console) {
// check if we want to play another round
System.out.print("Do you want to play again? ");
String input = (console.next()).toUpperCase(); // read the input
if (input.contains("Y")) return true; // if the input contains Y return true: we want play another round (hint: don't use contains. use equals("yes") for example)
else return false; // otherwise return false: we finished and dont want to play another round
}
// Prints the results of the game, in terms of the total number
// of games, total guesses, average guesses per game and best game.
public static void getGameResults(int totalGames, int totalGuesses, int bestGame) {
// here you passed the total guesses twice. that isnt necessary.
System.out.println("Overall results:");
System.out.println("\ttotal games = " + totalGames);
System.out.println("\ttotal guesses = " + totalGuesses);
System.out.println("\tguesses/games = " + ((double) (totalGuesses) / (double) (totalGames))); // cast the numbers to double to get a double result. not the best way, but it works :D
System.out.println("\tbest game = " + bestGame);
}
}
Hope I could help.
Is it a problem passing the variables between functions? ex:
public static void getGameResults(int games, int totalGuesses, int guesses, int bestGame) {
// implementation
}
Another option, assuming this is all in one class, is using private static memeber variables. They aren't global. Then again, they might be considered 'global' by your teacher for this assignment.
Given that you've only learnt how to use static methods, your only option is to pass the information from function to function via its arguments.