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;
    }