Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package baseballmanager;
  2.  
  3. import java.util.*;
  4.  
  5. public class BaseballManager
  6. {
  7.  
  8.     public static final int MENU_ITEMS = 4;
  9.  
  10.     public String[] name = new String[25];
  11.  
  12.     public String[] position = new String[25];
  13.  
  14.     public int[] order = new int[25];
  15.  
  16.     public int count = 0;
  17.  
  18.     Scanner in = new Scanner(System.in);
  19.  
  20.     public static void main(String[] args)
  21.     {
  22.  
  23.         BaseballManager baseballObject = new BaseballManager();
  24.  
  25. }
  26.  
  27.     public BaseballManager()
  28.     {
  29.          while(true)
  30.         {
  31.              printMenu();
  32.  
  33.             boolean valid = false;
  34.  
  35.             int choice = 0;        
  36.  
  37.             while(valid ==false)
  38.             {
  39.                 choice = getChoice();
  40.  
  41.                 if(choice > 0 && choice <= MENU_ITEMS)
  42.                 {
  43.                     valid = true;
  44.                 }
  45.                 else
  46.                 {
  47.                     System.out.println("Invalid Choice. Please pick 1-4.");
  48.                 }          
  49.             }
  50.  
  51.             makeChoice(choice);            
  52.  
  53.         }
  54.  
  55.     }
  56.  
  57.     public void printMenu(){
  58.  
  59.         System.out.println("1. Display Line-up");
  60.  
  61.         System.out.println("2. Display Roster");
  62.  
  63.         System.out.println("3. Display Bench");
  64.  
  65.         System.out.println("4. Add Player");
  66.  
  67.     }
  68.  
  69.    
  70.  
  71.     public int getChoice()
  72.     {
  73.         in = new Scanner(System.in);
  74.  
  75.         System.out.print("> ");
  76.  
  77.         int choice = in.nextInt();
  78.  
  79.         return choice;
  80.      }
  81.  
  82.    
  83.  
  84.     public void makeChoice(int choice)
  85.     {
  86.          switch(choice)
  87.         {
  88.             case 1: displayLineup();
  89.  
  90.                 break;
  91.  
  92.             case 2: displayRoster();
  93.  
  94.                 break;
  95.  
  96.             case 3: displayBench();
  97.  
  98.                 break;
  99.  
  100.             case 4: addPlayer();
  101.  
  102.                 break;
  103.          }
  104.     }
  105.  
  106.     public void displayLineup()
  107.     {
  108.         Arrays.sort(order);
  109.        
  110.         for(int a=0;a <order.length; a++)
  111.         {
  112.             {
  113.                 if(order[a] > 0)
  114.                 {
  115.                     System.out.println(name[0]);
  116.                     System.out.println(name[1]);
  117.                 }
  118.                 else
  119.                 {
  120.                 //Do nothing.    
  121.                 }
  122.             }
  123.         }    
  124.     }
  125.            
  126.    
  127.     public void displayRoster()
  128.     {
  129.        
  130.         for(int b = 0; b < count; b++)
  131.         {
  132.  
  133.             System.out.println(name[b]);
  134.  
  135.         }
  136.        
  137.     }
  138.  
  139.    
  140.  
  141.     public void displayBench()
  142.     {
  143.        
  144.         for(int c=0;c <count; c++)
  145.         {      
  146.             if(order[c] == 0)
  147.             {      
  148.                 System.out.println(name[c]);  
  149.             }
  150.             else
  151.             {
  152.                 //Do nothing.    
  153.             }
  154.            
  155.         }
  156.        
  157.     }
  158.  
  159.    
  160.     public void addPlayer()
  161.     {
  162.        in = new Scanner(System.in);
  163.  
  164.        if(count < 25)
  165.        {
  166.  
  167.        System.out.println("Enter Player Name: ");
  168.  
  169.        name[count] = in.nextLine();
  170.  
  171.        System.out.println("Enter Player Position: ");
  172.  
  173.        position[count] = in.nextLine();
  174.  
  175.        System.out.println("Enter Player Batting Order"
  176.                + " (Enter 0 if not in batting lineup): ");
  177.  
  178.        order[count] = in.nextInt();
  179.  
  180.        count++;
  181.  
  182.        }
  183.  
  184.     }
  185.  
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement