Advertisement
hombretao

Alumno

Jun 21st, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package administrarcurso;
  6.  
  7. /**
  8.  *
  9.  * @author tao
  10.  */
  11. public final class Alumno {
  12.    
  13.     // Atributos
  14.     private int rut;
  15.     private String nombre;
  16.     private String email;
  17.     private String direccion;
  18.     private int telefono;
  19.     private float notas[];
  20.    
  21.     // Constructor
  22.     public Alumno( int rut, String nombre, String email, String direccion, int telefono )
  23.     {
  24.         setRut( rut );
  25.         setNombre( nombre );
  26.         setEmail( email );
  27.         setDireccion( direccion );
  28.         setTelefono( telefono );
  29.         inicializarNotas();
  30.     }
  31.    
  32.     // Comportamientos
  33.     private void inicializarNotas()
  34.     {
  35.         float notas[] = new float[5];
  36.        
  37.         for ( int i = 0; i < notas.length; i++ )
  38.         {
  39.             notas[i] = 1f;
  40.         }
  41.        
  42.         this.notas = notas;
  43.     }
  44.    
  45.     public void agregarNota( int posicion, float nota )
  46.     {
  47.         // posicion - 1 porque el vector empieza en 0
  48.         notas[posicion - 1] = nota;
  49.     }
  50.    
  51.     public float calcularPromedio()
  52.     {
  53.         float sumaNotas = 0f;
  54.        
  55.         for(int i = 0; i < notas.length; i++) {
  56.             sumaNotas += notas[i];
  57.         }
  58.        
  59.         return sumaNotas/notas.length;
  60.     }
  61.    
  62.     @Override
  63.     public String toString()
  64.     {
  65.         return "Rut: "+rut+
  66.                 ", Nombre: "+nombre+
  67.                 ", Email: "+email+
  68.                 ", dirección: "+direccion+
  69.                 ", teléfono: "+Integer.toString(telefono)+
  70.                 ", Notas: "+notas[0]+
  71.                 " – "+notas[1]+
  72.                 " – "+notas[2]+
  73.                 " – "+notas[3]+
  74.                 " – "+notas[4]+
  75.                 ", Promedio: "+calcularPromedio();
  76.     }
  77.    
  78.     // Accesadores y Mutadores
  79.     public String getDireccion() {
  80.         return direccion;
  81.     }
  82.  
  83.     public void setDireccion(String direccion) {
  84.         this.direccion = direccion;
  85.     }
  86.  
  87.     public String getEmail() {
  88.         return email;
  89.     }
  90.  
  91.     public void setEmail(String email) {
  92.         this.email = email;
  93.     }
  94.  
  95.     public String getNombre() {
  96.         return nombre;
  97.     }
  98.  
  99.     public void setNombre(String nombre) {
  100.         this.nombre = nombre;
  101.     }
  102.  
  103.     public int getRut() {
  104.         return rut;
  105.     }
  106.  
  107.     // PRIVADO!!!!!!!
  108.     private void setRut(int rut) {
  109.         this.rut = rut;
  110.     }
  111.  
  112.     public int getTelefono() {
  113.         return telefono;
  114.     }
  115.  
  116.     public void setTelefono(int telefono) {
  117.         this.telefono = telefono;
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement