Codigo ejercicios
Upcoming SlideShare
Loading in...5
×
 

Codigo ejercicios

on

  • 856 views

 

Statistics

Views

Total Views
856
Views on SlideShare
856
Embed Views
0

Actions

Likes
0
Downloads
55
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Codigo ejercicios Codigo ejercicios Document Transcript

  • LIBRERIAS USADASimport javax.swing.JOptionPane;import java.applet.Applet;import java.awt.Color;import javax.swing.JApplet;import java.awt.Graphics;import javax.swing.*; EDAD EN UNA DECADA //VARIABLES String dato; double edad; dato=JOptionPane.showInputDialog("Ingrese su edad: "); edad=Double.parseDouble(dato); //FORMULA edad=edad+10; JOptionPane.showMessageDialog(this, "Su edad en una decada sera: "+edad);EDAD A PARTIR DE SU FECHA DE NACIMIENTO String dato; double fnac; dato=JOptionPane.showInputDialog("Ingrese el año de su Nacimiento: "); fnac=Double.parseDouble(dato); fnac=2011-fnac; JOptionPane.showMessageDialog(this, "Su edad es: "+fnac); MAYOR DE 5 NUMEROS String dato1; double num1; String dato2; double num2; String dato3; double num3; String dato4; double num4; String dato5; double num5; dato1=JOptionPane.showInputDialog("Ingrese el primer valor: "); num1=Double.parseDouble(dato1); dato2=JOptionPane.showInputDialog("Ingrese el segundo valor: "); num2=Double.parseDouble(dato2); dato3=JOptionPane.showInputDialog("Ingrese el tercer valor: "); num3=Double.parseDouble(dato3); dato4=JOptionPane.showInputDialog("Ingrese el cuarto valor: "); num4=Double.parseDouble(dato4); dato5=JOptionPane.showInputDialog("Ingrese el quinto valor: "); num5=Double.parseDouble(dato5);
  • if(((((num1 >= num2)&&(num1>=num3)&&(num1>=num4)&&(num1>=num5))))){ JOptionPane.showMessageDialog(this, "el numero mayor es: "+ num1); }else if(((((num2>=num1)&&(num2>=num3)&&(num2>=num4)&&(num2>=num5))))){ JOptionPane.showMessageDialog(this, "el numero mayor es: "+ num2);}else if(((((num3>= num1)&&(num3>=num2)&&(num3>=num4)&&(num3>=num5))))){ JOptionPane.showMessageDialog(this, "el numero mayor es: "+ num3);}else if(((((num4>=num1)&&(num4>=num2)&&(num4>=num3)&&(num4>=num5))))){ JOptionPane.showMessageDialog(this, "el numero mayor es: "+ num4);}else if(((((num5>=num1)&&(num5>=num2)&&(num5>=num3)&&(num5>=num4))))){ JOptionPane.showMessageDialog(this, "el numero mayor es: "+ num5);} ECUACIÓN String dato1; double a; String dato2; double b; String dato3; double c; dato1=JOptionPane.showInputDialog("Ingrese el valor de A: "); a=Double.parseDouble(dato1); dato2=JOptionPane.showInputDialog("Ingrese el valor de B: "); b=Double.parseDouble(dato2); dato3=JOptionPane.showInputDialog("Ingrese el valor de C: "); c=Double.parseDouble(dato3); if(b*b<4*a*c){JOptionPane.showMessageDialog(this, "Solucion perteneciente al campo de los numeros complejos");} else if(a!=0&&b*b>4*a*c) { JOptionPane.showMessageDialog(this,"La primera solucion es "+(-b+Math.sqrt(b*b-4*a*c))/(2*a)); JOptionPane.showMessageDialog(this,"La segunda solucion es "+(-b-Math.sqrt(b*b-4*a*c))/(2*a)); } else { JOptionPane.showMessageDialog(this,"la siguiente ecuacion no es de segundo grado"); }
  • INDICE DE MASA CORPORAL String dato1; double peso; String dato2; double altura; String dato3; double total; dato1=JOptionPane.showInputDialog("Ingrese su peso: "); peso=Double.parseDouble(dato1); dato2=JOptionPane.showInputDialog("Ingrese su altura en metros: "); altura=Double.parseDouble(dato2); total = peso / altura; if(total <= 16){ JOptionPane.showMessageDialog(this,"Criterio de ingreso a hospital"); }else if((total >16)&&(total <=17)){ JOptionPane.showMessageDialog(this,"Infrapeso");}else if((total>17 )&&(total<=18)){ JOptionPane.showMessageDialog(this,"bajo peso");}else if((total >18)&&(total <=25)){ JOptionPane.showMessageDialog(this,"Su peso es normal(saludable)");}else if((total >25)&&(total <=30)){ JOptionPane.showMessageDialog(this,"Usted tiene sobrepeso(obesidad de grado I)");}else if((total >30)&&(total <=35)){ JOptionPane.showMessageDialog(this,"Usted tiene sobrepeso cronico(obesida de grado II)");}else if((total >35)&&(total<=40)){ JOptionPane.showMessageDialog(this,"usted tiene obesidad premórbida(obesidad de grado III)");}else if(total > 40){ JOptionPane.showMessageDialog(this,"Usted tiene obesida mórbida(obesida de grado IV)");}
  • SUMA DE NUMEROS PARESString dato1; double total=0;for (int contador=2;contador<=1000;contador+=2) { total+=contador; } JOptionPane.showMessageDialog(this,"El total es: "+total); CALCULADORA CON IF String dato1; double n1;String dato2; double n2;String dato3; double suma;String dato4; double resta;String dato5; double multi;String dato6; double divi;String dato7; double opcion;dato1=JOptionPane.showInputDialog("Ingrese el primer valor: ");n1=Double.parseDouble(dato1);dato2=JOptionPane.showInputDialog("Ingrese el segundo valor: ");n2=Double.parseDouble(dato2); dato7=JOptionPane.showInputDialog("SUMA 1 RESTA 2 MULTIPLICACION 3 DIVISION 4: "); opcion=Double.parseDouble(dato7); if (opcion==1) {suma = n1+n2; JOptionPane.showMessageDialog(this,"El total de la Suma es: "+suma);} if (opcion==2) {resta = n1-n2; JOptionPane.showMessageDialog(this,"El total de la Resta es: "+resta);} if (opcion==3) {multi = n1*n2; JOptionPane.showMessageDialog(this,"El total de la Multiplicacion es: "+multi);} if (opcion==4) {divi = n1/n2; JOptionPane.showMessageDialog(this,"El total de la Division es: "+divi);}
  • CONVERSIÓN DE HORAS String dato1; double hora; String dato2; double minutos; String dato3; double segundos; String dato4; double hora1; String dato5; double minutos2=60; String dato6; double segundos3=3600; String dato7; double resul; String dato8; double resul1;dato1=JOptionPane.showInputDialog("Ingrese la hora: ");hora=Double.parseDouble(dato1);dato2=JOptionPane.showInputDialog("Ingres los minutos: ");minutos=Double.parseDouble(dato2);dato3=JOptionPane.showInputDialog("Ingrese los segundos: ");segundos=Double.parseDouble(dato3); resul= minutos2 / hora; resul1 = segundos3 / hora;JOptionPane.showMessageDialog(this,"la hora en minutos es: " + resul);JOptionPane.showMessageDialog(this,"la hora en segundos es: " + resul1); DETERMINA SI UN NUMERO ES PRIMO int numero=4; int i,aux=0; for (i=1;i<=numero;i++){ if (numero%i==0) aux++; } if (aux==2) JOptionPane.showMessageDialog(this,"el numero es primo"); else JOptionPane.showMessageDialog(this,"el numero no es primo");
  • CALCULADORA private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { int n1=Integer.parseInt(Text1.getText()); int n2=Integer.parseInt(Text2.getText()); int resta; resta=n1-n2; jLabel3.setText(String.valueOf(resta));} private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { int n1=Integer.parseInt(Text1.getText()); int n2=Integer.parseInt(Text2.getText()); int suma; suma=n1+n2; jLabel3.setText(String.valueOf(suma));} private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { int n1=Integer.parseInt(Text1.getText()); int n2=Integer.parseInt(Text2.getText()); int division; division=n1/n2; jLabel3.setText(String.valueOf(division));} private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { int n1=Integer.parseInt(Text1.getText()); int n2=Integer.parseInt(Text2.getText()); int producto; producto=n1*n2; jLabel3.setText(String.valueOf(producto));} private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0);
  • PROMEDIO private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0);} private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String nota; double n1; nota=JOptionPane.showInputDialog("Ingrese la Nota: "); n1=Double.parseDouble(nota); if (n1>=60) { JOptionPane.showMessageDialog(this,"APROBADO"); } else JOptionPane.showMessageDialog(this,"REPROBADO");} CASAimport java.applet.Applet;import java.awt.*;import java.awt.Graphics;public class casita extends Applet { public void paint(Graphics g){ dibujarCasa(g, 100, 100, 100, 100); } private void dibujarCasa(Graphics g, int inferiorX, int inferiorY, int base, int altura){ g.drawLine(inferiorX, inferiorY, inferiorX + base, inferiorY); g.setColor(Color.green); //g.drawLine(inferiorX + base, inferiorY, inferiorX + base/2); g.drawLine(inferiorX + base/2, inferiorY - altura, inferiorX, inferiorY); g.drawLine(inferiorX + base, inferiorY, inferiorX + base/2, inferiorY - altura); g.setColor(Color.yellow); g.fillRect(base, base, base, altura); //g.drawRect(80, 200, 100, 100); g.drawRect(base, base, base, altura); }}
  • FIGURASpackage TAREAS;import java.applet.Applet;import java.awt.Color;import javax.swing.JApplet;import java.awt.Graphics;import javax.swing.*;public class FIGURAS extends Applet { public void init() { } public void paint(Graphics x){ super.paint(x); x.drawRect(15, 15, 100, 60); x.drawOval(150, 15, 60, 60); x.drawRect(15, 100, 100, 60); x.setColor(Color.red); x.fillRect(15, 100, 100, 60); x.drawOval(150, 100, 60, 60); x.setColor(Color.blue); x.fillOval(150, 100, 60, 60); }} FAMILIAimport java.applet.Applet;import java.awt.Graphics;import java.awt.Color;public class familiacompleta extends Applet { public void paint(Graphics x){ super.paint(x); //Padre x.setColor(Color.red); x.drawOval(100, 20, 100, 100); x.drawRect(100, 120, 100, 150); x.drawRect(90, 120, 10, 10); //hombros x.drawRect(200, 120, 10, 10); //hombros x.drawRect(80, 120, 10, 100); //brazos x.drawRect(210, 120, 10, 100); //brazos x.drawRect(120, 270, 20, 100); //piernas x.drawRect(160, 270, 20, 100); //piernas
  • x.drawString("El Papa",125,200); //madre x.setColor(Color.yellow); x.drawOval(335, 20, 100, 100); x.drawRect(335, 120, 100, 150); x.drawRect(325, 120, 10, 10); //hombros x.drawRect(435, 120, 10, 10); //hombros x.drawRect(315, 120, 10, 100); //brazos x.drawRect(445, 120, 10, 100); //brazos x.drawRect(350, 270, 20, 100); //piernas x.drawRect(400, 270, 20, 100); //piernas //hijo x.setColor(Color.blue); x.drawOval(550, 100, 75, 75); x.drawRect(550, 175, 75, 80); x.drawRect(540, 175, 10, 10); //hombros x.drawRect(625, 175, 10, 10); //hombros x.drawRect(530, 175, 10, 50); //brazos x.drawRect(635, 175, 10, 50); //brazos x.drawRect(565, 255, 10, 50); //piernas x.drawRect(600, 255, 10, 50); //piernas //hija x.setColor(Color.pink); x.drawOval(700, 100, 75, 75); x.drawRect(700, 175, 75, 80); x.drawRect(690, 175, 10, 10); //hombros x.drawRect(775, 175, 10, 10); //hombros x.drawRect(680, 175, 10, 50); //brazos x.drawRect(785, 175, 10, 50); //brazos x.drawRect(715, 255, 10, 50); //piernas x.drawRect(750, 255, 10, 50); //piernas }}
  • Universidad Mariano Galvez Sede RetalhuleuCATEDRÁTICO: Ing. Alver BeltetonCURSO: Programación Avanzada CODIGOS FUENTES DE EJERCICIOS Carlos García Fuentes 2890-10-1140