SHARE
TWEET

Untitled

a guest Feb 16th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package lab4;
  2.  
  3. public class generalTeamStats
  4. {
  5.     //local variables
  6.     protected String teamName;                                 //name of the team
  7.     protected String sportName;                                //which sport is it
  8.     protected int gamesPlayed;                                 //how many games played
  9.     protected int gamesWon;                                    //how many games won
  10.     protected int gamesLost;                                   //how many game lost
  11.  
  12.     //constructor
  13.     public generalTeamStats(String sportName, String teamName, int gamesPlayed, int gamesWon, int gamesLost)
  14.     {
  15.         this.teamName = teamName;
  16.         this.sportName = sportName;
  17.         this.gamesPlayed = gamesPlayed;
  18.         this.gamesWon = gamesWon;
  19.         this.gamesLost = gamesLost;
  20.     }
  21.  
  22.  
  23.     public generalTeamStats (String sportName, String teamName)
  24.     {
  25.         this.sportName = sportName;
  26.         this.teamName = teamName;
  27.         gamesPlayed = 0;
  28.         gamesWon = 0;
  29.         gamesLost = 0;
  30.     }
  31.  
  32.     //updates a individual stat
  33.     public void update (int stat, int updateAmount)
  34.     {
  35.         if (stat == 1)
  36.         gamesPlayed = updateAmount;
  37.        
  38.         if (stat == 2)
  39.         gamesWon = updateAmount;
  40.        
  41.         if (stat == 3)
  42.         gamesLost = updateAmount;
  43.        
  44.     }
  45.  
  46.     public String displayStats ()
  47.     {
  48.         //make string with all data and return that
  49.     }
  50.  
  51.  
  52. //
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59. public class baseballStats extends generalTeamStats
  60.  
  61. {
  62.     //class variables
  63.     protected int totalHomeRuns;
  64.     protected int totalHomeRunsAllowed;
  65.     protected int totalErrors;
  66.  
  67.     public baseballStats(int totalHomeRuns, int totalHomeRunsAllowed, int totalErrors, String sportName, String teamName, int gamesPlayed, int gamesWon, int gamesLost)
  68.     {
  69.         super(sportName, teamName, gamesPlayed, gamesWon, gamesLost);
  70.         this.totalHomeRuns = totalHomeRuns;
  71.         this.totalHomeRunsAllowed = totalHomeRunsAllowed;
  72.         this.totalErrors = totalErrors;
  73.     }
  74.  
  75.     public baseballStats(int totalHomeRuns, int totalHomeRunsAllowed, int totalErrors, String sportName, String teamName)
  76.     {
  77.         super(sportName, teamName);
  78.         this.totalHomeRuns = totalHomeRuns;
  79.         this.totalHomeRunsAllowed = totalHomeRunsAllowed;
  80.         this.totalErrors = totalErrors;
  81.     }
  82.    
  83.     public double averageErrors (int totalErrors, int gamesPlayed)
  84.     {
  85.         double answer;
  86.         answer = totalErrors / gamesPlayed;
  87.         return answer;
  88.     }
  89.    
  90.     public averageRunsAllowed (int totalHomeRuns, int gamesPlayed)
  91.     {
  92.         double answer;
  93.         answer = totalHomeRuns / gamesPlayed;
  94.         return answer;
  95.     }
  96.    
  97.    
  98.     //updates a individual stat overloaded method
  99.     public void update (int stat, int updateAmount)
  100.     {
  101.         if (stat == 1)
  102.         gamesPlayed = updateAmount;
  103.        
  104.         if (stat == 2)
  105.         gamesWon = updateAmount;
  106.        
  107.         if (stat == 3)
  108.         gamesLost = updateAmount;
  109.        
  110.         if (stat == 4)
  111.         totalHomeRuns = updateAmount;
  112.        
  113.         if (stat == 5)
  114.         total totalHomeRunsAllowed = updateAmount;
  115.        
  116.         if (stat == 6)
  117.         totalErrors = updateAmount;
  118.        
  119.     }
  120.  
  121.  
  122.  
  123. //prompt user to enter 4 for total HomeRuns
  124. //prompt user to enter 5 for total HomeRuns Allowed
  125. //prompt user to enter 6 for total Errors
  126. import java.util.Scanner;
  127. public class Lab4
  128. {
  129.    
  130.     public static void main(String[] args)
  131.     {
  132.         generalTeamStats team;
  133.         int gamesWon;
  134.         int gamesLost;
  135.         int gamesPlayed;
  136.         int teamName;
  137.         String sportName;
  138.         String update;
  139.         Scanner scan = new Scanner (System.in);
  140.        
  141.         //prompt user what sport would you like to keep track of
  142.         System.out.print("what sport would you like to keep track of");
  143.         sportName = scan.nextLine();
  144.        
  145.         //prompt user for teamName
  146.         System.out.print("whats the name of the team);
  147.         teamName = scan.nextLine();
  148.        
  149.         //prompt user what sport would you like to keep track of
  150.         System.out.print("how many games played this season");
  151.         gamesPlayed = scan.nextInt();
  152.        
  153.         //prompt user what sport would you like to keep track of
  154.         System.out.print("how many games won this season");
  155.         gamesWon = scan.nextInt();
  156.        
  157.         //prompt user what sport would you like to keep track of
  158.         System.out.print("how many games won this season");
  159.         gamesWon = scan.nextInt();
  160.        
  161.         //instantiate a teamStats object based on sport they entered
  162.         if (sportName.toUpper().equals("BASEBALL")
  163.         {
  164.             int totalHomeRuns;
  165.             int totalhomeRunsAllowed;
  166.             int totalErrors;
  167.            
  168.             //prompt for total home runs
  169.             System.out.print("how many home runs this season:");
  170.             totalHomeRuns = scan.nextInt();
  171.            
  172.             //prompt for total home runs allowed
  173.             System.out.print("how many home runs did you give up this season:");
  174.             totalHomeRunsAllowed = scan.nextInt();
  175.            
  176.             //prompt for total home runs allowed
  177.             System.out.print("how many errors did your team have this season:");
  178.             homeRunsAllowed = scan.nextInt();
  179.            
  180.             team = new baseballStats(totalHomeRuns, totalHomeRunsAllowed, totalErrors, sportName, teamName, gamesPlayed, gamesWon, gamesLost)
  181.         }
  182.        
  183.         //if they want to do basektball
  184.         else if (sportName.toUpper().equals("BASKETBALL")
  185.        
  186.         //paste up from totalHomeRuns to team baseballStats
  187.        
  188.         {
  189.        
  190.         }
  191.        
  192.         //if they want to do football
  193.         else if (sportName.toUpper().equals("FOOTBALL")
  194.         {
  195.        
  196.         }
  197.        
  198.         //do u want to update stats
  199.         System.out.print("Do you want to update stats yes or no);
  200.         update = scan.NextLine();
  201.        
  202.         if (update.toUpper().equals("YES"))
  203.         {
  204.             if (sportName.toUpper().equals("BASEBALL"))
  205.             {
  206.                 int whichStat;
  207.                 int newValue;
  208.                 System.out.print("Enter in 1 to update games played
  209.                                   Enter in 2 to update games Won
  210.                                   Enter in 3 to update games Lost
  211.                                   Enter in 4 to update total HomeRuns
  212.                                   Enter in 5 to update total HomeRuns Allowed
  213.                                   Enter in 6 to update total Errors");
  214.                                   whichStat = scan.nextInt();
  215.                                  
  216.                 System.out.print("What do you want that value to be");
  217.                 newValue = scan.NextInt();
  218.                
  219.                 //call update method to pass in new params
  220.                 team.update(whichstat, newValue);
  221.             }
  222.             else if (sportName.toUpper().equals("FOOTBALL"))
  223.             {
  224.             //copy from int which stat to team.update just change print statements to names of the new stats
  225.            
  226.             }
  227.            
  228.         }
  229.        
  230.        
  231.        
  232.        
  233.        
  234.     }
  235.    
  236. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top