Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab4;
- public class generalTeamStats
- {
- //local variables
- protected String teamName; //name of the team
- protected String sportName; //which sport is it
- protected int gamesPlayed; //how many games played
- protected int gamesWon; //how many games won
- protected int gamesLost; //how many game lost
- //constructor
- public generalTeamStats(String sportName, String teamName, int gamesPlayed, int gamesWon, int gamesLost)
- {
- this.teamName = teamName;
- this.sportName = sportName;
- this.gamesPlayed = gamesPlayed;
- this.gamesWon = gamesWon;
- this.gamesLost = gamesLost;
- }
- public generalTeamStats (String sportName, String teamName)
- {
- this.sportName = sportName;
- this.teamName = teamName;
- gamesPlayed = 0;
- gamesWon = 0;
- gamesLost = 0;
- }
- //updates a individual stat
- public void update (int stat, int updateAmount)
- {
- if (stat == 1)
- gamesPlayed = updateAmount;
- if (stat == 2)
- gamesWon = updateAmount;
- if (stat == 3)
- gamesLost = updateAmount;
- }
- public String displayStats ()
- {
- //make string with all data and return that
- }
- //
- }
- public class baseballStats extends generalTeamStats
- {
- //class variables
- protected int totalHomeRuns;
- protected int totalHomeRunsAllowed;
- protected int totalErrors;
- public baseballStats(int totalHomeRuns, int totalHomeRunsAllowed, int totalErrors, String sportName, String teamName, int gamesPlayed, int gamesWon, int gamesLost)
- {
- super(sportName, teamName, gamesPlayed, gamesWon, gamesLost);
- this.totalHomeRuns = totalHomeRuns;
- this.totalHomeRunsAllowed = totalHomeRunsAllowed;
- this.totalErrors = totalErrors;
- }
- public baseballStats(int totalHomeRuns, int totalHomeRunsAllowed, int totalErrors, String sportName, String teamName)
- {
- super(sportName, teamName);
- this.totalHomeRuns = totalHomeRuns;
- this.totalHomeRunsAllowed = totalHomeRunsAllowed;
- this.totalErrors = totalErrors;
- }
- public double averageErrors (int totalErrors, int gamesPlayed)
- {
- double answer;
- answer = totalErrors / gamesPlayed;
- return answer;
- }
- public averageRunsAllowed (int totalHomeRuns, int gamesPlayed)
- {
- double answer;
- answer = totalHomeRuns / gamesPlayed;
- return answer;
- }
- //updates a individual stat overloaded method
- public void update (int stat, int updateAmount)
- {
- if (stat == 1)
- gamesPlayed = updateAmount;
- if (stat == 2)
- gamesWon = updateAmount;
- if (stat == 3)
- gamesLost = updateAmount;
- if (stat == 4)
- totalHomeRuns = updateAmount;
- if (stat == 5)
- total totalHomeRunsAllowed = updateAmount;
- if (stat == 6)
- totalErrors = updateAmount;
- }
- //prompt user to enter 4 for total HomeRuns
- //prompt user to enter 5 for total HomeRuns Allowed
- //prompt user to enter 6 for total Errors
- import java.util.Scanner;
- public class Lab4
- {
- public static void main(String[] args)
- {
- generalTeamStats team;
- int gamesWon;
- int gamesLost;
- int gamesPlayed;
- int teamName;
- String sportName;
- String update;
- Scanner scan = new Scanner (System.in);
- //prompt user what sport would you like to keep track of
- System.out.print("what sport would you like to keep track of");
- sportName = scan.nextLine();
- //prompt user for teamName
- System.out.print("whats the name of the team);
- teamName = scan.nextLine();
- //prompt user what sport would you like to keep track of
- System.out.print("how many games played this season");
- gamesPlayed = scan.nextInt();
- //prompt user what sport would you like to keep track of
- System.out.print("how many games won this season");
- gamesWon = scan.nextInt();
- //prompt user what sport would you like to keep track of
- System.out.print("how many games won this season");
- gamesWon = scan.nextInt();
- //instantiate a teamStats object based on sport they entered
- if (sportName.toUpper().equals("BASEBALL")
- {
- int totalHomeRuns;
- int totalhomeRunsAllowed;
- int totalErrors;
- //prompt for total home runs
- System.out.print("how many home runs this season:");
- totalHomeRuns = scan.nextInt();
- //prompt for total home runs allowed
- System.out.print("how many home runs did you give up this season:");
- totalHomeRunsAllowed = scan.nextInt();
- //prompt for total home runs allowed
- System.out.print("how many errors did your team have this season:");
- homeRunsAllowed = scan.nextInt();
- team = new baseballStats(totalHomeRuns, totalHomeRunsAllowed, totalErrors, sportName, teamName, gamesPlayed, gamesWon, gamesLost)
- }
- //if they want to do basektball
- else if (sportName.toUpper().equals("BASKETBALL")
- //paste up from totalHomeRuns to team baseballStats
- {
- }
- //if they want to do football
- else if (sportName.toUpper().equals("FOOTBALL")
- {
- }
- //do u want to update stats
- System.out.print("Do you want to update stats yes or no);
- update = scan.NextLine();
- if (update.toUpper().equals("YES"))
- {
- if (sportName.toUpper().equals("BASEBALL"))
- {
- int whichStat;
- int newValue;
- System.out.print("Enter in 1 to update games played
- Enter in 2 to update games Won
- Enter in 3 to update games Lost
- Enter in 4 to update total HomeRuns
- Enter in 5 to update total HomeRuns Allowed
- Enter in 6 to update total Errors");
- whichStat = scan.nextInt();
- System.out.print("What do you want that value to be");
- newValue = scan.NextInt();
- //call update method to pass in new params
- team.update(whichstat, newValue);
- }
- else if (sportName.toUpper().equals("FOOTBALL"))
- {
- //copy from int which stat to team.update just change print statements to names of the new stats
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement