Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment you are adding functionality to a slot machine simulation to

ID: 3607110 • Letter: F

Question

For this assignment you are adding functionality to a slot machine simulation to make it more like a real slot machine using netbeans/java. you need to include clear comments throughout the program that explain what functionality the various lines/small sections of code/methods are as related to the execution of the program.:

-The user begins with a balance of $20

-Each spin costs $1 (note: the first spin should happen automatically)

-If the user gets 2 numbers the same, s/he wins $2 (provide feedback)

-If the user gets all 3 numbers the same, s/he wins $25 (provide feedback)

-After each spin (and balance update), the user’s balance needs to be printed to the screen and formatted as currency prior to asking him/her if s/he would like to spin again

-The program needs to end when the user no longer has an adequate balance to spin again (less than $1)

-When the program ends, print a thank you message to the user.

-Once the program has ended, print a message to the user to pick up his/her winnings if his/her balance is greater than $1; include the balance in the message.

-Within the program you are required to create a comment area at the top of the program. You need to include clear comments throughout the program that explain what functionality the various lines/small sections of code/methods are as related to the execution of the program.

Sample output from the start of the program

Sample output from the end of the program (user has a positive balance)

Sample output from the end of the program (user runs out of money)

Explanation / Answer

public class Markov

{

    private class similarities

    {

        private char c;

        private int count;

         

        public similarities(char a, int b)

        {

            c = a;

            count = b;

        }

         

        public char getC()

        {

            return c;

        }

         

        public int getCount()

        {

            return count;

        }

         

        public void setCount(int a)

        {

            count = a;

        }

         

        public void increaseCount()

        {

            count++;

        }

    }

    private List<similarities> entries;

    private List<String> axies;

    private double[][] matrix;

    public Markov()

    {

        entries = new ArrayList();

        axies = new ArrayList();

    }

    public void getSimilarity(List<String> s)

    {

        String temp = new String();

        for (int i = 0; i < s.size(); i++)

        {

            if (temp.length() > 0)

            {

                temp = temp + " " + s.get(i);

            }

            else temp = s.get(i);

        }

        setupAxis(temp);

        compareCharsAgainstAxis(temp);

        display();

        for (int i = 0; i < matrix.length; i++)

        {

            double line = getLineValue(i);

            for (int j = 0; j < matrix[i].length; j++)

            {

                double t = matrix[i][j];

                matrix[i][j] = t / line;

            }

        }

        display();

    }

    private void compareCharsAgainstAxis(String s)

    {

        matrix = new double[axies.size()][axies.size()];

        String comparison = "";

        String test = s;

        for (int h = 0; h < test.length(); h++)

        {

            int end = test.indexOf(" ");

            if (end > 0)

            {

                comparison = test.substring(0,end);

            }

            else

            {

                comparison = test.substring(0,test.length());

                end = test.length()-1;

            }

            test = test.substring(end+1,test.length());

            for (int i = 1; i < comparison.length(); i++)

            {

                for (int j = 0; j < axies.size(); j++)

                {

                    for (int k = 0; k < axies.size(); k++)

                    {

                        if (String.valueOf(comparison.charAt(i-1)).equalsIgnoreCase(axies.get(j)) && String.valueOf(comparison.charAt(i)).equalsIgnoreCase(axies.get(k)))

                        {

                            matrix[j][k]++;

                        }

                    }

                }

            }

        }

    }

    private void setupAxis(String temp)

    {

        for (int j = 0; j < temp.length(); j++)

        {

            boolean found = false;

            for (int k = 0; k < axies.size() && !found; k++)

            {

                if (String.valueOf(temp.charAt(j)).equalsIgnoreCase(axies.get(k)))

                {

                    found = true;

                }

            }

            if (!found)

            {

                if (temp.charAt(j) > 32)

                {

                    axies.add(String.valueOf(temp.charAt(j)));

                }

            }

        }

    }

    private double getTotalValue()

    {

        double sum = 0;

        for (int i = 0; i < matrix.length; i++)

        {

            for (int j = 0; j < matrix[i].length; j++)

            {

                double t = matrix[i][j];

                sum = sum + t;

            }

        }

        return sum;

    }

    private double getLineValue(int line)

    {

        double sum = 0;

        for (int i = 0; i < matrix[line].length; i++)

        {

            double t = matrix[line][i];

            sum = sum + t;

        }

        return sum;

    }

    private void display()

    {

        System.out.println("Sum of matrix is "+getTotalValue());

        System.out.println("Sum of line 1 = "+getLineValue(3));

        System.out.print(" ");

        for (int j = 0; j < axies.size(); j++)

        {

            System.out.print(axies.get(j)+" ");

        }

        System.out.println();

        for (int i = 0; i < matrix.length; i++)

        {

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

            for (int j = 0; j < matrix[i].length; j++)

            {

                System.out.print(matrix[i][j]+" ");

            }

            System.out.println();

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote