Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class BBall {
  3.  
  4. public static int home; //0 for visitor 1 for home
  5. public static int overtime;
  6. public static int quarter = 1;
  7.  
  8. public static final int SENTINEL = -999;
  9. public static final int REGULATION_NUM_Quarters = 4;
  10. public static final int MAX_BOX_SCORE_LENGTH = 13;
  11.  
  12. public static int []visitorScores = new int[MAX_BOX_SCORE_LENGTH];
  13. public static int []homeScores = new int[MAX_BOX_SCORE_LENGTH];
  14.  
  15. public static void initialize (int[] visitorScores, int [] homeScores ) {
  16. for (int i = 0; i < MAX_BOX_SCORE_LENGTH-1; i++){
  17. visitorScores[i] = 0;
  18. homeScores[i] = 0;
  19. }
  20. }
  21. public static void readScores (Scanner scores) {
  22. while (!gameIsOver ()) {
  23. visitorScores[quarter-1] = scores.nextInt();
  24. homeScores[quarter-1] = scores.nextInt();
  25. quarter++;
  26. }
  27. }
  28.  
  29. public static int gameScore(int[] teamBoxScore) {
  30. int output = 0;
  31. for (int v : teamBoxScore) {
  32. if (v != SENTINEL) {
  33. output += v;
  34. }
  35. }
  36. return output;
  37. }
  38.  
  39. public static boolean gameIsOver ( ) {
  40. return (quarter > REGULATION_NUM_Quarters && home == 0 && gameScore(visitorScores) != gameScore(homeScores))
  41. || (quarter == REGULATION_NUM_Quarters && home == 1 && gameScore(visitorScores) < gameScore(homeScores));
  42. }
  43.  
  44. public static void printBoxScore(int[] teamBoxScore) {
  45.  
  46. }
  47.  
  48. public static String result ( ) {
  49. if (gameScore(visitorScores) > gameScore(homeScores)) {
  50. return "The visiting team won "
  51. + gameScore(visitorScores) + " to " + gameScore(homeScores)
  52. + " in " + "__________" + " quarters.";
  53. }
  54. if (home == 0) {
  55. return "The home team won "
  56. + gameScore(homeScores) + " to " + gameScore(visitorScores)
  57. + " in " + "__________" + " quarters.";
  58. }
  59. if (home == 1) {
  60. return "The home team won "
  61. + gameScore(homeScores) + " to " + gameScore(visitorScores)
  62. + " in " + "__________" + " quarters.";
  63. }
  64. return "";
  65. }
  66. public static void main (String [ ] args) {
  67.  
  68. System.out.println("Please enter the scores below");
  69. initialize(visitorScores, homeScores);
  70.  
  71. readScores (new Scanner (System.in));
  72. System.out.println (result ( ));
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement