Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Slot Machine game in Java. using Net Beans.

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Slot Machine game in Java. using Net Beans.

    Here is my code!! Please Help!!!!!!!!!!!!!! i have to turn in the assignment on Monday!!
    MAIN:

    package game;
    import javax.swing.JOptionPane;
    public class Game {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            JOptionPane.showMessageDialog(null,"********Welcome to The Slot Machine Game!********");
     
            String name = JOptionPane.showInputDialog("Please enter your name");
     
            double money;
            money = Double.parseDouble(JOptionPane.showInputDialog("How much money do you have?"));
            double currentBalance = money;
            int coins = (int)(money/0.25);
            int coinsBet = Integer.parseInt(JOptionPane.showInputDialog("How many coins do you want to bet? (0-4)"));
     
            if(coins == 0 || coins > 4){
                JOptionPane.showMessageDialog(null, "Hello " +name + "," + "your current balance is " +currentBalance +"\n"
                        + "You bet " + coinsBet + "coin(s)" +"\nBye-Bye!");}
     
                while(coins!=0){
                currentBalance= currentBalance-(coins*0.25);
                JOptionPane.showMessageDialog(null, name +", your current balance is " +currentBalance );
                JOptionPane.showInputDialog("how many coins do u wanna bet?");
            }
        }
    }
     
     
     
    package game;
    import game.SlotMachine;
    /**
     *
     * @author Syeda
     */
    public class PullResult {
        private String column1;
        private String column2;
        private String column3;
     
        public PullResult(String column1, String column2, String column3){
     
        }
     
        public String getColumn1(){
            return column1;}
     
        public String getColumn2(){
            return column2;}
     
        public String getColumn3(){
            return column3;}
     
        public int getPayoff(){
            return getPayoff(this.column1,this.column2,this.column3);
        }
     
        public static int getPayoff(String column1, String column2, String column3){
        int payoff;
        int result = 9;
     
        if (column1.equals("BELL") && column2.equals("BELL") && column3.equals("BELL")) {
            result = 0;
        } else if (column1.equals("GRAPE") && column2.equals("GRAPE") && column3.equals("GRAPE")) {
            result = 1;
            } else if (column1.equals("CHERRY") && column2.equals("CHERRY") && column3.equals("CHERRY")) {
            result = 2;
            } else if (column1.equals("CHERRY") && column2.equals("CHERRY")) {
            result = 3;
            } else if (column1.equals("CHERRY") && column3.equals("CHERRY")) {
            result = 4;
            } else if (column2.equals("CHERRY") && column3.equals("CHERRY")) {
            result = 5;
            } else if (column1.equals("CHERRY")) {
            result = 6;
            } else if (column2.equals("BELL")) {
            result = 7;
            } else if (column3.equals("BELL")) {
            result = 8; }
     
        switch (result) {
        case 0:
             payoff = 8;
                 break;
        case 1:
             payoff = 5;
                 break;
        case 2:
             payoff = 4;
                 break;
        case 3:
        case 4:
        case 5: 
             payoff = 2;
                 break;
        case 6:
        case 7:
        case 8: 
             payoff = 1;
                 break;      
        default:
            payoff = 0;
        }
     
        return payoff;
        }
    }
     
    package game;
     
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
     
     
    public class SlotMachine {
     
        public static PullResult getPullResult(){
        List<String> list = new ArrayList<String>();        
            list.add("BELL");
            list.add("GRAPE");
            list.add("CHERRY"); 
     
            Random rg = new Random();
            int size = list.size();
     
        String column1 = list.get(rg.nextInt(size));
        String column2 = list.get(rg.nextInt(size));
        String column3 = list.get(rg.nextInt(size));
     
        return new PullResult(column1, column2, column3);
     
        }
      }

    it is not showing the result from PullResult class
    Last edited by leo24; October 26th, 2012 at 03:57 PM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Slot Machine game in Java. using Net Beans.

    Please see the announcements page for tips on forum use. Then see if you can fix the posted code with tags, and try to explain what the problem is and where you are stuck.

    Speaking of stuck, get that keyboard checked out. It looks like one of the keys has a problem. Surely you were not doing this on purpose.
    Here is my code!! Please Help!!!!!!!!!!!!!! i have to turn in the assignment on Monday!!

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Slot Machine game in Java. using Net Beans.

    oh alright. my keyboard is fine. let me see if i can fix the posted code.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Slot Machine game in Java. using Net Beans.

    We don't just fix code posted to the forum. We offer hints and suggestions as you work through the problem solving process yourself.

    What does the code do compared to what you want it to do?
    What are you stuck on?
    Have you tried walking through the code line by line and seeing if things take place how you wanted them to? Where do things seem to go wrong?

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Slot Machine game in Java. using Net Beans.

    okay i have fixed the problem. can you please tell me how to add sound in program? i really do not know how to add sound in my game. any help will be appreciated.

Similar Threads

  1. Slot machine, animating the reels to spin
    By LukeDavison in forum Object Oriented Programming
    Replies: 3
    Last Post: November 27th, 2011, 10:59 AM
  2. Net-beans-java
    By Tanmaysinha in forum Java IDEs
    Replies: 2
    Last Post: November 6th, 2011, 05:45 AM
  3. HOW TO MAKE a TIC TAC TOE GAME in Net beans as a desktop application ?
    By jude_pinas in forum Object Oriented Programming
    Replies: 2
    Last Post: September 26th, 2011, 12:51 AM
  4. Slot Machine
    By nemoisback66 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 17th, 2010, 01:57 PM
  5. Replies: 8
    Last Post: February 24th, 2009, 04:04 PM

Tags for this Thread