Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SlotMachine {
- public int[][] machine;
- public int slot;
- public String out;
- public SlotMachine(){
- machine = new int[6][6];
- slot = 0;
- out = "";
- for(int i = 0; i <6; i++) //Initialize all slots as empty (0) initially
- machine[i][i] = 0;
- }
- public void Play(String p){
- //Get position
- for (char s : p.toCharArray()){
- if(s == 'R')
- slot++;
- }
- //Insert
- for (int j = 0; j < 6; j++){
- if(machine[slot][j] == 0){
- machine[slot][j] = 1;
- break;
- }
- }
- }
- public void Display(){
- String temp="";
- //Look carefully how I use i and j
- for(int i = 0; i < 6; i++){
- for(int j = 0; j < 6; j++){
- if(machine[j][i] == 0)
- temp+="| | ";
- else
- temp+="|* | ";
- }
- //Im printing row first, so gotta and a new line after each round
- temp+="\n";
- }
- System.out.print(temp);
- System.out.println("-----------------------------------\n");
- //Print the indexes on the bottom
- for(int i = 0; i < 6; i++)
- System.out.print(i+" ");
- //return out;
- }
- public static void main(String[] args) {
- SlotMachine m = new SlotMachine();
- Scanner r = new Scanner(System.in);
- System.out.print("Enter your string: ");
- String play = r.next();
- m.Play(play);
- m.Display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement