0

Im currently creating a program that works like a slot machine, the user writes "Spin" and then it generates some random numbers in the form of an array and then prints them off for the user to see. The problem is i can quite figure out how to print out the array so that it can be used later to find matches.
Here's the code so far:

public static int listofNums(int NUM_VALS)  {
    NUM_VALS=3;
    Random rn=new Random();
    int[] list=new int[NUM_VALS];
    int i=0;
    list[0]=rn.nextInt(10);
    list[1]=rn.nextInt(10);
    list[2]=rn.nextInt(10);

    for(i=0;i<NUM_VALS-1;i++){
        System.out.print(list[i]+" ");
    }
return list[i];
}
public static int addPoints(int numMatches){
    int score=50;
    numMatches=0;
    switch (numMatches) {
        case 1: numMatches=0;
            score=score-1;
            System.out.println("Sorry, you lost 1 point.");
            break;
        case 2: numMatches=2;
            score=score+5;
            System.out.println("You gained 5 points!");
            break;
        case 3: numMatches=3;
            score=score+20;
            System.out.println("You gained 20 points!");
        case 4: numMatches=4;
            score=score+750;
            System.out.println("Jackpot! You gained 750 points!");
    }
    return score;
}       

public static void main(String[] args) {
    final int NUM_VALS=3;
    int[] list=new int[listofNums(3)];
    int[] newList; 
    newList=list;
    boolean stop=false;
    String command;
    Scanner scnr=new Scanner(System.in);
    System.out.println("Welcome to high stakes slot!");
    System.out.println("Type 'Spin' to spin the wheel, type 'Stop' to see hoe much youve won!");

    while(!stop)    {
        command=scnr.next();
        if (command.equals("Spin"))     {
            System.out.println(newList[0]); }

And when i run the program, it prints out something like this:

Welcome to high stakes slot! Type 'Spin' to spin the wheel, type 'Stop' to see hoe much youve won! Spin 0 Spin 0

I don't know what I'm doing wrong, help will be greatly appreciated! Thank you so much.

Update: After looking over what was given to me to see if this was a duplicate, the difference between my problem and what was said in the other thread is: -Im using random numbers to generate my array, as well as, having to do so by makeing a reference to a method, ie, i cant just put a bracket in the back of the declared array. Or so i think.

Update: I have gotten rid of the printed out reference, but now it just prints out 0 when the user "Spins".

Mark Wilcoxen
  • 69
  • 1
  • 10

0 Answers0