Advertisement
Shavit

P. 122 Ex. 12.5

Mar 16th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. public class SheshBesh
  5. {
  6.     boolean[][] games;
  7.    
  8.     public SheshBesh()
  9.     {
  10.         games = new boolean[7][10];
  11.     }
  12.    
  13.     public void updateGame(int day, int game, boolean result)
  14.     {
  15.         games[day][game] = result;
  16.     }
  17.    
  18.     public boolean moreWins()
  19.     {
  20.         int wins = 0;
  21.         for(int i = 0; i < 7; i++)
  22.             for(int j = 0; j < 10; j++)
  23.                 if(games[i][j])
  24.                     wins++;
  25.         return wins >= 35 ? true : false; // true - Hagit, false - Liron
  26.     }
  27.    
  28.     public int luckyDay()
  29.     {
  30.         int wins = 0;
  31.         int max = -1;
  32.         int luckyDay = 0;
  33.         for(int i = 0; i < 7; i++)
  34.         {
  35.             wins = 0;
  36.             for(int j = 0; j < 10; j++)
  37.                 if(games[i][j])
  38.                     wins++;
  39.             if(wins > max)
  40.             {
  41.                 max = wins;
  42.                 luckyDay = i + 1;
  43.             }
  44.         }
  45.         return luckyDay;
  46.     }
  47.    
  48.     public int luckyGame()
  49.     {
  50.         int wins = 0;
  51.         int max = -1;
  52.         int luckyGame = 0;
  53.         for(int j = 0; j < 10; j++)
  54.         {
  55.             wins = 0;
  56.             for(int i = 0; i < 7; i++)
  57.                 if(!(games[i][j]))
  58.                     wins++;
  59.             if(wins > max)
  60.             {
  61.                 max = wins;
  62.                 luckyGame = j + 1;
  63.             }
  64.         }
  65.         return luckyGame;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement