Hello,
Wrote a simple program that basically ask the user to enter the # of people entering and exiting a store. No more than 125 people allowed total inside and people may come and go anytime they choose to. Everything seems to be running fine, except for allowing only UP TO 125. Appreciated if any hits given to prevent user from entering 2 for example while the total is at 124 because that would make total of 126.
Also, I tried using array like "int [] arrayName = new int[125]", but was unsuccessful as well. Here is what I have so far:
Also attached the .java file. Again, any help is appreciated!
Wrote a simple program that basically ask the user to enter the # of people entering and exiting a store. No more than 125 people allowed total inside and people may come and go anytime they choose to. Everything seems to be running fine, except for allowing only UP TO 125. Appreciated if any hits given to prevent user from entering 2 for example while the total is at 124 because that would make total of 126.
Also, I tried using array like "int [] arrayName = new int[125]", but was unsuccessful as well. Here is what I have so far:
import javax.swing.*;
public class testExample {
public static void main(String [] args){
final int MAXNUM = 125;
int peopleIn = 0;
int peopleOut = 0;
int totalInClub = 0;
int showTotalInClub = 0;
int option;
boolean bool = true;
do{
try{
option = Integer.parseInt(JOptionPane.showInputDialog(null,"Currently: "+ showTotalInClub +
"\n1.For entering \n2.For exiting"));
if(option ==1){
peopleIn = Integer.parseInt(JOptionPane.showInputDialog(null,"How many people entering?"));
if(peopleIn <= MAXNUM){
totalInClub = peopleIn + totalInClub;
showTotalInClub = totalInClub;
JOptionPane.showMessageDialog(null, peopleIn + " people entered!");
if(totalInClub >= MAXNUM){
JOptionPane.showMessageDialog(null,"Sorry, you may not get in at this time. The club is full");
bool = false;
}
}else {
JOptionPane.showMessageDialog(null, "Too many people");
}
}else if(option ==2){
peopleOut = Integer.parseInt(JOptionPane.showInputDialog(null,"how many people exiting?(positive integers)"));
if(peopleOut>totalInClub){
JOptionPane.showMessageDialog(null,"Not that many people in the Club!");
}else{
totalInClub = totalInClub - peopleOut;
showTotalInClub = totalInClub;
JOptionPane.showMessageDialog(null, peopleOut+ " people exited!");
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Invalid entry, try again!");
}
}while(bool ==true);
}
}
Also attached the .java file. Again, any help is appreciated!