Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package administrarcurso;
- /**
- *
- * @author tao
- */
- public final class Alumno {
- // Atributos
- private int rut;
- private String nombre;
- private String email;
- private String direccion;
- private int telefono;
- private float notas[];
- // Constructor
- public Alumno( int rut, String nombre, String email, String direccion, int telefono )
- {
- setRut( rut );
- setNombre( nombre );
- setEmail( email );
- setDireccion( direccion );
- setTelefono( telefono );
- inicializarNotas();
- }
- // Comportamientos
- private void inicializarNotas()
- {
- float notas[] = new float[5];
- for ( int i = 0; i < notas.length; i++ )
- {
- notas[i] = 1f;
- }
- this.notas = notas;
- }
- public void agregarNota( int posicion, float nota )
- {
- // posicion - 1 porque el vector empieza en 0
- notas[posicion - 1] = nota;
- }
- public float calcularPromedio()
- {
- float sumaNotas = 0f;
- for(int i = 0; i < notas.length; i++) {
- sumaNotas += notas[i];
- }
- return sumaNotas/notas.length;
- }
- @Override
- public String toString()
- {
- return "Rut: "+rut+
- ", Nombre: "+nombre+
- ", Email: "+email+
- ", dirección: "+direccion+
- ", teléfono: "+Integer.toString(telefono)+
- ", Notas: "+notas[0]+
- " – "+notas[1]+
- " – "+notas[2]+
- " – "+notas[3]+
- " – "+notas[4]+
- ", Promedio: "+calcularPromedio();
- }
- // Accesadores y Mutadores
- public String getDireccion() {
- return direccion;
- }
- public void setDireccion(String direccion) {
- this.direccion = direccion;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getNombre() {
- return nombre;
- }
- public void setNombre(String nombre) {
- this.nombre = nombre;
- }
- public int getRut() {
- return rut;
- }
- // PRIVADO!!!!!!!
- private void setRut(int rut) {
- this.rut = rut;
- }
- public int getTelefono() {
- return telefono;
- }
- public void setTelefono(int telefono) {
- this.telefono = telefono;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement