I would like to know what statement can be made so that I do not get an error if I leave blank spaces.
For example I have 11 textField
in a JFrame
in netbeans. If I fill those 11, it makes me the normal sum, but if for example of those 11 I only want to fill 5 or 2 or 3 or 7 or 4 or 1, etc; It throws me an error if I leave those blank, and it no longer does the sum.
How can I fix the problem? I know that with a IgnoreCase
I can make it not leave blank spaces when I fill out a form, but I don't know how to make it leave blank spaces and continue executing the ordinary sum.
In other words, count it as if it were a 0 but without putting a zero in the sum.
double pro1; double pro2; double pro3; double pro4; double pro5; double pro6; double pro7; double pro8; double pro9; double pro10; double pro11;
double vtnum1; double vtnum2; double vtnum3; double vtnum4; double vtnum5; double vtnum6; double vtnum7; double vtnum8; double vtnum9; double vtnum10; double vtnum11;
double pnum1; double pnum2; double pnum3; double pnum4; double pnum5; double pnum6; double pnum7; double pnum8; double pnum9; double pnum10; double pnum11;
double ivita; double totalito; double subtotalito;
pro1=Double.parseDouble(num1.getText());
pro2=Double.parseDouble(num2.getText());
pro3=Double.parseDouble(num3.getText());
pro4=Double.parseDouble(num4.getText());
pro5=Double.parseDouble(num5.getText());
pro6=Double.parseDouble(num6.getText());
pro7=Double.parseDouble(num7.getText());
pro8=Double.parseDouble(num8.getText());
pro9=Double.parseDouble(num9.getText());
pro10=Double.parseDouble(num10.getText());
pro11=Double.parseDouble(num11.getText());
pnum1=Double.parseDouble(precio1.getText());
pnum2=Double.parseDouble(precio2.getText());
pnum3=Double.parseDouble(precio3.getText());
pnum4=Double.parseDouble(precio4.getText());
pnum5=Double.parseDouble(precio5.getText());
pnum6=Double.parseDouble(precio6.getText());
pnum7=Double.parseDouble(precio7.getText());
pnum8=Double.parseDouble(precio8.getText());
pnum9=Double.parseDouble(precio9.getText());
pnum10=Double.parseDouble(precio10.getText());
pnum11=Double.parseDouble(precio11.getText());
vtnum1=pro1*pnum1;
vtnum2=pro2*pnum2;
vtnum3=pro3*pnum3;
vtnum4=pro4*pnum4;
vtnum5=pro5*pnum5;
vtnum6=pro6*pnum6;
vtnum7=pro7*pnum7;
vtnum8=pro8*pnum8;
vtnum9=pro9*pnum9;
vtnum10=pro10*pnum10;
vtnum11=pro11*pnum11;
String valtota1=vtnum1 + "";
String valtota2=vtnum2 + "";
String valtota3=vtnum3 + "";
String valtota4=vtnum4 + "";
String valtota5=vtnum5 + "";
String valtota6=vtnum6 + "";
String valtota7=vtnum7 + "";
String valtota8=vtnum8 + "";
String valtota9=vtnum9 + "";
String valtota10=vtnum10 + "";
String valtota11=vtnum11 + "";
num12.setText(valtota1);
num13.setText(valtota2);
num14.setText(valtota3);
num15.setText(valtota4);
num16.setText(valtota5);
num17.setText(valtota6);
num18.setText(valtota7);
num19.setText(valtota8);
num20.setText(valtota9);
num21.setText(valtota10);
num22.setText(valtota11);
subtotalito=vtnum1+vtnum2+vtnum3+vtnum4+vtnum5+vtnum6+vtnum7+vtnum8+vtnum9+vtnum10+vtnum11;
String st= subtotalito+"";
subtotal.setText(st);
ivita=subtotalito*0.12;
String i= ivita+"";
iva.setText(i);
totalito=subtotalito+ivita;
String t= totalito+"";
total.setText(t);
}
Complementing the answer of M. Gress (sorry, the system does not allow me to add comments yet)
Ideally, you would make a function to reduce the size of the code and also make it easier to maintain and reuse.
Specifically, a function similar to this
Thus, the modification would be cleaner to read
Edited adding changes suggested by Luiggi Mendoza
You would have to add something like this for each of your entries:
One option is to use the commons lang library, add the jar file to your project from your IDE. If you use maven or gradle you add it easily as a dependency.
Download the library from here
You should add this to your code (once you have the library loaded to your project)
What the above code does is return a "0" if num.getText() is null, an empty string, or a string with spaces.