CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Posts
    12

    I am Almost Done!

    Okay so I finished my Slot Machine Code! Well Almost! It works it is good and ya if you have any comments saying why didnt you put the numbers into arrays, well ya I never really understood that while I was making the actual game! O well! Atleast it works!

    Now all I am asking you guys is do you guys have any simple methods I can put into this program just to make it a bit better? A couple of methods are fine! And if you could also give me an example of the method! Other thaan that thanks so much for your hellp on this forum!

    Code:
    // import the java.util.Random class:
    import java.io.*;
    import java.util.Random;
    public class SlotMachine  
    {
      public static void main(String args[]) throws IOException{
        Random randomizer = new Random();
     
       ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
        String b; int bi=0;
    
       ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
         InputStreamReader input = new InputStreamReader(System.in);
       BufferedReader reader= new BufferedReader(input);
    
       // Make the player think that they have a high chance of winning, even if they don't!
       System.out.println("Welcome to *Saim's* Casino");
       System.out.println("Unfortunately we only have one machine available at this moment");
       System.out.println("Just because of the lack of variety in games, odds of winning this game are really good");   
       System.out.println("The game is called Saim's Slots");
       System.out.println("All you do is enter in $100 by simply typing in 100 when prompted");
       System.out.println("That will allow you to spin once!");
       System.out.println("Now you might be saying ***! It is so expensive");
       System.out.println("Well there are 53 different ways towin in this casino!");
       System.out.println("Basically you hav to do is make 2 pairs in a row!");
       System.out.println("For example : 2,2 & 3,3");
       System.out.println("If you get that you win money upto $10000");
       System.out.println("The prize money increases if you match another 2 pairs in a row");
       System.out.println("For example: Horizontally: 2,2 & 3,3 & Vertically  4,4 & 5,5");
       System.out.println("It can be in any order but you will definetly win the prize!");
       System.out.println("If you get all the numbers to match you win the Jackpot!");
       System.out.println("All this just for a $100");
       System.out.println("Unless you are feeling unlucky today, go ahead and make your self richer!");   
       System.out.println("So what are you waiting for? Luck is on your side!");   
       
        // Enter in the money
       System.out.println("Please enter in the $100 by typing in 100");
       b=reader.readLine();
       
        bi=Integer.parseInt(b);
       
       while (bi==100) {
         
       
       ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
       
       // Initialize variables in the actualy machine so they generate a random number between 0 and 7
       int ci = randomizer.nextInt(7);
       int di = randomizer.nextInt(7);
       int ei = randomizer.nextInt(7);
       int fi = randomizer.nextInt(7);
       int gi = randomizer.nextInt(7);
       int hi = randomizer.nextInt(7);
       int ii = randomizer.nextInt(7);
       int ji = randomizer.nextInt(7);
       int ki = randomizer.nextInt(7);
       int li = randomizer.nextInt(7);
       int mi = randomizer.nextInt(7);
       int ni = randomizer.nextInt(7);
       int oi = randomizer.nextInt(7);
       int pi = randomizer.nextInt(7);
       int qi = randomizer.nextInt(7);
       int ri = randomizer.nextInt(7);
       
       // Print out the actual slot machine numbers through the initialize variables!
       System.out.println(ci +"\t" + di+"\t" + ei+"\t" + fi);
       System.out.println(gi +"\t" + hi+"\t" + ii+"\t" + ji);
       System.out.println(ki +"\t" + li+"\t" + mi+"\t" + ni);
       System.out.println(oi +"\t" + pi+"\t" + qi+"\t" + ri);    
       
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
       // Put the money into arrays so it outputs upto $10000
       Random money = new Random();
    
      int[] x = new int[4];
      for (int m=0; m<x.length; m++)
      {
       x[m] = (money.nextInt(10000));
      }
    
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
      // If every number matches you win the Jackpot giving them the highest chance to win more money!
       if (((((ci==di)&&(di==ei))&&(ei==fi))&&(fi==ji))&&(ii==hi)&&(hi==gi)&&(gi==ki)&&(ki==li)&&(li==mi)&&(mi==ni)&&(oi==pi)&&(qi==ri)){
        System.out.println(" OMFG You won $" + x[0] + x[1] + x[2] + x[3] + x[4]);}      
       
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
       // If that dosen't work check if numbers match in the 1st row, diagonally starting from the 1st number on the 4th row, and the 3rd row!
       else if (((((ci==di)&&(ei==fi))&&(fi==ii))&&(li==oi))&&(ki==li)&&(mi==ni)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}      
      
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 4th row!
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(oi==pi)&&(qi==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}       
    
       // If that dosen't work check if numbers match in the 1st row, 2nd row and the 3rd row!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(oi==pi)&&(qi==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
    
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 4th row!   
       else if (((((ci==di)&&(ei==fi))&&(ki==li))&&(mi==ni))&&(oi==pi)&&(qi==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
     
       // If that dosen't work check if numbers match in the 1st column, 2nd column and the 3rd column!   
       else if (((((ci==gi)&&(ki==oi))&&(di==hi))&&(li==pi))&&(ei==ii)&&(mi==qi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
       
       // If that dosen't work check if numbers match in the 2nd column, 3rd column and the 4th column!   
       else if (((((di==hi)&&(li==pi))&&(ei==ii))&&(mi==qi))&&(fi==ji)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}       
      
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 4th row!   
       else if (((((ci==gi)&&(ki==oi))&&(di==hi))&&(li==pi))&&(fi==ii)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}   
      
       // If that dosen't work check if numbers match in the 1st column, 3rd column and the 4th column!   
       else if (((((ci==gi)&&(ki==oi))&&(ei==ii))&&(mi==qi))&&(fi==ji)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}       
      
       // If that dosen't work check if numbers match in the 1st row, 2nd row and diagonally starting from the first number!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(ci==hi)&&(mi==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
      
       // If that dosen't work check if numbers match in the 1st row, 2nd row and diagonally starting from the last number on the first row!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(fi==ii)&&(li==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
      
       // If that dosen't work check if numbers match in the 1st row, diagonally starting from the 1st number and diagonally starting from the last number on the first row!!   
       else if (((((ci==di)&&(ei==fi))&&(ci==hi))&&(mi==ri))&&(fi==ii)&&(li==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
      
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and diagonally starting from the first number!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(ci==hi)&&(mi==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}   
       
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 1st column!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(ci==gi)&&(ki==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}     
    
       // If that dosen't work check if numbers match in the 3rd row, 4th row and diagonally starting from the last number on the 1st row!!   
       else if (((((ki==li)&&(mi==ni))&&(oi==pi))&&(qi==ri))&&(fi==ii)&&(li==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}        
    
       // If that dosen't work check if numbers match in the 1st row, 2nd row and the 1st column!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(ci==gi)&&(ki==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
       
       // If that dosen't work check if numbers match in the 1st row, 2nd row and the 2nd column!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(di==hi)&&(li==pi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}        
       
       // If that dosen't work check if numbers match in the 1st row, 2nd row and the 3rd column!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(ei==ii)&&(mi==qi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
       
       // If that dosen't work check if numbers match in the 1st row, 2nd row and the 4th column!   
       else if (((((ci==di)&&(ei==fi))&&(gi==hi))&&(ii==ji))&&(fi==ji)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
    
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 1st column!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(ci==gi)&&(ki==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
    
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 2nd column!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(di==hi)&&(li==pi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}          
       
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 3rd column!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(ei==ii)&&(mi==qi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}         
       
       // If that dosen't work check if numbers match in the 2nd row, 3rd row and the 4th column!   
       else if (((((gi==hi)&&(ii==ji))&&(ki==li))&&(mi==ni))&&(fi==ji)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
    
       // If that dosen't work check if numbers match in the 1st row, 3rd row and the 1st column!   
       else if (((((ci==di)&&(ei==fi))&&(ki==li))&&(mi==ni))&&(ci==gi)&&(ki==oi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}  
      
       // If that dosen't work check if numbers match in the 1st row, 3rd row and the 2nd column!   
       else if (((((ci==di)&&(ei==fi))&&(ki==li))&&(mi==ni))&&(di==hi)&&(li==pi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}     
      
       // If that dosen't work check if numbers match in the 1st row, 3rd row and the 3rd column!   
       else if (((((ci==di)&&(ei==fi))&&(ki==li))&&(mi==ni))&&(ei==ii)&&(mi==qi)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}   
      
       // If that dosen't work check if numbers match in the 1st row, 3rd row and the 4th column!   
       else if (((((ci==di)&&(ei==fi))&&(ki==li))&&(mi==ni))&&(fi==ji)&&(ni==ri)){
        System.out.println("You won $" + x[0] + x[1] + x[2]);}     
    
    
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
       // If that dosen't work check if numbers match in the 1st column and diagonally starting from the last number on the first row!   
       else if (((((fi==ji)&&(ni==ri))&&(fi==ii))&&(li==oi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
    
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
       // If that dosen't work check if numbers match in the 3rd column and the 4th column!   
       else if (((((ei==ii)&&(mi==qi))&&(fi==ji))&&(ni==ri))){
        System.out.println("You won $" + x[0] + x[1]);}          
    
    
       // If that dosen't work check if numbers match in the 3rd column and diagonally starting from the last number on the 1st row!      
       else if (((((ei==ii)&&(mi==qi))&&(fi==ii))&&(li==oi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
       
    
       // If that dosen't work check if numbers match diagonally starting from the first number and the 2nd column!      
       else if (((((ci==hi)&&(mi==ri))&&(di==hi))&&(li==pi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match diagonally starting from the first number and the 3rd column!         
       else if (((((ci==hi)&&(mi==ri))&&(ei==ii))&&(mi==qi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match diagonally starting from the first number and the 4th column!         
       else if (((((ci==hi)&&(mi==ri))&&(fi==ji))&&(ni==ri))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match diagonally starting from the first number and diagonally starting from the last number on the 1st row!         
       else if (((((ci==hi)&&(mi==ri))&&(fi==ii))&&(li==oi))){
        System.out.println("You won $" + x[0] + x[1]);}       
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    
       // If that dosen't work check if numbers match in the 1st column and diagonally starting from the 1st number!         
       else if (((((ci==gi)&&(ki==oi))&&(ci==hi))&&(mi==ri))){
         System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match in the 1st column and the 2nd column!            
       else if (((((ci==gi)&&(ki==oi))&&(di==hi))&&(li==pi))){
        System.out.println("You won $" + x[0] + x[1]);}       
    
       // If that dosen't work check if numbers match in the 1st column and the 3rd column!         
       else if (((((ci==gi)&&(ki==oi))&&(ei==ii))&&(mi==qi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match in the 1st column and the 4th column!         
       else if (((((ci==gi)&&(ki==oi))&&(fi==ji))&&(ni==ri))){
        System.out.println("You won $" + x[0] + x[1]);}         
    
       // If that dosen't work check if numbers match in the 1st column and diagonally starting from the last number in the 1st row!         
       else if (((((ci==gi)&&(ki==oi))&&(fi==ii))&&(li==oi))){
        System.out.println("You won $" + x[0] + x[1]);}       
        
      
       /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
       
       // If that dosen't work check if numbers match in the 1st row and the 1st column!         
       else if (((((ci==di)&&(ei==fi))&&(ci==gi))&&(ki==oi))){
        System.out.println("You won $" + x[0] + x[1]);}     
     
       // If that dosen't work check if numbers match in the 1st row and diagonally starting from the 1st number!            
       else if (((((ci==di)&&(ei==fi))&&(ci==hi))&&(mi==ri))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match in the 1st row and the 2nd column!            
       else if (((((ci==di)&&(ei==fi))&&(di==hi))&&(li==pi))){
        System.out.println("You won $" + x[0] + x[1]);}     
    
       // If that dosen't work check if numbers match in the 1st row and the 3rd column!            
       else if (((((ci==di)&&(ei==fi))&&(ei==ii))&&(mi==qi))){
        System.out.println("You won $" + x[0] + x[1]);}       
    
       // If that dosen't work check if numbers match in the 1st row and the 4th column!            
       else if (((((ci==di)&&(ei==fi))&&(fi==ji))&&(ni==ri))){
        System.out.println("You won $" + x[0] + x[1]);}           
    
       // If that dosen't work check if numbers match in the 1st row and diagonally starting from the last number on the 1st row!            
       else if (((((ci==di)&&(ei==fi))&&(fi==ii))&&(li==oi))){
        System.out.println("You won $" + x[0] + x[1]);}      
       
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
     
       // If that dosen't work check if numbers match in the 1st row!          
       else if ((ci==di)&&(ei==fi)){
        System.out.println("You won $" +x[0]);}
    
       // If that dosen't work check if numbers match in the 1st column!        
       else if ((ci==gi)&&(ki==oi)){
        System.out.println("You won $" +x[0]);}
      
       // If that dosen't work check if numbers match diagonally starting from the 1st number!        
       else if ((ci==hi)&&(mi==ri)){
        System.out.println("You won $" +x[0]);}
    
       // If that dosen't work check if numbers match in the 2nd column!        
       else if ((di==hi)&&(li==pi)){
        System.out.println("You won $" +x[0]);}
            
       // If that dosen't work check if numbers match in the 3rd column!        
       else if ((ei==ii)&&(mi==qi)){
        System.out.println("You won $" +x[0]);}
               
       // If that dosen't work check if numbers match in the 4th column!        
       else if ((fi==ji)&&(ni==ri)){
        System.out.println("You won $" +x[0]);}
    
       // If that dosen't work check if numbers match diagonally starting from the last number on the 1st row!        
       else if ((fi==ii)&&(li==oi)){
        System.out.println("You won $" +x[0]);}   
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
    
       // If that dosen't work check if numbers match diagonally starting from the last number on the 1st row!        
       else { 
         System.out.println ("You are officialy the unluckiest person ever! Just leave and get yourself a 4 leaf clover and never come back! Hmph Bad Luck");}
       
       System.out.println("Please enter in 100 if you want to start over");
       b=reader.readLine();
       
        bi=Integer.parseInt(b);
       
         
       
       }
       if 
         (bi!=100
         )
        System.out.println("Loser Run Again and enter in 100! Ha you just lost your money to the machine! I don't care if you entered in 101 or 99 enter in 100");
      }
    }
    Thanks again!

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: I am Almost Done!

    Why ask for an initial number if it has to be $100, why not just say "Hit enter to bet $100"?

    As for making this better, the only way from here is to throw away all this code (maybe you could keep the opening print statements) and write it properly. If you don't understand my original suggestion to use arrays read up on arrays and ask sensible questions about what you don't understand and we'll explain it to you.

    If this was homework I'd set, I'm sorry but you wouldn't even get a bare pass mark.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jan 2011
    Posts
    12

    Re: I am Almost Done!

    Lol just when I thought I was getting better at Java! Lmao your such a ***** and thanks for telling me basically i fail!

  4. #4
    Join Date
    Jan 2011
    Location
    Tacoma, Washington
    Posts
    31

    Re: I am Almost Done!

    Now come on no need for getting so defensive. Keang was being blunt and honest. If you just want someone to pat you on the back then let your instructor do that with the grade. I suspect that if this is a 10th grade assignment the focus will be on the output only. If you want to earn respect from professional programmers (of which I am not yet myself) then you should be ready to take the most direct criticism and be willing implement all reasonable changes including the gut wrenching "Fail... start all over from a different angle."

    Ask yourself:

    What is the program required to do?
    Does it perform that task (or tasks) without any critical errors?

    If you can say your program does what the assignment says it was supposed to do I am sure you will get a passing mark. But, as Keang points out, your program definitely looks amateur. Which is fine. If you want to make this software "better" it does require a complete retooling. If you are seriously interested in programming I would turn this assignment in (assuming it does what is required) then forget about this one. Start reading anything and everything you can get your hands on that has to do with any programming language or design in general. Define some simple projects for yourself. Start small but start with correct programming practices in mind. Build on what you know and always challenge yourself. If you don't really want to get into programming then just enjoy the fact that you got a computer to bend to your will.

    Good luck.

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: I am Almost Done!

    Lol just when I thought I was getting better at Java! Lmao your such a ***** and thanks for telling me basically i fail!
    Look, I told you how to solve the problem on the 16th, you didn't bother to reply to my post and just ploughed on with what you were doing. If you had said you didn;t understand my suggestion, I or someone else would have explained further.

    I might be a ***** but I'm not so ignorant that when I ask for help I just ignore the advice I'm given and then insult the people trying to help me.

    And I didn't say you were going to fail I said if I had set the homework you would fail, your teacher may be more interested in just getting code that works than getting code that is properly designed. Personally I look for more that just "does it work", I prefer it when someone has made the effort to analyse the problem and produce a good design. In my opinion the implementation is only a part of the solution.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured