Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- import javax.swing.JOptionPane;
- public class SoccerTeams
- {
- //prgm calaculates number of teams a league ,ay create based on available players,
- //each team has 9-15 players
- public static void main(String[] args)
- {
- String in;
- int players, teamSize, teamN, leftover;
- final int MIN_PLAYERS = 9;
- final int MAX_PLAYERS = 15;
- in = JOptionPane.showInputDialog(null,"how many players do you want on each team,"
- + " number bust be 9-15");
- teamSize = Integer.parseInt(in);
- while (teamSize < MIN_PLAYERS && teamSize > MAX_PLAYERS)
- {
- in = JOptionPane.showInputDialog(null,"the number must be atleast "
- +MIN_PLAYERS+" - "+MAX_PLAYERS);
- teamSize = Integer.parseInt(in);
- }
- in = JOptionPane.showInputDialog(null, "how many players are participating?");
- players = Integer.parseInt(in);
- while (players < 0)
- {
- in = JOptionPane.showInputDialog(null,"enter 0 or greater");
- players = Integer.parseInt(in);
- }
- leftover = players % teamSize;
- teamN = players / teamSize;
- JOptionPane.showMessageDialog(null, "there can be "+teamN+" teams of "
- +teamSize+" players with "+leftover+" players left over");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement