-
Notifications
You must be signed in to change notification settings - Fork 0
Dev munguia #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Dev munguia #9
Changes from all commits
925326d
5a21ef4
88fcc82
b389d87
ee4ffa3
beb2f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1; | ||
|
|
||
| import com.cert.oca8.course.devdamunguia95.module10.practice1.utility.GameUtils; | ||
|
|
||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class Game { | ||
|
|
||
| private Team homeTeam; | ||
| private Team awayTeam; | ||
| private Goal[] goals; | ||
|
|
||
| public Game() { | ||
| } | ||
|
|
||
| public Game(Team homeTeam, Team awayTeam) { | ||
| this.homeTeam = homeTeam; | ||
| this.awayTeam = awayTeam; | ||
| } | ||
|
|
||
| public void playGame(int maxGoals) { | ||
| int numberOfGoals = (int) (Math.random() * (maxGoals + 1)); | ||
| Goal[] theGoals = new Goal[numberOfGoals]; | ||
| this.setGoals(theGoals); | ||
| GameUtils.addGamesGoals(this); | ||
| } | ||
|
|
||
| public void playGame() { | ||
| playGame(6); | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| int homeTeamGoals = 0; | ||
| int awayTeamGoals = 0; | ||
| StringBuilder returnString = new StringBuilder(); | ||
|
|
||
| returnString.append(homeTeam.getTeamName() | ||
| + " vs " + awayTeam.getTeamName() + "\n"); | ||
| for (Goal currGame : this.getGoals()) { | ||
| if (currGame.getTheTeam() == homeTeam) { | ||
| homeTeamGoals++; | ||
|
|
||
| } else { | ||
| awayTeamGoals++; | ||
| } | ||
| returnString.append("Goal scored after " | ||
| + currGame.getTheTime() + " mins by " | ||
| + currGame.getThePlayer().getPlayerName() + " of " | ||
| + currGame.getTheTeam().getTeamName() + "\n"); | ||
| } | ||
|
|
||
| if (homeTeamGoals == awayTeamGoals) { | ||
| returnString.append("it's a draw!"); | ||
| homeTeam.incPointsTotal(1); | ||
| awayTeam.incPointsTotal(1); | ||
| } else if (homeTeamGoals > awayTeamGoals) { | ||
| returnString.append(homeTeam.getTeamName() + " win"); | ||
| homeTeam.incPointsTotal(1); | ||
| } else { | ||
| returnString.append(awayTeam.getTeamName() + " win"); | ||
| awayTeam.incPointsTotal(1); | ||
| } | ||
| returnString.append("(" + homeTeamGoals + " - " | ||
| + awayTeamGoals + ") \n"); | ||
| return returnString.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * @return the homeTeam | ||
| */ | ||
| public Team getHomeTeam() { | ||
| return homeTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @param homeTeam the homeTeam to set | ||
| */ | ||
| public void setHomeTeam(Team homeTeam) { | ||
| this.homeTeam = homeTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @return the awayTeam | ||
| */ | ||
| public Team getAwayTeam() { | ||
| return awayTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @param awayTeam the awayTeam to set | ||
| */ | ||
| public void setAwayTeam(Team awayTeam) { | ||
| this.awayTeam = awayTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @return the goals | ||
| */ | ||
| public Goal[] getGoals() { | ||
| return goals; | ||
| } | ||
|
|
||
| /** | ||
| * @param goals the goals to set | ||
| */ | ||
| public void setGoals(Goal[] goals) { | ||
| this.goals = goals; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1; | ||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class Goal { | ||
| private Team theTeam; | ||
| private Player thePlayer; | ||
| private double theTime; | ||
| /** | ||
| * @return the theTeam | ||
| */ | ||
| public Team getTheTeam() { | ||
| return theTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @param theTeam the theTeam to set | ||
| */ | ||
| public void setTheTeam(Team theTeam) { | ||
| this.theTeam = theTeam; | ||
| } | ||
|
|
||
| /** | ||
| * @return the thePlayer | ||
| */ | ||
| public Player getThePlayer() { | ||
| return thePlayer; | ||
| } | ||
|
|
||
| /** | ||
| * @param thePlayer the thePlayer to set | ||
| */ | ||
| public void setThePlayer(Player thePlayer) { | ||
| this.thePlayer = thePlayer; | ||
| } | ||
|
|
||
| /** | ||
| * @return the theTime | ||
| */ | ||
| public double getTheTime() { | ||
| return theTime; | ||
| } | ||
|
|
||
| /** | ||
| * @param theTime the theTime to set | ||
| */ | ||
| public void setTheTime(double theTime) { | ||
| this.theTime = theTime; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1; | ||
|
|
||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class League { | ||
|
|
||
| public static void main(String[] args) { | ||
| League league = new League(); | ||
| Team[] theTeams = league.createTeams(); | ||
| Game[] theGames = league.createGames(theTeams); | ||
|
|
||
| for (Game theGame : theGames) { | ||
| theGame.playGame(); | ||
| System.out.println(theGame.getDescription()); | ||
| } | ||
| league.showBestTeam(theTeams); | ||
| } | ||
|
|
||
| public Team[] createTeams() { | ||
| // TODO code application logic here | ||
| Player player1 = new Player("George Eliot"); | ||
| Player player2 = new Player("Graham Greene"); | ||
| Player player3 = new Player("Geoffrey Chaucer"); | ||
| Player[] thePlayers = {player1, player2, player3}; | ||
|
|
||
| Team team1 = new Team("The Greens", thePlayers); | ||
| //Second Team | ||
| Team team2 = new Team("The Reeds", new Player[3]); | ||
| team2.getPlayerArray()[0] = new Player("Robert Service"); | ||
| team2.getPlayerArray()[1] = new Player("Robbie Burns"); | ||
| team2.getPlayerArray()[2] = new Player("Rafael Sabatini"); | ||
|
|
||
| Team[] theTeams = {team1, team2}; | ||
| return theTeams; | ||
| } | ||
|
|
||
| public Game[] createGames(Team[] theTeams) { | ||
| Game theGame = new Game(theTeams[0], theTeams[1]); | ||
| Game theGame2 = new Game(theTeams[1], theTeams[0]); | ||
| Game theGame3 = new Game(theTeams[0], theTeams[1]); | ||
| Game theGame4 = new Game(theTeams[1], theTeams[0]); | ||
| Game[] theGames = {theGame, theGame2, theGame3, theGame4}; | ||
| return theGames; | ||
| } | ||
|
|
||
| public void showBestTeam(Team[] theTeams) { | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliminar espacio innecesario |
||
| System.out.println("\nTeams Poinst"); | ||
|
|
||
| for (Team currTeam : theTeams) { | ||
| System.out.println(currTeam.getTeamName() + ":" + | ||
| currTeam.getPointsTotal()); | ||
| } | ||
|
|
||
| Team currBestTeam = theTeams[0]; | ||
|
|
||
| for (Team currTeam : theTeams) { | ||
| currBestTeam = currTeam.getPointsTotal() > | ||
| currBestTeam.getPointsTotal()? | ||
| currTeam : currBestTeam; | ||
| } | ||
| System.out.println("Winner of League is " + | ||
| currBestTeam.getTeamName()); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1; | ||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class Player { | ||
| private String playerName; | ||
|
|
||
| public Player(String playerName) { | ||
| this.playerName = playerName; | ||
| } | ||
|
|
||
| public Player() { | ||
| } | ||
| /** | ||
| * @return the playerName | ||
| */ | ||
| public String getPlayerName() { | ||
| return playerName; | ||
| } | ||
| /** | ||
| * @param playerName the playerName to set | ||
| */ | ||
| public void setPlayerName(String playerName) { | ||
| this.playerName = playerName; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1; | ||
|
|
||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class Team { | ||
|
|
||
| private String teamName; | ||
| private Player[] playerArray; | ||
| private int pointsTotal; | ||
|
|
||
| public Team() { | ||
| } | ||
|
|
||
| public Team(String teamName) { | ||
| this.teamName = teamName; | ||
| } | ||
|
|
||
| public Team(String teamName, Player[] playerArray) { | ||
| this(teamName); | ||
| this.playerArray = playerArray; | ||
| } | ||
|
|
||
| public void incPointsTotal(int pointsTotal) { | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliminar espacio innecesario |
||
| this.pointsTotal += pointsTotal; | ||
| } | ||
|
|
||
| /** | ||
| * @return the teamName | ||
| */ | ||
| public String getTeamName() { | ||
| return teamName; | ||
| } | ||
|
|
||
| /** | ||
| * @param teamName the teamName to set | ||
| */ | ||
| public void setTeamName(String teamName) { | ||
| this.teamName = teamName; | ||
| } | ||
|
|
||
| /** | ||
| * @return the playerArray | ||
| */ | ||
| public Player[] getPlayerArray() { | ||
| return playerArray; | ||
| } | ||
|
|
||
| /** | ||
| * @param playerArray the playerArray to set | ||
| */ | ||
| public void setPlayerArray(Player[] playerArray) { | ||
| this.playerArray = playerArray; | ||
| } | ||
|
|
||
| /** | ||
| * @return the pointsTotal | ||
| */ | ||
| public int getPointsTotal() { | ||
| return pointsTotal; | ||
| } | ||
|
|
||
| /** | ||
| * @param pointsTotal the pointsTotal to set | ||
| */ | ||
| public void setPointsTotal(int pointsTotal) { | ||
| this.pointsTotal = pointsTotal; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.cert.oca8.course.devdamunguia95.module10.practice1.utility; | ||
|
|
||
| import com.cert.oca8.course.devdamunguia95.module10.practice1.Game; | ||
| import com.cert.oca8.course.devdamunguia95.module10.practice1.Goal; | ||
|
|
||
| /** | ||
| * | ||
| * @author dmunguias | ||
| */ | ||
| public class GameUtils { | ||
|
|
||
| public static Game addGamesGoals(Game currGame) { | ||
|
|
||
| for (int i = 0; i < currGame.getGoals().length; i++) { | ||
| Goal goals = new Goal(); | ||
| int numberOfTeam = (int) (Math.random() * 2); | ||
| if (numberOfTeam != 0) { | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliminar espacio innecesario |
||
| int arrayPlayerLength = currGame.getAwayTeam().getPlayerArray().length; | ||
| int numberOfPlayer = (int) (Math.random() * arrayPlayerLength); | ||
|
|
||
| goals.setThePlayer(currGame.getAwayTeam().getPlayerArray()[numberOfPlayer]); | ||
| goals.setTheTeam(currGame.getAwayTeam()); | ||
| goals.setTheTime((int) (Math.random() * 90)); | ||
|
|
||
| } else { | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliminar espacio innecesario |
||
| int arrayPlayerLength = currGame.getHomeTeam().getPlayerArray().length; | ||
| int numberOfPlayer = (int) (Math.random() * arrayPlayerLength); | ||
| goals.setThePlayer(currGame.getHomeTeam().getPlayerArray()[numberOfPlayer]); | ||
| goals.setTheTeam(currGame.getHomeTeam()); | ||
| goals.setTheTime((int) (Math.random() * 90)); | ||
| } | ||
| currGame.getGoals()[i] = goals; | ||
| } | ||
| return currGame; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eliminar espacio innecesario