Professional Documents
Culture Documents
PROGRAMAS
Sandra Garzón
sandragarzon26@hotmail.com
Sandra Guzmán
sayis85@hotmail.com
Jorge Luis Quitian Quitian
george_740@hotmail.com
}
RESUMEN: A continuación veremos unos ca=Integer.parseInt(a);
programas creados en lenguaje orientado a objetos, son // Condición para no ingresar un valor negativo
programas sencillos pero bastante útiles. while(ca<0)
{
1 INTRODUCCIÓN a=JOptionPane.showInputDialog("POR
FAVOR INGRESE LA MEDIDA DEL PRIMER LADO EN
CENTIMETROS");
En este “paper” encontraremos ejemplos de
programas de nivel básico donde observaremos la //Condición para que no ingresen caracteres
sintaxis de Java, clases, Objetos y posibles caos en los while(!esnumero(a)){
programas con su respectiva solución. a=JOptionPane.showInputDialog("POR
FAVOR INGRESE LA MEDIDA DEL PRIMER LADO EN
2 PROGRAMAS CENTIMETROS");
}
ca=Integer.parseInt(a);
2.1 PROGRAMA PARA HALLAR EL AREA }
DE UN TRIANGULO CON LA FORMULA
A= T(T-S1)(T-S2)(T-S3) //Solicitar un dato al usuario y almacenarlo en
una variable
1. Requerimientos: a,b,c.
b=JOptionPane.showInputDialog("POR FAVOR
INGRESE LA MEDIDA DEL SEGUNDO LADO EN
2. Variables que Interviene: CENTIMETROS");
String a,b,c; //Condición para que no ingresen caracteres
int ca,cb,cc,p,t,p1,p2,iperi2,perimetro=0;
while(!esnumero(b)){
3. Caos: Cuando en la variable a,b ó c ingresen b=JOptionPane.showInputDialog("POR
<0,ó algún carácter. FAVOR INGRESE LA MEDIDA DEL SEGUNDO LADO
EN CENTIMETROS");
// Librería }
import javax.swing.*; cb=Integer.parseInt(b);
// Condición para no ingresar un valor negativo
public class areas {
while(cb<0)
public static void main(String[] args) { {
b=JOptionPane.showInputDialog("POR
//Variables FAVOR INGRESE LA MEDIDA DEL SEGUNDO LADO
String a,b,c; EN CENTIMETROS");
int while(!esnumero(b)){
ca,cb,cc,p=0,t=0,p1=0,p2=0,iperi2=0,perimetro=0; b=JOptionPane.showInputDialog("POR
//Solicitar un dato al usuario y almacenarlo en FAVOR INGRESE LA MEDIDA DEL SEGUNDO LADO
una variable EN CENTIMETROS");
a=JOptionPane.showInputDialog("POR FAVOR }
INGRESE LA MEDIDA DEL PRIMER LADO EN cb=Integer.parseInt(b);
CENTIMETROS");
//Condición para que no ingresen caracteres }
while(!esnumero(a)){
a=JOptionPane.showInputDialog("POR c=JOptionPane.showInputDialog("POR FAVOR
FAVOR INGRESE LA MEDIDA DEL PRIMER LADO EN INGRESE LA MEDIDA DEL TERCER LADO EN
CENTIMETROS"); CENTIMETROS");
1
Programas.Teoría General de Sistemas
.
1. Requerimientos: a,b,c.
3 PROGRAMA DE NUMEROS IMPARES 2. Variables que Interviene:
int v1,v2,v3,vt,vm,s,np;
1. Requerimientos: a. String sv;
2
Programas.Teoría General de Sistemas
.
sv=JOptionPane.showInputDialog("¡¡DATO
ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE
// Librería LA PRIMERA VENTA");
}
v2=Integer.parseInt(sv);
import javax.swing.*; }
public class vendedor { //Solicitar un dato al usuario y almacenarlo en
una variable
public static void main(String[] args) {
int v1=0,v2=0,v3=0,vt=0,vm=0,s=515000,np=0; sv=JOptionPane.showInputDialog("POR FAVOR
String sv; INGRESE EL VALOR DE LA TERCERA VENTA");
while(!esnumero(sv)){
//Solicitar un dato al usuario y almacenarlo en sv=JOptionPane.showInputDialog("POR FAVOR
una variable INGRESE EL VALOR DE LA TERCERA VENTA");
}
v3=Integer.parseInt(sv);
sv=JOptionPane.showInputDialog("POR FAVOR
INGRESE EL VALOR DE LA PRIMERA VENTA"); // Condición para no ingresar un valor negativo
//Condición para que no ingresen caracteres while(v3<0){
sv=JOptionPane.showInputDialog("¡¡DATO
while(!esnumero(sv)){ ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE
sv=JOptionPane.showInputDialog("¡¡DATO LA PRIMERA VENTA");;
ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE while(!esnumero(sv)){
LA PRIMERA VENTA"); sv=JOptionPane.showInputDialog("¡¡DATO
} ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE
v1=Integer.parseInt(sv); LA PRIMERA VENTA");
}
// Condición para no ingresar un valor negativo v3=Integer.parseInt(sv);
}
while(v1<0){ vm=v1+v2+v3;
sv=JOptionPane.showInputDialog("¡¡DATO vt=(vm*10)/100;
ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE np=s+vt;
LA PRIMERA VENTA");;
while(!esnumero(sv)){ JOptionPane.showMessageDialog(null,"TOTAL DE
sv=JOptionPane.showInputDialog("¡¡DATO VENTAS DEL MES: "+vm+"\n\n TOTAL NETO A
ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE PAGAR: "+np+"\n\n TOTAL COMISIONDEL MES:
LA PRIMERA VENTA"); "+vt);
}
v1=Integer.parseInt(sv); }
}
// Este código nos permite que cada vez que
//Solicitar un dato al usuario y almacenarlo en ingresen un dato comprueba si es numero o carácter
una variable
public static boolean esnumero(String cadena) {
sv=JOptionPane.showInputDialog("POR FAVOR try{Integer.parseInt(cadena);
INGRESE EL VALOR DE LA SEGUNDA VENTA"); return true;}
while(!esnumero(sv)){
sv=JOptionPane.showInputDialog("POR FAVOR catch (NumberFormatException nfe){
INGRESE EL VALOR DE LA SEGUNDA VENTA"); return false;}
} }
v2=Integer.parseInt(sv); }
// Condición para no ingresar un valor negativo
5 PROGRAMA PRESUPUESTO
while(v2<0){ HOSPITAL
sv=JOptionPane.showInputDialog("¡¡DATO 1. Requerimientos: a,b,c,d
ERRADO!!"+"\n POR FAVOR INGRESE EL VALOR DE 2. Variables que Interviene:
LA PRIMERA VENTA"); int a,b,c,d;
String as;
//Condición para que no ingresen caracteres
while(!esnumero(sv)){
3
Programas.Teoría General de Sistemas
.
4
Programas.Teoría General de Sistemas
.
dnum=JOptionPane.showInputDialog("POR resp=dat-dat2;
FAVOR INGRESE UN NUMERO");
num=Integer.parseInt(dnum); JOptionPane.showMessageDialog(null, "EL
RESULTADO ES: "+resp);
if (num<0)
{ }
//Solicitar un dato al usuario y almacenarlo en
una variable para limitar el contador }
slim=JOptionPane.showInputDialog("POR FAVOR }
INGRESE EL LIMITE");
lim=Integer.parseInt(slim);
for(a=0;a<lim;a+2) 8 PROGRAMA NUMEROS INFINITOS
{ // Librería
import javax.swing.*;
public class infinitos{
if(a%4!=0)
{
public static void main(String[] args) {
}
else
{ for(int a=1;a<0;a++){
r1+=a;
} JOptionPane.showMessageDialog(null, "No. "+a);
} }
}
}