domingo, 10 de mayo de 2015

Nomenclatura de controles Swing.


Documento sobre estándares de programación:
ESTÁNDARES DE PROGRAMACIÓN
Versión 1.0





PROPUESTO POR: Nora La Serna Palomino                   nlaserna@pucp.edu.pe

ELABORADO POR:                       
SEMINARIO HUAMANÍ, LIZZETT NATALY                    20037185
RIOS GÁRATE, CÉSAR HUMBERTO                            20042153
BALBIN AVALOS, CAROLINA                                      20050373
DÍAZ MUGURUZA, SHEYLA ABIGAIL                           20057079
CHÁVEZ LAZARTE, VICTOR ALFONSO                       20062038



REVISADO POR:     Joseph Gallart Suárez                           jgallart@pucp.edu.pe

Enlaces:


Fuente
Copia del documento.

jueves, 30 de abril de 2015

package corredoresporpaises;
import java.util.ArrayList;
/**
*
* @author juan
*/
public class Pais {
private String nombre;
private ArrayList corredores;
public ArrayList getCorredores() {
return corredores;
}

public void setCorredores(ArrayList corredores) {
this.corredores = corredores;
}

public Pais(String nombre) {
this.nombre = nombre;
corredores = new ArrayList<>();
}
public String getNombre() {
return nombre;
}

public boolean anhade(Corredor nuevo) {
boolean retorno = true;

try {
if (corredores.contains(nuevo)){
System.out.println("El corredor ya estaba incluido");

}
else
{
nuevo.setPais(this);
corredores.add(nuevo);
}

} catch (Exception e) {
retorno=false;
}
return retorno;
}
public void listarCorredores(){
System.out.println(nombre);
System.out.println("==============");
for (Corredor corredor : corredores) {
System.out.println(corredor);
}
}


jueves, 12 de febrero de 2015

ejercicio 11 tema3, números aleatorios

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejercicio11;
import java.util.Random;
/**
*
* @author juan
*/
public class Ejercicio11 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int [] lista = new int [25];
float [] auxi = new float[4];
Random al = new Random();

Ejercicio 10, tema 3 Generar un examen aleatorio de preguntas

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejercicio9;
/**
*
* @author juan
*/
public class Test {
private int Num;
private String Enunciado;
private String [] Opciones = new String[4];
private int Valida;
public int getNum() {
return Num;
}
public void setNum(int Num) {
this.Num = Num;
}

lunes, 9 de febrero de 2015

Clase monitor con uso en un array para buscar repeticiones

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package preparacion4;
/**
*
* @author juan
*/
public class Monitor {
String Fabricante;
int Pulgadas;
int ResolucionH;
int ResolucionV;
String Modelo;
public Monitor() {
}

jueves, 5 de febrero de 2015

Tema 3 ejercicio 8: Creando vector de ecuaciones de segundo grado

package ejercicio8;
import java.util.Random;

/**
 *
 * @author juan
 */
public class Ejercicio8 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Random al = new Random();
        EcuacionSegundoGrado [] vector = new EcuacionSegundoGrado [5];
        int contIncorrectas;
        
        for (int i = 0; i < 5; i++) {
            
            

miércoles, 4 de febrero de 2015

Ejercicio 6 Tema 3: Comprobar nif usando arrays

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejercicio5;
import java.util.Scanner;
/**
 *
 * @author juan
 */
public class Ejercicio5 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        char [] letras ={'T','R','W','A','G','M','Y','F', 'P', 'D','X','B', 'N', 'J', 'Z', 'S', 'Q','V', 'H', 'L', 'C', 'K','E', };
        String cadena;
        int numDni;
        int resto;
        char letra;
        String numeros;
        int cont =0;
        boolean esNumero;
        
        Scanner leer = new Scanner(System.in);
    

Ejercicio 5 Tema 3: Calcular el NIF usando arrays

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejercicio5;
import java.util.Scanner;
/**
 *
 * @author juan
 */
public class Ejercicio5 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        char [] letras ={'T','R','W','A','G','M','Y','F', 'P', 'D','X','B', 'N', 'J', 'Z', 'S', 'Q','V', 'H', 'L', 'C', 'K','E', };
        int numDni;
        int resto;
     
        Scanner leer = new Scanner(System.in);
       
        System.out.println("Introduzca su dni: ");
        numDni= leer.nextInt();
        resto = numDni%23;
       
        System.out.println(letras[resto]);
     
       
       
    }
   
}

lunes, 2 de febrero de 2015

ejercicio 4 tema3

package ejercicio4;
import java.util.Random;

/**
 *
 * @author juan
 */
public class Ejercicio4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int [] numeros = new int[100];
        int [] ocurren = new int[10];
        Random r = new Random();
        int cont;
       
