Skip to content

Instantly share code, notes, and snippets.

/FootballGame Secret

Created November 8, 2013 22:27
Show Gist options
  • Save anonymous/beec75b6361ff1fcbc28 to your computer and use it in GitHub Desktop.
Save anonymous/beec75b6361ff1fcbc28 to your computer and use it in GitHub Desktop.
package footballgame;
import java.util.Scanner;
public class FootballGame {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
String choice;
Scanner keyboard = new Scanner(System.in);
String footballTeam1;
String footballTeam2;
System.out.print("Enter a name for a team:");
footballTeam1 = keyboard.nextLine();
System.out.print("Enter a name for another team:");
footballTeam2 = keyboard.nextLine();
System.out.println("Game Score:");
System.out.println(footballTeam1 + ":0");
System.out.println(footballTeam2 + ":0");
choice = getMenuChoice(footballTeam1, footballTeam2);
}
public static String getMenuChoice(String footballTeam1, String footballTeam2) {
String choice = "";
String input;
do {
System.out.println("Select an option:");
System.out.println("A:" + footballTeam1 + " scored");
System.out.println("B:" + footballTeam2 + " scored");
System.out.println("C: game ended.");
System.out.println("?:");
input = keyboard.nextLine();
if (input.equalsIgnoreCase("A")) {
choice = (footballTeam1);
} else if (input.equalsIgnoreCase("B")) {
choice = (footballTeam2);
} else if (input.equalsIgnoreCase("C")) {
choice = ("Game over!");
}
} while (!input.equals("A") && !input.equals("B") && !input.equals("C"));
return choice;
}
public static int handleTeamScore(int footballTeam) {
do {
System.out.println("How many points were scored by " + choice);
int Keyboard = keyboard.nextInt();
if (points == 1) {
return footballTeam; }
if (points == 2) {
return footballTeam; }
if (points == 3) {
return footballTeam; }
if (points == 6) {
return footballTeam; }
} while ( footballTeam != 1 || footballTeam != 2 || footballTeam != 3 || footballTeam != 6); {
}
System.out.println("Game Score: ");
System.out.println(footballTeam1 + ": " + FootballTeam.getScore());
System.out.println(footballTeam2 + ": " + FootballTeam.getScore());
return footballTeam;
}
}
public class FootballTeam {
private String name;
private int score;
public static int TOUCHDOWN = 6;
public static int FIELD_GOAL = 3;
public static int SAFETY = 2;
public static int TWO_POINT_CONVERSION = 2;
public static int EXTRA_POINT = 1;
public FootballTeam(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public boolean addScore(int points) {
if (points == TOUCHDOWN || points == FIELD_GOAL || points == SAFETY || points == TWO_POINT_CONVERSION || points == EXTRA_POINT) {
score = points + score;
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment