Jcreator Slot Machine Help!

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 693 Views - Last Post: 18 May 2014 - 02:20 PM Rate Topic: ***-- 2 Votes

#16 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:04 PM

View Postastonecipher, on 18 May 2014 - 01:02 PM, said:

How do you add a method to a class? How do you add any code to a class? How do you call a method?
These are things you are already doing in your code.


but it dosent seem to work?
Was This Post Helpful? 0
  • +
  • -

#17 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,493
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:10 PM

Show your current code. You would need to call the function 3 times .
Was This Post Helpful? 0
  • +
  • -

#18 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:13 PM

View Postastonecipher, on 18 May 2014 - 01:10 PM, said:

Show your current code. You would need to call the function 3 times .


import java.io.*; 
import java.util.*;
import java.util.Random;




public class k {
    

public class SlotMachine {
    //Generates 3 random numbers for slot machine
    public static void main(ArrayList<Integer> slotMachine) {
     
    int count = 0;
    while (count<3) 
     
    {
    Random slot = new Random();
    int slotNumber= slot.nextInt(10)+1;
    slotMachine.add(slotNumber);
    count+=1;
    }  
    return;
    }//End of slotNumbers method   
    //Determine points earned on slot machine
    public static int winnings(ArrayList<Integer> slotMachine)
    {
    int number1= slotMachine.get(0);
    int number2= slotMachine.get(1);
    int number3= slotMachine.get(2);
    int points;
     
    //if three 7's
    if (number1==7 && number2==7&& number3==7)
    {
    points=750;
    return points;
    }
     
    //if three matches
    if (number1==number2 && number1==number3 && number2==number3)
    {
      points=75;
      return points;
     
    }
     
    //if two matches
    if(number1==number2 || number1==number3 || number2==number3)
    {
       if(number1==7 && number2==7)
       {
        points=20;
        return points;
    }
     
    else if (number2==7 && number3==7)
    {
    points= 20;
    return points;
     
    }  
    }
    else
    {
    points = 5;
    return points;
    }
     
   }//End of winnings method   
    
   public static void main(String[] args) throws InterruptedException
   {
   int userPoints;
   int points;
   Scanner input = new Scanner(System.in);
    
   //Allow user to enter in points brought to play.
   System.out.println("Enter amount of playable points: ");
   userPoints = input.nextInt();
   input.nextLine();
    
   while (userPoints>0)
   {
      System.out.println("Spin? (Yes/No)");
      String answer = input.nextLine();
      if (answer.equalsIgnoreCase("Yes"))
      {
         userPoints-=1;//Take point for spin
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
          
         //Obtain random 3 numbers.

         slotNumber(slotMachine);

          

         //Obtain points earned.

         points=winnings(slotMachine);

         userPoints+=points;

        

         //Timing for slot numbers

         for(int i=0; i<3; i++)

         {

          

         System.out.print(slotMachine.get(i) + " ");

         } 

            

         //Display points won

         System.out.println("\nPoints won: " +points);

        System.out.println("Ponts left: " +userPoints);

       }   

    

       else if (answer.equalsIgnoreCase("No"))

       {

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

       System.out.println("Points left: " +userPoints);

       System.out.println("Thank you for playing.");

       break;

       }   

    

    

    

   }   

    

}  



Was This Post Helpful? 0
  • +
  • -

#19 mike73  Icon User is online

  • D.I.C Addict

Reputation: 141
  • View blog
  • Posts: 561
  • Joined: 24-April 10

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:20 PM

013    public static void main(ArrayList<Integer> slotMachine) {

Change this method name, it is a terrible choice of name and is just plain confusing.
Was This Post Helpful? 0
  • +
  • -

#20 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:22 PM

View Postmike73, on 18 May 2014 - 01:20 PM, said:

013    public static void main(ArrayList<Integer> slotMachine) {

Change this method name, it is a terrible choice of name and is just plain confusing.


to what name slotNumber?
Was This Post Helpful? 1
  • +
  • -

#21 mike73  Icon User is online

  • D.I.C Addict

Reputation: 141
  • View blog
  • Posts: 561
  • Joined: 24-April 10

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:24 PM

What does the method do? Your comments says: //Generates 3 random numbers for slot machine so why not name it as such? generateNumbers or generateThreeNumbers etc. When you name method, use a name that is useful and understandable to anyone reading your code.
Was This Post Helpful? 0
  • +
  • -

#22 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:27 PM

View Postmike73, on 18 May 2014 - 01:24 PM, said:

What does the method do? Your comments says: //Generates 3 random numbers for slot machine so why not name it as such? generateNumbers or generateThreeNumbers etc. When you name method, use a name that is useful and understandable to anyone reading your code.


import java.io.*;
002
import java.util.*;
003
import java.util.Random;
004
 
005
 
006
 
007
 
008
public class k {
009
     
010
 
011
public class SlotMachine {
012
    //Generates 3 random numbers for slot machine
013
    public static void main(slotMachine) {
014
      
015
    int count = 0;
016
    while (count<3)
017
      
018
    {
019
    Random slot = new Random();
020
    int slotNumber= slot.nextInt(10)+1;
021
    slotMachine.add(slotNumber);
022
    count+=1;
023
    } 
024
    return;
025
    }//End of slotNumbers method  
026
    //Determine points earned on slot machine
027
    public static int winnings(ArrayList<Integer> slotMachine)
028
    {
029
    int number1= slotMachine.get(0);
030
    int number2= slotMachine.get(1);
031
    int number3= slotMachine.get(2);
032
    int points;
033
      
034
    //if three 7's
035
    if (number1==7 && number2==7&& number3==7)
036
    {
037
    points=750;
038
    return points;
039
    }
040
      
041
    //if three matches
042
    if (number1==number2 && number1==number3 && number2==number3)
043
    {
044
      points=75;
045
      return points;
046
      
047
    }
048
      
049
    //if two matches
050
    if(number1==number2 || number1==number3 || number2==number3)
051
    {
052
       if(number1==7 && number2==7)
053
       {
054
        points=20;
055
        return points;
056
    }
057
      
058
    else if (number2==7 && number3==7)
059
    {
060
    points= 20;
061
    return points;
062
      
063
    } 
064
    }
065
    else
066
    {
067
    points = 5;
068
    return points;
069
    }
070
      
071
   }//End of winnings method  
072
     
073
   public static void main(String[] args) throws InterruptedException
074
   {
075
   int userPoints;
076
   int points;
077
   Scanner input = new Scanner(System.in);
078
     
079
   //Allow user to enter in points brought to play.
080
   System.out.println("Enter amount of playable points: ");
081
   userPoints = input.nextInt();
082
   input.nextLine();
083
     
084
   while (userPoints>0)
085
   {
086
      System.out.println("Spin? (Yes/No)");
087
      String answer = input.nextLine();
088
      if (answer.equalsIgnoreCase("Yes"))
089
      {
090
         userPoints-=1;//Take point for spin
091
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
092
           
093
         //Obtain random 3 numbers.
094
 
095
         slotNumber(slotMachine);
096
 
097
           
098
 
099
         //Obtain points earned.
100
 
101
         points=winnings(slotMachine);
102
 
103
         userPoints+=points;
104
 
105
         
106
 
107
         //Timing for slot numbers
108
 
109
         for(int i=0; i<3; i++)
110
 
111
         {
112
 
113
           
114
 
115
         System.out.print(slotMachine.get(i) + " ");
116
 
117
         }
118
 
119
             
120
 
121
         //Display points won
122
 
123
         System.out.println("\nPoints won: " +points);
124
 
125
        System.out.println("Ponts left: " +userPoints);
126
 
127
       }  
128
 
129
     
130
 
131
       else if (answer.equalsIgnoreCase("No"))
132
 
133
       {
134
 
135
       System.out.println("Thanks for playing!");
136
 
137
       System.out.println("Points left: " +userPoints);
138
 
139
       System.out.println("Thank you for playing.");
140
 
141
       break;
142
 
143
       }  
144
 
145
     
146
 
147
     
148
 
149
     
150
 
151
   }  
152
 
153
     
154
 
155
} 



good enough now? and thanks

srry for the nummbers
Was This Post Helpful? 1
  • +
  • -

#23 mike73  Icon User is online

  • D.I.C Addict

Reputation: 141
  • View blog
  • Posts: 561
  • Joined: 24-April 10

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:29 PM

025    public static void main(slotMachine) {
You didn't change the name of the method, just the parameters, which in itself is wrong and will give you a compiler error. The name of this method is currently "main", change it to what we agreed on in the last post, and change the parameter back to how it was.
Was This Post Helpful? 0
  • +
  • -

#24 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:29 PM

import java.io.*;
import java.util.*; 
import java.util.Random;
public class SlotMachine {
    //Generates 3 random numbers for slot machine
    public static void main(slotMachine) {
    
    int count = 0;
    while (count<3)	
    
    {
    Random slot = new Random();
    int slotNumber= slot.nextInt(10)+1;
    slotMachine.add(slotNumber);
    count+=1;
    }	
    return;	
    }//End of slotNumbers method	
    
    //Determine points earned on slot machine
    public static int winnings(ArrayList<Integer> slotMachine)
    {
    int number1= slotMachine.get(0);
    int number2= slotMachine.get(1);
    int number3= slotMachine.get(2);
    int points;
    
    //if three 7's
    if (number1==7 && number2==7&& number3==7)
    {
    points=750;
    return points;
    }
    
    //if three matches
    if (number1==number2 && number1==number3 && number2==number3)
    {
      points=75;
      return points;
    
    }
    
    //if two matches 
    if(number1==number2 || number1==number3 || number2==number3)
    {
       if(number1==7 && number2==7)
       {
       	points=20;
       	return points;
    }
    
    else if (number2==7 && number3==7)
    {
    points= 20;
    return points;
    
    }	
    }
    else
    {
    points = 5;
    return points;
    }
    
   }//End of winnings method	
   
   public static void main(String[] args) throws InterruptedException
   {
   int userPoints;
   int points;
   Scanner input = new Scanner(System.in);
   
   //Allow user to enter in points brought to play.
   System.out.println("Enter amount of playable points: ");
   userPoints = input.nextInt();
   input.nextLine();
   
   while (userPoints>0)
   {
      System.out.println("Spin? (Yes/No)");
      String answer = input.nextLine();
      if (answer.equalsIgnoreCase("Yes"))
      {
         userPoints-=1;//Take point for spin
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
         
         //Obtain random 3 numbers.
         slotNumber(slotMachine);
         
         //Obtain points earned.
         points=winnings(slotMachine);
         userPoints+=points;
         
         //Timing for slot numbers
         for(int i=0; i<3; i++)
         {
         
         System.out.print(slotMachine.get(i) + " ");
         }	
         	
         //Display points won
         System.out.println("\nPoints won: " +points);
         System.out.println("Ponts left: " +userPoints);
      	}	 
   
       else if (answer.equalsIgnoreCase("No"))
       {
       System.out.println("Thanks for playing!");
       System.out.println("Points left: " +userPoints);
       System.out.println("Thank you for playing.");
       break;
       }	
   
   
   
   }	
   
}	
   
   
    
}


Was This Post Helpful? 1
  • +
  • -

#25 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:36 PM

import java.io.*;
import java.util.*; 
import java.util.Random;
public class SlotMachine {
    //Generates 3 random numbers for slot machine
    public static void generateNumber(ArrayList<Integer> slotMachine) {
    
    int count = 0;
    while (count<3)	
    
    {
    Random slot = new Random();
    int slotNumber= slot.nextInt(10)+1;
    slotMachine.add(slotNumber);
    count+=1;
    }	
    return;	
    }//End of slotNumbers method	
    
    //Determine points earned on slot machine
    public static int winnings(ArrayList<Integer> slotMachine)
    {
    int number1= slotMachine.get(0);
    int number2= slotMachine.get(1);
    int number3= slotMachine.get(2);
    int points;
    
    //if three 7's
    if (number1==7 && number2==7&& number3==7)
    {
    points=750;
    return points;
    }
    
    //if three matches
    if (number1==number2 && number1==number3 && number2==number3)
    {
      points=75;
      return points;
    
    }
    
    //if two matches 
    if(number1==number2 || number1==number3 || number2==number3)
    {
       if(number1==7 && number2==7)
       {
       	points=20;
       	return points;
    }
    
    else if (number2==7 && number3==7)
    {
    points= 20;
    return points;
    
    }	
    }
    else
    {
    points = 5;
    return points;
    }
    
   }//End of winnings method	
   
   public static void main(String[] args) throws InterruptedException
   {
   int userPoints;
   int points;
   Scanner input = new Scanner(System.in);
   
   //Allow user to enter in points brought to play.
   System.out.println("Enter amount of playable points: ");
   userPoints = input.nextInt();
   input.nextLine();
   
   while (userPoints>0)
   {
      System.out.println("Spin? (Yes/No)");
      String answer = input.nextLine();
      if (answer.equalsIgnoreCase("Yes"))
      {
         userPoints-=1;//Take point for spin
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
         
         //Obtain random 3 numbers.
         slotNumber(slotMachine);
         
         //Obtain points earned.
         points=winnings(slotMachine);
         userPoints+=points;
         
         //Timing for slot numbers
         for(int i=0; i<3; i++)
         {
         
         System.out.print(slotMachine.get(i) + " ");
         }	
         	
         //Display points won
         System.out.println("\nPoints won: " +points);
         System.out.println("Ponts left: " +userPoints);
      	}	 
   
       else if (answer.equalsIgnoreCase("No"))
       {
       System.out.println("Thanks for playing!");
       System.out.println("Points left: " +userPoints);
       System.out.println("Thank you for playing.");
       break;
       }	
   
   
   
   }	
   
}	
   
   
    
}



Like this?
Was This Post Helpful? 1
  • +
  • -

#26 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,493
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:41 PM

I think you are quite confused at this point... Changing this might be helpful though,

Quote

017 return;


return slotMachine;


And this,

Quote

006 public static void generateNumber(ArrayList<Integer> slotMachine) {


public static ArrayList<Integer> slotNumber(ArrayList<Integer> slotMachine) {

Was This Post Helpful? 1
  • +
  • -

#27 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:42 PM

It says incompatible types
Was This Post Helpful? 1
  • +
  • -

#28 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,493
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:44 PM

On which line?
Was This Post Helpful? 0
  • +
  • -

#29 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:47 PM

its saying that it needs braces around the other Array<Integer>

View Postastonecipher, on 18 May 2014 - 01:44 PM, said:

On which line?


its also saying invalid method declaration. im not quitting till i solve this code
Was This Post Helpful? 1
  • +
  • -

#30 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:59 PM

View Postastonecipher, on 18 May 2014 - 01:41 PM, said:

I think you are quite confused at this point... Changing this might be helpful though,

Quote

017 return;


return slotMachine;


And this,

Quote

006 public static void generateNumber(ArrayList<Integer> slotMachine) {


public static ArrayList<Integer> slotNumber(ArrayList<Integer> slotMachine) {


Okay bro so i've done my work and only have 1 problem it says that i need a return value





import java.io.*;
import java.util.*; 
import java.util.Random;

public class l {
    
    
    
    
    //Generates 3 random numbers for slot machine
    public static ArrayList<Integer> slotNumber(ArrayList<Integer> slotMachine) {
    
    int count = 0;
    while (count<3)	
    
    {
    Random slot = new Random();
    int slotNumber= slot.nextInt(10)+1;
    slotMachine.add(slotNumber);
    count+=1;
    }	
    return slotMachine;	
    }//End of slotNumbers method	
    
    //Determine points earned on slot machine
    public static int winnings(ArrayList<Integer> slotMachine)
    {
    int number1= slotMachine.get(0);
    int number2= slotMachine.get(1);
    int number3= slotMachine.get(2);
    int points;
    
    //if three 7's
    if (number1==7 && number2==7&& number3==7)
    {
    points=750;
    return points;
    }
    
    //if three matches
    if (number1==number2 && number1==number3 && number2==number3)
    {
      points=75;
      return points;
    
    }
    
    //if two matches 
    if(number1==number2 || number1==number3 || number2==number3)
    {
       if(number1==7 && number2==7)
       {
       	points=20;
       	return points;
    }
    
    else if (number2==7 && number3==7)
    {
    points= 20;
    return points;
    
    }	
    }
    else
    {
    points = 5;
    return points;
    }
   
   }//End of winnings method	
   
   public static void main(String[] args) throws InterruptedException
   {
   int userPoints;
   int points;
   Scanner input = new Scanner(System.in);
   
   //Allow user to enter in points brought to play.
   System.out.println("Enter amount of playable points: ");
   userPoints = input.nextInt();
   input.nextLine();
   
   while (userPoints>0)
   {
      System.out.println("Spin? (Yes/No)");
      String answer = input.nextLine();
      if (answer.equalsIgnoreCase("Yes"))
      {
         userPoints-=1;//Take point for spin
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
         
         //Obtain random 3 numbers.
         slotNumber(slotMachine);
         
         //Obtain points earned.
         points=winnings(slotMachine);
         userPoints+=points;
         
         //Timing for slot numbers
         for(int i=0; i<3; i++)
         {
         
         System.out.print(slotMachine.get(i) + " ");
         }	
         	
         //Display points won
         System.out.println("\nPoints won: " +points);
         System.out.println("Ponts left: " +userPoints);
      	}	 
   
       else if (answer.equalsIgnoreCase("No"))
       {
       System.out.println("Thanks for playing!");
       System.out.println("Points left: " +userPoints);
       System.out.println("Thank you for playing.");
       break;
       }	
   
   
   
   }	
   
}	
   
   
    
}


it says that it there should be a return value at line 69
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3