Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BBall {
- public static int home; //0 for visitor 1 for home
- public static int overtime;
- public static int quarter = 1;
- public static final int SENTINEL = -999;
- public static final int REGULATION_NUM_Quarters = 4;
- public static final int MAX_BOX_SCORE_LENGTH = 13;
- public static int []visitorScores = new int[MAX_BOX_SCORE_LENGTH];
- public static int []homeScores = new int[MAX_BOX_SCORE_LENGTH];
- public static void initialize (int[] visitorScores, int [] homeScores ) {
- for (int i = 0; i < MAX_BOX_SCORE_LENGTH-1; i++){
- visitorScores[i] = 0;
- homeScores[i] = 0;
- }
- }
- public static void readScores (Scanner scores) {
- while (!gameIsOver ()) {
- visitorScores[quarter-1] = scores.nextInt();
- homeScores[quarter-1] = scores.nextInt();
- quarter++;
- }
- }
- public static int gameScore(int[] teamBoxScore) {
- int output = 0;
- for (int v : teamBoxScore) {
- if (v != SENTINEL) {
- output += v;
- }
- }
- return output;
- }
- public static boolean gameIsOver ( ) {
- return (quarter > REGULATION_NUM_Quarters && home == 0 && gameScore(visitorScores) != gameScore(homeScores))
- || (quarter == REGULATION_NUM_Quarters && home == 1 && gameScore(visitorScores) < gameScore(homeScores));
- }
- public static void printBoxScore(int[] teamBoxScore) {
- }
- public static String result ( ) {
- if (gameScore(visitorScores) > gameScore(homeScores)) {
- return "The visiting team won "
- + gameScore(visitorScores) + " to " + gameScore(homeScores)
- + " in " + "__________" + " quarters.";
- }
- if (home == 0) {
- return "The home team won "
- + gameScore(homeScores) + " to " + gameScore(visitorScores)
- + " in " + "__________" + " quarters.";
- }
- if (home == 1) {
- return "The home team won "
- + gameScore(homeScores) + " to " + gameScore(visitorScores)
- + " in " + "__________" + " quarters.";
- }
- return "";
- }
- public static void main (String [ ] args) {
- System.out.println("Please enter the scores below");
- initialize(visitorScores, homeScores);
- readScores (new Scanner (System.in));
- System.out.println (result ( ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement