an alternative for this code

look guys im new on this of JAVA im starting a career on this but i have a lot of questions, the only one who can resolve this is somebody and not a manual xD

is simple i just need an alternative

(im sorry for my english but i cannot speak much english)

the code have comments in spanish dont read it

well this is the code the question is simple i have the IOException for any error if you see i have do-whiles for repetitions (iteracion para los que puedan leer) of this code when has ended..

i need to know something if the code drops a exception i dont want break the code y want to continue; the code

but how? because i can't say

if (pet != int) continue; but that is the idea

if i put a "" i get a exception error

if i put a String again i get the exception error

//made by exekyelipliz

import java.io.*;

public class teatro

{

public static void main (String args[])throws IOException

{

int pet = 0; //personasEnTotal

int edad = 0; //la edad de la persona, abajo se especifican limitaciones

int ve = 2000; //valorEntrada

int a = 35; //de 5 a 14 a駉s 35% de descuento

int b = 25; //de 15 a 19 a駉s 25% de descuento

int c = 10; //de 20 a 45 a駉s 10% de descuento

int d = 25; //de 46 a 65 a駉s 25% de descuento

int e1 = 35; //de 66 a駉s en adelante 35% de descuento

//por un asunto de orden es que se genero "d" y "e1(por razones del try/catch "e1")"

int f = 100; //este porcentaje lo usaremos para la ecuacion matematica del porcentaje asi no quedan rastros tipo double

int tn = 0; //total neto con el descuento ya realizado

int td = 0; //total descontado

int ttn = 0;

int ttd = 0;

int contador = 1; //el contador este nos permitira iterar la secuencia correspondiente al numero de personas

do{ //este do-while permite la auto inicializacion del programa una vez haya concluido

try{

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("indique el numero de personas");

pet = Integer.parseInt(in.readLine());

do{ //este es le do-while al cual le hemos agregado un contador para que de

//esta forma no solo itere lo primero que encuentre si no todo el codigo dentro del do-while

System.out.println("indique la edad del cliente");

System.out.println("RECUERDE!!\nsi la edad de la persona\n es inferior a 5 a駉s\n el total no sera calculado");

edad = Integer.parseInt(in.readLine());

contador++;

if (edad <5){

System.out.println("lo sentimos pero la edad del la persona no cumple el rango para poder acceder");

}

if (edad < 5) continue;

if (edad >=5){

tn = (ve - (ve * a)/f);

td =((ve * a)/f);

ttn = ttn + tn;

ttd = ttd + td;

}

if (edad >=15){

tn = (ve - (ve * d)/f);

td = ((ve * d)/f);

ttn = ttn + tn;

ttd = ttd + td;

}

if (edad >=20){

tn = (ve - (ve * c)/f);

td = ((ve * c)/f);

ttn = ttn + tn;

ttd = ttd + td;

}

if (edad >=46){

tn = (ve - (ve * d)/f);

td = ((ve * d)/f);

ttn = ttn + tn;

ttd = ttd + td;

}

if (edad >=66){

tn = (ve - (ve * e1)/f);

td =((ve * e1)/f);

ttn = ttn + tn;

ttd = ttd + td;

}

System.out.println("esta persona paga en total:" +" " +tn +" y tiene un descuento de:" +" " +td);

//aqui concluye el do-while de iteracion pet esta era la contaba

//con un contador y que servia para iterar el programa enconrde a los datos de pet

}while (contador <= pet);

//aqui trate pero no pude crear una impresion con la sumas de los "TN" y "TD"

//referente a la cantidad de ellos puesto por la cantidad de personas en "pet"V0.1

//ahora si pude crearlo a travez de los valores "TTN" y TTD" que me permiten sumar

//el valor de tn o td que son nuevos siempre y utilizar por defecto un valor que solo puede ser tomado

//de alguna operacion anterior lo que me permite sacar sumas o incluso restas u otros de las iteraciones.--V0.2

System.out.println("");

System.out.println("*********************************************");

System.out.println("en total las personas deben pagar:" +" "+ttn+"\ny el total a descontar es:" +" " +ttd);

System.out.println("*********************************************");

System.out.println("");

//aca lo que hacemos es lo sgte le indicamos a ttn y ttd que asuman valor 0 por que de lo contrario siguen sumando

//aunque el cogido de iteracion en si haya terminado

//ADVERTENCIA: si el contador no se le indica que vuelva a ser 1 ,una vez que se itere el programa no tomara en cuenta pet

//en pocas palabras no pedira la info de todas las personas por grupo a lo menos 2 veces ...no se por que pasa eso me imagino

//que debe ser que correspodiente al valor dado por pet que al que se debe acercar toma el valor de pet por lo que en cuando

//el contador tome el while va a quedar una razon de 1>2 y se va a repetir tan solo una vez

if (ttn > 0){

ttn = 0;

}

if (ttd > 0){

ttd = 0;

}

if (contador != 1){

contador = 1;

}

}

catch(Exception e)

{

e.printStackTrace();

}

}while (0 < pet);

}

}

[5474 byte] By [Exekyela] at [2007-11-27 8:50:07]
# 1

Is this what you are trying to do?

if someone enters something that is not a number you print an error

and try again. If it is then I think this will help.

In your exception handler make sure that you set the variable pet to

something that will allow the loop to continue.

catch (Exception e)

{

e.printStackTrace();

pet = something to allow the loop to continue;

}

PS: In the future when you post some code please use the code tags

(see the formatting tips.) It makes you code much much easier to read.

johndjra at 2007-7-12 21:00:38 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

yah sorry for the tags, well you have told me that i have to put something that let me continue, but if i say

pet = someting <that something must be a int but

if u do it how i declare my continue

if (pet == something) continue; ?

if i get wrong the idea sorry

i have this question and i need to know what i can do on this

pd: i try that and dont works

Exekyela at 2007-7-12 21:00:38 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

You do not have to write another if statement to get the loop to continue.

your do-while loop looks like this

do {

...

try {

pet = Integer.parseInt(in.readline());

....

}

catch (Exception e)

{

e.printStackTrace();

// this is where I said you should set pet to something

}

} while (0 < pet)

if the string that in.readline() returns is not an integer, you get an exception (you know that already) and execution jumps to the catch (did you know that?).

What happens when the catch is done?

what makes the do-while loop stop or continue?

What value can you set pet to so that the loop will continue all by itself

without you having to write another if statement or a continue?

If you know the answer to the first two the answer to the third will be simple.

johndjra at 2007-7-12 21:00:38 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...