Ok in my program i'm trying to prevent a user from adding too many objects. i have three arrays called subs airs and dests, the user shouldn't be able to have more than a total of 10 objects between them.
in order to add an object to an array the user must press a JButton on my GUI
here is the action listener for one of these buttons
if(e.getSource() == addAir && (subs.length + airs.length + dests.length)<=10)
{
String name=JOptionPane.showInputDialog(null, "What is the name of this Aircreft Carrier?");
String row=JOptionPane.showInputDialog(null, "What is the horizontal posistion of this Aircreft Carrier?");
String col=JOptionPane.showInputDialog(null, "Where is the vertical posistion of this Aircreft Carrier?");
String numAircraft=JOptionPane.showInputDialog(null, "How many Aircrafts are on this Aircraft Carrier?");
}
to prevent the user from adding more than 10 objects ive included in the if statement a code which adds the lengths of the arrays together and then sees if the total is less than or equal to 10.
this doesn't work because the length of the arrays always exceeds 10, so how do i change this code so that i can add together the total number of objects are in the array?