        for (int i = 0; i < numeros.length; i++) {
            numeros[i]= r.nextInt(31)+20;
        }
       
        cont=0;
        for (int i = 0; i < numeros.length; i++) {
            System.out.print(numeros[i]+",");
            ++cont;
            if (cont==20) {
                System.out.println("");
                cont=0;
            }
        }
        for (int num : numeros) {
            if (num>20 && num <31 p="">                ocurren[(num-21)]++;
        }
     
     
        for (int i = 0; i < ocurren.length; i++) {
            System.out.println("El número: "+ (21+i)+ " aparece "+ ocurren[i]+ " veces");
        }
    /*
        switch (num) {
            case 21: ocurren[0]++;break;
            case 22: ocurren[1]++;
                     break;
               
                break;
            default:
                throw new AssertionError();
        }
            */
    }
   
}

Ejercicio 3 tema 3

package ejercicio3;
import java.util.Random;
/**
 *
 * @author juan
 */
public class Ejercicio3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        long t0;
        int [] resultado = new int [6];
        Random tirada = new Random();
       
        t0 = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            resultado[tirada.nextInt(6)]++;
        }
       
       
        for (int i = 0; i < resultado.length; i++) {
            System.out.println((i+1 )+":"+resultado[i]);
        }
        System.out.println("Tiempo (milisegundos): "+(System.currentTimeMillis()-t0));
   
    }
   
}

Cuenta corriente (ejercicio 83) sin análisis de excepciones

package ejercicio83;

/**
 *
 * @author juan
 */
public class CuentaCorriente {

    private String Nombre;
    private String Apellidos;
    private String Direccion;
    private String Telefono;
    private String Nif;
    private double Saldo;

    public CuentaCorriente() {
        Nombre = "";
    }

    private boolean esDigito(String cadena) {
        boolean retorno = true;
        for (int i = 0; i < cadena.length(); i++) {
            if (!Character.isDigit(cadena.charAt(i))) {
                return false;
            }
        }
        return retorno;
    }

jueves, 22 de enero de 2015

Clase fecha (80) v2.0

package ejercicio80;

/**
 *
 * @author juan
 */
public class Fecha {

    private int dia;
    private int mes;
    private int anyo;

    /**
     * Constructor por defecto genera fechas al 1 del 1 del 2013
     */
    public Fecha() {
        this.dia = 1;
        this.mes = 1;
        this.anyo = 2013;
    }

    /**
     * Constructor al que les pasamos tres parámetros si la fecha es posible se
     * le asigna en caso de fecha incorrecta inicializa el objeto al 1-1-2013
     *
     * @param dia representa el día de la fecha completa
     * @param mes mes de la fecha
     * @param anyo año de la fecha
     */
    public Fecha(int dia, int mes, int anyo) {
        if (comprobarFecha(dia, mes, anyo)) {
            this.dia = dia;
            this.mes = mes;
            this.anyo = anyo;
        } else {
            this.dia = 1;
            this.mes = 1;
            this.anyo = 2013;
        }
    }

    /**
     * Permite asignar día, mes y anyo al objeto fecha. Si la asignación es
     * correcta devuelve true, en caso contrario false.
     *
     * @param dia día del año que se quiere asignar
     * @param mes mes del año en formato numérico
     * @param anyo año en formato numérico
     * @return true si la fecha asignada es posible, false en caso contrario
     */
    public boolean asignate(int dia, int mes, int anyo) {
        boolean retorno = false;

        if (comprobarFecha(dia, mes, anyo)) {
            this.dia = dia;
            this.mes = mes;
            this.anyo = anyo;
 

lunes, 19 de enero de 2015

Clase fecha (ejercicio 80)

Primera parte del ejercicio en la que comprobamos las fechas y vamos añadiendo comentarios a los métodos

package ejercicio80;

/**
 *
 * @author juan
 */

viernes, 16 de enero de 2015

Ecuaciones de segundo grado. Ejercicio 79

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio79;

/**
 *
 * @author juan
 */
public class EcuacionSegundoGrado {

    private int a;
    private int b;
    private int c;

    public EcuacionSegundoGrado(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

jueves, 15 de enero de 2015

Clase animal ejercicio 73, explicando clases

package animalito;

/**
 *
 * @author juan
 */
class Animal {

    private int edad;
    private String nombre;

    public Animal(){
       
    }