Advertisement
476179

soccer players

Nov 18th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package lessons;
  2. import javax.swing.JOptionPane;
  3. public class SoccerTeams
  4. {
  5. //prgm calaculates number of teams a league ,ay create based on available players,
  6. //each team has 9-15 players
  7. public static void main(String[] args)
  8. {
  9. String in;
  10. int players, teamSize, teamN, leftover;
  11. final int MIN_PLAYERS = 9;
  12. final int MAX_PLAYERS = 15;
  13. in = JOptionPane.showInputDialog(null,"how many players do you want on each team,"
  14. + " number bust be 9-15");
  15. teamSize = Integer.parseInt(in);
  16. while (teamSize < MIN_PLAYERS && teamSize > MAX_PLAYERS)
  17. {
  18. in = JOptionPane.showInputDialog(null,"the number must be atleast "
  19. +MIN_PLAYERS+" - "+MAX_PLAYERS);
  20. teamSize = Integer.parseInt(in);
  21. }
  22.  
  23.  
  24. in = JOptionPane.showInputDialog(null, "how many players are participating?");
  25. players = Integer.parseInt(in);
  26.  
  27. while (players < 0)
  28. {
  29. in = JOptionPane.showInputDialog(null,"enter 0 or greater");
  30. players = Integer.parseInt(in);
  31. }
  32.  
  33. leftover = players % teamSize;
  34. teamN = players / teamSize;
  35.  
  36. JOptionPane.showMessageDialog(null, "there can be "+teamN+" teams of "
  37. +teamSize+" players with "+leftover+" players left over");
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement