Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 37

Programas en NetBeans (Java)

1. Programa Que gneros la Suma de 2 Nmeros ingresados por El usuario


Clase (sumador) paquete pckSumador; public class sumador { / / Atributos-variables de Instancia. private int num1; private int num2; / / Metodos (Constructor - Convencional). pblica sumador (int num1, int num2) { this.num1 = num1; this.num2 = num2; } pblica sumador () { this.num1 = 0; this.num2 = 0; } public int GenerarSuma () { int suma = this.num1 + this.num2; volver suma; }

} Clase Principal (Principal) paquete pckSumador; import java.io. *; Principal public class {

/ / Objetos Leer Datos Teclado. public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer); public static void main (String [] args) throws IOException { System.out.print ("Ingrese valor 1:");

int Valor1 = Integer.parseInt (Teclado.readLine ()); System.out.print ("Ingrese valor 2:"); int valor2 = Integer.parseInt (Teclado.readLine ()); Sumador Obj1 = new sumador (Valor1, valor2); int resul = Obj1.GenerarSuma (); System.out.println ("Resultado =" + resul); } } Ejecucion del Programa

2. Programa en el Cual s ejecucin sin Proceso Que permite leer 10 Valores Numricos desde el teclado, verificar Cuales y CUANTOS hijo Nmeros perfectos. Clase (Perfecto)
paquete pcknumeroperfecto; public class Perfecto { valor int privado; pblica Perfecto () { this.valor = 0; } public boolean VerificarPerfecto (int valor) { this.valor = valor; int suma = 0, t = 1; while (t <this.valor) { / / Si this Residuo es Igual a 0

if (this.valor% t == 0) suma + = t; t + +; } if (suma == this.valor) return true; ms return false; } }

Clase Principal (Principal)


paquete pcknumeroperfecto; import java.io. *; Principal public class { public static InputStreamReader leer = new InputStreamReader (System.in); public static BufferedReader teclado = new BufferedReader (leer); public static void main (String [] args) throws IOException { System.out.println ("Ingrese 10 Valores ...!"); int num = 0, cont = 0; Perfecto Perfecto miercoles = new (); for (int i = 1; i <= 10, i + +) { num = Integer.parseInt (teclado.readLine ()); if (miercoles.VerificarPerfecto (num)) { System.out.println ("Numero Perfecto =" + num); cont + +; } } System.out.println ("existencial Numeros Perfectos:" + cont); }

} Ejecucion del Programa

3. Implementar Una Clase Que permita leer 10 Valores o Nmeros Aleatorios determinando Cuales de Ellos hijo Nmeros primos. Clase (Aleatorios)
packaleatorio paquete; Aleatorio public class { valor int privado; Aleatorio pblica () { this.valor = 0; } setValor public void (int valor) { this.valor = valor; } public boolean VerificarSiNoPrimo () { int cont = 0; for (int p = 1, p <= this.valor; p + +) { if (this.valor% p == 0) cont + +; } if (cont <= 2) return true;

ms return false; } }

Clase Principal (Principal)


packaleatorio paquete; importar java.util.Random; director public class { public static void main (String [] args) { / Cdigo TODO lgica / solicitud aqu Random RND = new Random (); Aleatorio Aleatorio viernes = new (); for (int i = 1; i <= 10, i + +) { int num = rnd.nextInt (30); viernes.setValor (num); if (viernes.VerificarSiNoPrimo ()) System.out.println ("es sin numero primo: "+ num); ms System.out.println ("no es numero primo: "+ num); } } Ejecucion del Programa }

4. Programa Que calcula Distancia entre tareas pendientes Puntos Clase (Distancia,)
pckDistpuntos paquete; public class Distancia, { x1 int privado; int x2 privado; private int y1; private int y2; pblico Distancia, (int x1, x2 int, int y1, int y2) { this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; } doble Dis pblico (int x1, x2 int, int y1, int y2) { Resultado doble; doble res1, res2; res1 = this.x2-this.x1; res2 = this.y2-this.y1; res1 = Math.pow (res1, 2) + Math.pow (res2, 2); resultado = Math.sqrt (res1); return resultado; } }

Clase Principal (Principal)


pckDistpuntos paquete; import java.io. *; Principal public class { / / Objetos Leer Datos Teclado.

public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer);

public static void main (String [] args) throws IOException { System.out.print ("Ingrese valor 1 de x:"); int Valor1 = Integer.parseInt (Teclado.readLine ()); System.out.print ("Ingrese valor de 2 x:"); int valor2 = Integer.parseInt (Teclado.readLine ()); System.out.print ("Ingrese valor de 1 y:"); int val1 = Integer.parseInt (Teclado.readLine ()); System.out.print ("valor Ingrese 2 de y:"); int val2 = Integer.parseInt (Teclado.readLine ()); Distancia, Obj1 = new Distancia, (Valor1, valor2, val1, val2); doble resul = Obj1.Dis (Valor1, valor2, val1, val2); System.out.println (resul); } } Ejecucion del Programa

5.Programa Sobre CuentaBancaria (Deposito, Retiros, Transacciones) Clase (Cuenta)


paquete Cuenta1; public class Cta { float Saldo privado;

nom charla privada; int n_cta privado; int n_ci privado; flotador privado saldo_ad; Cta pblica () { this.saldo = 0; this.n_cta = 0; this.n_ci = 0; } pblica Cta (float Saldo, charlas nom, n_cta int, int n_ci) { this.saldo = Saldo; this.nom = nom; this.n_cta = n_cta; this.n_ci = n_ci; } pblica Cta (float saldo_ad) { this.saldo_ad = saldo_ad; } flotador Dep. pblica (flotador t) { this.saldo = this.saldo + t; volver this.saldo; } public boolean Ret (float r) { si (r <= this.saldo) { this.saldo = this.saldo-r; return true; } Else { return false;} }

Saldo pblico flotador (flotador s) { s = this.saldo; volver s; } pblica TranferenciaBancaria float (flotar a) { this.saldo = this.saldo-a; this.saldo_ad = this.saldo_ad + a; volver this.saldo_ad; } }

Clase Principal (Principal)


paquete Cuenta1; import java.io. *; Principal public class { public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer); void (String [] args) public static throws IOException { int op; do { System.out.println ("\ n \ t \ t \ t \ t \ tCuenta Bancaria"); System.out.println ("\ t \ t \ t \ t \-T1, Deposito"); System.out.println ("\ t \ t \ t \ t \ t2.-Retiro"); System.out.println ("\ t \ t \ t \ t \ t3.-Consulta de sado"); System.out.println ("\ t \ t \ t \ t \ t4.-Transferencia"); System.out.println ("\ t \ t \ t \ t \ t5.-Salir"); System.out.println ("\ nIngresar la opcion:"); op = Integer.parseInt (Teclado.readLine ()); switch (op) { caso 1:

int n_c = 0, C_d = 0; System.out.println ("Deposito");

System.out.println ("Ingrese la CANTIDAD Que va a Depositar:"); C_d = Integer.parseInt (Teclado.readLine ()); Cta obj = new Cta (); float d = Obj.Dep (C_d); System.out.println ("Su Saldo actual es:" + d); break; caso 2: int nc = 0, c_r = 0; booleano s = true; System.out.println ("Retiro"); System.out.println ("Ingrese la CANTIDAD Que va a Borrarse:"); c_r = Integer.parseInt (Teclado.readLine ()); Cta Obj2 Cta = new (); if (s == Obj2.Ret (c_r)) { System.out.println ("Su Saldo actual:" + s); } else { System.out.println ("Saldo Insuficiente"); } break; Caso 3: n_c1 int = 0; float cs = 0; System.out.println ("Consulta de Saldo"); Cta Obj3 Cta = new (); cs = Obj3.Saldo (cs); System.out.println ("Su Saldo es:"); break;

Caso 4: n_c2 int = 0; float trans = 0, m = 0; System.out.println ("Transferencia bancaria"); System.out.println ("Ingrese la CANTIDAD Que va a Transferir:"); trans = Integer.parseInt (Teclado.readLine ()); Cta Obj4 Cta = new (); m = Obj4.TranferenciaBancaria (m); break; } } While (op! = 4); } } Ejecucion del Programa

6. Programa de las Naciones Unidas Sobre vehiculo (Si this estacionado, si DESEA arrancar, acelerar, frenar) Clase A (automtico)
pckAut paquete; public class Auto { privada auto int; Auto pblico (int auto) {

this.auto = auto; } public int acelerar (int as) { this.auto = as; volver this.auto; } public int frenar (int fre) { this.auto = this.auto-fre; volver this.auto; } aceleracion public int (int masace) { this.auto = this.auto + masace; volver this.auto; } }

Clase Principal (Principal)


pckAut paquete; import java.io. *;

public class PrincipalAuto { public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer); public static void main (String [] args) throws IOException { System.out.println ("vehiculo estacionado");

System.out.println ("DESEA arrancar [1/0]");

int a = Integer.parseInt (Teclado.readLine ()); if (a == 1) { System.out.println ("con Que VELOCIDAD DESEA arrancar");

int j = Integer.parseInt (Teclado.readLine ()); int c = 0; mientras que (c <j) { C + +; System.out.println (c + "km / h");} Obj = new Auto Auto (j); int as = obj.acelerar (j); System.out.println ("su VELOCIDAD es" + as); System.out.println ("DESEA acelerar [1/0]");

int as = Integer.parseInt (Teclado.readLine ()); if (as == 1) {

System.out.println ("Ingrese Cuanto DESEA acelerar"); int ret = Integer.parseInt (Teclado.readLine ());

int dis = obj.aceleracion (ret); j = des; mientras que (c <j) { C + +; System.out.println (c + "km / h"); } System.out.println ("su velosidad es" + j); } System.out.println ("DESEA frenar [1/0]"); int f = Integer.parseInt (Teclado.readLine ()); si (f == 1) { System.out.println ("CUANTOS km / h DESEA frenar]"); int d = Integer.parseInt (Teclado.readLine ());

si (d <= j) { int r = obj.frenar (d); j = r; while (C! = j) { c -; System.out.println (c + "km / h");} System.out.println ("su VELOCIDAD es es real" + j); if (j == 0) System.out.println ("vehiculo estacionado");

} Else System.out.println ("no Florerias frenar mas de Lo Que marca el velocmetro");

}}}} Ejecucion del Programa

7. Programa Que transformacin sin numero de decimales a (Binario, Octal y Hexadecimal) Clase Transformar Numricos paquete;
clase ClaseBinaria {public int valour privado; ClaseBinaria pblica () { this.valor = 0; } public void setvalor (int valor) {

} public int [] tb () { int [ ] ve = new int [30]; int ve; } public int [] para () { int [] vec = new int [30]; int i = 0; { vec [i] = this.valor% 8; this.valor = this.valor / 8, i + +; }

this.valor = valor;

while (this.valor> 0)

while (i <30) { vec [i] = 5; i + +; } vec return; } coche public void () { cadena res = Integer.toHexString (this.valor); System.out.println (res); } }

Clase director (Principal)


Clase Principal:

Numricos paquete; import java.io. *; Principal public class { InputStreamReader Leer = new InputStreamReader (System.in) estticos pblicos; public static BufferedReader Teclado = new BufferedReader (Leer); void (String [] args) static throws IOException { int [ ] v = new int [30], int [] b = new int [30]; ClaseBinaria bina ClaseBinaria = new (); System.out.println ("Ingrese sin numero");

int valor = Integer.parseInt (Teclado. readLine ()); bina.setvalor (valor); int t; do { System.out.println ("Escoja 1 binario octal 2 3 4 hexadesimal Salir"); t = Integer.parseInt (Teclado.readLine ()); interruptor (t) { caso 1: v = bina.tb (); for (int i = 19; i> = 0; i -) { if (v [i] = 5) { System.out.print (v [i]);}} System.out.println (""); break; caso 2: bina.setvalor (valor), b = bina.to (); for (int i = 19; i> = 0; i -) { if (b [i] = 5) {! System.out.print (b [i]);}} System.out.println (""); break; caso 3: bina.setvalor (valor) ; System.out.println ("el valor en hexadesimal es"); bina.car (); break; } } while (t <4); } }

Ejecucion del Programa

8.Implementar ONU Programa Que permita realizar divisiones Por Medio de Restas. CLASE NORMAL
paquete pckdivisin;

divi_restas public class { divisor int privado; dividendo int privado; divi_restas pblicos (int divisor, dividendo int) { this.divisor = divisor; this.dividendo = dividendo; } division_restas public void () { int contador = 0, cociente = 0; do { cociente = this.divisor-this.dividendo; contador + +; divisor = cociente +; } Mientras que (cociente> = this.dividendo); System.out.println ("Resultado:" + contador); System.out.println ("Residuo: "+ cociente); } }

CLASE PRINCIPAL
paquete pckdivisin; import java.io. *; Principal public class { public static InputStreamReader leer = new InputStreamReader (System.in); public static BufferedReader teclado = new BufferedReader (leer); public static void main (String [] args) throws IOException { System.out.println ("Ingrese el Nmero Que va un servicio divisor"); int Valor1 = Integer.parseInt (teclado.readLine ()); System.out.println ("Ingrese el Nmero Que va un servicio dividendo"); int valor2 = Integer.parseInt (teclado.readLine ()); divi_restas Objeto = new divi_restas (Valor1, valor2); Objeto.division_restas (); } } ejecucion del Programa

9.Programa Que permite Calcular rea Radio y Dimetro del Crculo Clase Diametro
pckRadio paquete; public class Diametro { private int x, y; Radio int privado; setX public void (int x) { this.x = x; } public void setY (int y) { this.y = y; } public void setRadio (int radio) { this.radio = Radio; } Diametro pblica () { this.x = 0; this.y = 0; this.radio = 0; } doble CalcularArea pblica () { double zona; ra int = 0; double pi = Math.PI; area = pi * Math.pow (ra, 2), del rea de vuelo; } doble CalcularDiametro pblica () { double diametro; doble rad = 0; diametro = 2 * rad; regreso diametro; } / / public boolean VerificarSiNoDentro () / int cont /; }

Clase Principal (Principal)


paquete pckRadio; import java.io. *; Principal clase pblica { public static InputStreamReader Leer = new InputStreamReader (System.in) public static BufferedReader Teclado = new BufferedReader (Leer) public static void main (String [] args) throws IOException { System.out.println ("rea Calcular"); System.out.println ("Ingrese valor de x"); int Valor1 = Integer.parseInt ( Teclado.readLine ()); System.out.println ("Ingrese valor de y"); int valor2 = Integer.parseInt (Teclado.readLine ()); System.out.println ("Ingrese el radio"); int valor3 = Integer.parseInt (Teclado.readLine ()) ; Test37 obj = new Test37 () = obj.CalcularArea () de doble zona; ;: System.out.println ("el rea es") (rea System.out.println ); System.out.println ("Calcular diametro"); System.out.println ("Ingrese valor de x"); int val1 = Integer.parseInt (Teclado.readLine ()); System.out.println ("Ingrese valor de y "); int val2 = Integer.parseInt (Teclado.readLine ()); System.out.println ("Ingrese el diametro"); int val = Integer.parseInt (Teclado.readLine ()); Test37 obj2 = nueva Test37 (); doble diametro = obj2.CalcularDiametro (); System.out.println ("el diametro es:"); System.out.println (diametro); / / * doble x1, y1; / / System.out . println ("Calcular DISTANCIA"); / / System.out.println ("Ingrese valor de x1"); / / x1 = Integer.parseInt (Teclado.readLine ()); / / System.out.println ("Ingrese valor de y1 "); / / y1 = Integer.parseInt (Teclado.readLine ()) / / } } Ejecucion del Programa

10.Generar Una Clase Que Reciba COMO Parmetro 2 VectorEs y Que esta Clase contenga Nmeros randomicos, demostrar Teora de Conjuntos (Unin, Interseccin, Producto Cartesiano) Clase Vector
paquete Packrandom; import java.io. *; importar java.util.Random; Vector public class { public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer); private int [] a = new int [5]; private int [] b = new int [5]; Vector pblica () { this.a [0] = 0; this.b [0] = 0; } LLenar public void () { int n = 0;

Random RND = new Random (); for (int i = 0; i <5; i + +) { n = rnd.nextInt (10); this.a [i] = n; } for (int i = 0; i <5; i + +) { n = rnd.nextInt (10); this.b [i] = n; } }

Mostrar public void () throws IOException { System.out.println ("primer vector"); for (int i = 0; i <5; i + +) { System.out.println (this.a [i]); } System.out.println ("second vector"); for (int o = 0, o <5, o + +) { System.out.println (this.b [o]); } } Producto public void () { int [] c = new int [5]; for (int h = 0, h <5; h + +) { for (int i = 0; i <5; i + +) { c [h] + = this.a [h] * this.b [i]; } } / / Return s; for (int h = 0, h <5; h + +) { System.out.println (c [h]); }} Unin public void () throws IOException {

int l = 0; for (int h = 0, h <5; h + +) { for (int i = 0; i <5; i + +) { if (this.a [h] == this.b [i]) { this.b [i] = 11; l + +; } }} int [] c = new int [10 l]; int i; for (i = 0; i <5; i + +) { if (i <= 5) { c [i] = a [i]; } } Int v = 5; for (int m = 0, m <5; m + +) { if (b [m] <11) { c [v] = b [m]; v + +; } } System.out.println ("unin de vector "); for (int d = 0, d <10 l, d + +) { System.out.println (c [d]); } } }

Clase Principal (Principal)


paquete Packrandom; import java.io. *; Principal public class {

public static InputStreamReader Leer = new InputStreamReader (System.in); public static BufferedReader Teclado = new BufferedReader (Leer); public static void main (String [] args) throws IOException { Vector miercoles = new Vector (); miercoles.LLenar (); miercoles.Mostrar (); System.out.println ("unin"); miercoles.Union (); / / Int [] m = new int [10]; System.out.println ("Producto"); miercoles.Producto (); } } Ejecucion del Programa

11.Programa Que permite ELEVAR UN Nmero ONU un exponente a Travs De Una Potencia Clase Potencia

Paquete del paquete; Clase public class { int n1 privado; n2 int privado;

Clase pblica (int n1, n2 int) { this.n1 = n1; this.n2 = n2; } setvalor public void (int n1, n2 int) { this.n1 = n1; this.n2 = n2; } coche public int () { int r = 0, f = 1; for (int i = 0; i <n2, i + +) {r = 0; for (int j = 0; j <n1, j + +) { r + = f; } f = r; } volver (f); } public int bivi (int n1, n2 int) { int i = 0; mientras que (this.n1> = this.n2) { this.n1 = this.n1-this.n2; i + +; } volver (i);}

Clase Principal (Principal)


Paquete del paquete; import java.io. *; public class Pri { public static InputStreamReader L = new InputStreamReader (System.in); public static BufferedReader T = new BufferedReader (L); public static void main (String [] args) throws IOException { System.out.println ("Ingrese la base"); int a = Integer.parseInt (T.readLine ()); System.out.println ("Ingrese la Potencia"); int b = Integer.parseInt (T.readLine ()); Clase car1 = new Class (a, b); int r = car1.car (); System.out.println ("El Resultado es: "+ r); System.out.println ("Ingrese el divisor"); int c = Integer.parseInt (T.readLine ()); System.out.println ("Ingrese el dividendo"); int d = Integer.parseInt (T.readLine ()); car1.setvalor (c, d); int f = car1.bivi (c, d); System.out.println ("El Resultado es: "+ f); } } Ejecucion del Programa

Aplicaciones Graficas
12.Programa Que permite Calcular el rea y Radio del Crculo JFrame: Clase Que permite Crear el Objeto JPanel: Es la Clase Donde s Realizan los dibujos Clase Clculos
paquete appdibujarcirculocalculararea; Calculos public class { Xo private int, Yo; X1 int privado, Y1; Calculos pblicos (Xo int, int Yo, X1 int, int Y1) { this.Xo = Xo; this.Yo = Yo; this.X1 = X1; this.Y1 = Y1; } DistanciaPuntos dobles privadas () { doble d = Math.sqrt ((Math.pow ((this.X1 - this.Xo), 2)) + (Math.pow ((this.Y1 - this.Yo), 2))); volver d; } doble AreaCirculo pblico () { doble DISTANCIA = this.DistanciaPuntos (); doble de radio = DISTANCIA / 2; double area = Math.PI * Math.pow (radio, 2); regresar zona; } }

JPanel

appdibujarcirculocalculararea paquete; java.awt.Graphics importacin; import java.awt *;. Panel clase pblica se extiende javax.swing.JPanel { private int Xo, Yo, int X1 privada, Y1; setX1 public void (int X1) { this.X1 = X1; } public void setxo (int Xo) { = Xo this.Xo; } public void setY1 (int Y1) { this.Y1 = Y1; } public void Setyo (int Yo) { this.Yo = Yo; } pblica Panel () { initComponents (); } @ SuppressWarnings ("sin marcar") / / initComponents private void () { javax.swing.GroupLayout layout = new 400, 300, Short.MAX_VALUE) ); } / / @ Override pblica void paint (Graphics g) { super.paint (g); g.setColor (Color.red); g.drawOval (this.Xo, this.Yo, este . X1, this.Y1); Calculos obj = new Calculos (this.Xo, this.Yo, this.X1, this.Y1), doble a = Obj.AreaCirculo (); Cadena Cadena = "Area =" + String. valueOf (a); g.drawString (Cadena, 10, 15); } public void DibujarCirculo () { repaint (); } / / Variables declaracin - No se puede modificar / / Fin de la declaracin de las variables }

JFrame
paquete appdibujarcirculocalculararea; Principal public class extends javax.swing.JFrame { @ SuppressWarnings ("sin marcar") / / initComponents private void () { jPanel1 javax.swing.JPanel = new (); jLabel1 javax.swing.JLabel = new (); textX0 = new javax.swing . JTextField (); jLabel2 javax.swing.JLabel = new (); jLabel3 javax.swing.JLabel = new (); jLabel4 javax.swing.JLabel = new (); texty0 javax.swing.JTextField = new (); textX1 javax.swing.JTextField = new (); texty1 javax.swing.JTextField = new (); btngraficar javax.swing.JButton = new (); jLabel6 javax.swing.JLabel = new (); jLabel5 = new javax.swing. JLabel (); panel1 = new java.awt.Color (102, 102, 255)); setCursor (nueva java.awt.Color (0, 153, 153)); jPanel1.setBorder (nueva javax.swing.border.SoftBevelBorder (javax.swing.border.BevelBorder.RAISED)); jLabel1.setFont (nueva java.awt.Font ( "Tahoma", 1, 11)); jLabel1.setForeground (nueva java.awt.Color (255, 255, 255)); jLabel1.setText ("X0:"); jLabel2.setFont (nueva java.awt.Font ( "Tahoma", 1, 11)); jLabel2.setForeground (nueva java.awt.Color (255, 255, 255)); jLabel2.setText ("Y0:"); jLabel3.setFont (nueva java.awt.Font ( "Tahoma", 1, 11)); jLabel3.setForeground (nueva java.awt.Color (255, 255,

255)); jLabel3.setText ("x1:"); jLabel4.setFont (nueva java.awt.Font ( "Tahoma", 1, 11)); jLabel4.setForeground (nueva java.awt.Color (255, 255, 255)); jLabel4.setText ("y1"); btngraficar.setText ("Graficar"); btngraficar.addActionListener (nueva java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { btngraficarActionPerformed (evt); } }); jLabel6.setFont (nueva java.awt.Font ("Tahoma", 1, 11)); jLabel6.setForeground (nueva java.awt.Color (255, 255, 255)); jLabel6.setText ("Zona Java 2011"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) . addGap (69, 69, javax.swing.GroupLayout.PREFERRED_SIZE, de 38 aos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLay out.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) . addComponent (texty1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)) . addGap (36, 36, 36 ) . addComponent (btngraficar) . addContainerGap ()) . addComponent (jLabel6, 49, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) . addComponent (jLabel3) . addComponent (textX1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) . addComponent (texty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout . PREFERRED_SIZE)) . addContainerGap (javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) . addgroup (javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup () . addContainerGap (59, Short.MAX_VALUE) . addComponent ( btngraficar) . addGap (15, 15, 15) . addComponent (jLabel6)) ); jLabel5.setFont (nueva java.awt.Font ("Vineta BT", 0, 18)); jLabel5.setText ("CIRCULO CALCULO DE REA "); javax.swing.GroupLayout panel1Layout = new 387, 133, Short.MAX_VALUE) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)) . addgroup (layout.createSequentialGroup () . addContainerGap () . addComponent (panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) . addContainerGap (31 , layout.createSequentialGroup () . addComponent (jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) . addGap (18, 18, 18) . addComponent (jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); pack (); } / / private void btngraficarActionPerformed (java.awt.event.ActionEvent evt) { int Xo = Integer.parseInt (this.textX0.getText ()); int Yo = Integer.parseInt (this.texty0.getText ()); int X1 = Integer.parseInt (this.textX1.getText ()); int Y1 = @ Param args argumentos de la lnea de comandos * / public static void main (String args []) { java.awt.EventQueue.invokeLater (nueva Runnable () { public void run () { nuevo director () setVisible (true). } }); } / / Variables declaracin - no modifican btngraficar privado javax.swing.JButton; privado javax.swing.JLabel jLabel1; javax.swing.JLabel privado jLabel2; javax.swing.JLabel privado jLabel3; javax.swing.JLabel privado jLabel4; javax.swing.JLabel privado jLabel5; javax.swing.JLabel privado jLabel6; javax.swing.JPanel privado

jPanel1; appdibujarcirculocalculararea.Panel privado panel1; javax.swing.JTextField privado textX0; javax.swing.JTextField privado textX1; javax privado . swing.JTextField texty0; javax.swing.JTextField privado texty1; / / Fin de la declaracin de las variables }

ejecucion del Programa:

13.Programa con Herencia Clase Principal


Principal public class {

void (String [] args) public static { System.out.println ("Creando Objeto Empleado ....");

/ / Cadena de carga, String Departamento, mucho Cdula, Nombres de cadena, int EDAD Empleado Juan = new Empleado ("Director", "Sistemas", "12034576891", "Mariuxi Lpez", 35); Juan.DatosInformativos (); System.out.println (Juan.CalcularSueldo (60,18));

System.out.println ("Creando Objeto Estudiante ...."); / / Cadena Colegio, String Semestre, String Cedula, Nombres StriSng, int EDAD Estudiante Pedro = new Estudiante ("Monterrey", "Octavo", "1207895431", "Carlos Torres", 15); Pedro.setEspecialidad ("Telecomunicacion"); Pedro.DatosInformativos (); } }

Clase Padre (Persona)


Persona public class { Cadena Cedula privado; NOMBRES cadenas privadas; EDAD int privado; pblica Persona (String Cedula, Nombres de cadena, int EDAD) { this.Cedula = Cedula; this.Nombres = NOMBRES; this.Edad = EDAD; } DatosInformativos public void () { System.out.println ("Cdula Identidad:" + this.Cedula); System.out.println ("nombres:" + this.Nombres); System.out.println ("EDAD:" + this.Edad); }

Clase Hija (Estudiante): This Clase Hereda de personaje


public class Estudiante extiende Persona { Colegio private String; Semestre private String; private String especialidad; public void setEspecialidad (String Especialidad) { this.Especialidad = Especialidad; }

pblica Estudiante (String Colegio, String Semestre, String Cedula, Nombres de cadena, int EDAD) { super (Cdula, Nombres, EDAD); this.Colegio = Colegio; this.Semestre = Semestre; } @ Override DatosInformativos public void () { super.DatosInformativos (); System.out.println ("Colegio:" + this.Colegio); System.out.println ("Semestre:" + this.Semestre); System.out.println ("Especialidad:" + this.Especialidad); } }

Clase Hija (Empleado): This Clase Hereda de personaje


public class Empleado extiende Persona { Cargo private String;

Departamento private String; pblica Empleado (String Cargo, String Departamento, String Cedula, Nombres cadena, int EDAD) { super (Cdula, Nombres, EDAD); this.Cargo = carga; this.Departamento = Departamento; } @ Override DatosInformativos public void () { super.DatosInformativos (); System.out.println ("Cargo:" + this.Cargo); System.out.println ("Departamento:" + this.Departamento); } public String CalcularSueldo (int numHoras, doble valorHora) { doble sueldo = numHoras * valorHora; Cadena cadSueldo = "Sueldo:" + String.valueOf (sueldo); volver cadSueldo; } } Ejecucion del Programa

Publicado por Jessica Crespo en 15:13

También podría gustarte