Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class SlotMachine {
  5.  
  6. public int[][] machine;
  7. public int slot;
  8. public String out;
  9.  
  10. public SlotMachine(){
  11. machine = new int[6][6];
  12. slot = 0;
  13. out = "";
  14. for(int i = 0; i <6; i++) //Initialize all slots as empty (0) initially
  15. machine[i][i] = 0;
  16. }
  17.  
  18. public void Play(String p){
  19.  
  20. //Get position
  21. for (char s : p.toCharArray()){
  22. if(s == 'R')
  23. slot++;
  24. }
  25.  
  26. //Insert
  27. for (int j = 0; j < 6; j++){
  28. if(machine[slot][j] == 0){
  29. machine[slot][j] = 1;
  30. break;
  31. }
  32. }
  33. }
  34. public void Display(){
  35. String temp="";
  36.  
  37. //Look carefully how I use i and j
  38. for(int i = 0; i < 6; i++){
  39. for(int j = 0; j < 6; j++){
  40. if(machine[j][i] == 0)
  41. temp+="| | ";
  42. else
  43. temp+="|* | ";
  44. }
  45. //Im printing row first, so gotta and a new line after each round
  46. temp+="\n";
  47. }
  48. System.out.print(temp);
  49. System.out.println("-----------------------------------\n");
  50. //Print the indexes on the bottom
  51. for(int i = 0; i < 6; i++)
  52. System.out.print(i+" ");
  53. //return out;
  54. }
  55. public static void main(String[] args) {
  56. SlotMachine m = new SlotMachine();
  57. Scanner r = new Scanner(System.in);
  58. System.out.print("Enter your string: ");
  59. String play = r.next();
  60.  
  61. m.Play(play);
  62. m.Display();
  63.  
  64.  
  65.  
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement