All pastes #423728 Raw Edit

Something

public text v1 · immutable
·published 2007-04-04 11:38 UTC
rendered paste body

/**
 * Student is a class that holds students' names, ids, ages, and addresses. These can also be altered when needed.
 * 
 * @author (Louisa Clarkson) 
 * @version (version 1)
 */
public class Student
{
    String firstName;
    String lastName;
    String fullName;
    String name;
    int id;
    int age;
    String addressLine1;
    String addressLine2;
    
    /**
     * Constructor for objects of class Student
     */
    public Student(String firstName, String lastName, int id, int age, String addressLine1, String addressLine2)
    {
       if (firstName.equals(""))
       {
            fullName = lastName;
            name = lastName;
        }
        else
        {
            name = firstName + " " + lastName;
        }
       setName(firstName, lastName);
       this.id = id;
       this.age = age;
       setAddress(addressLine1, addressLine2);
    }

    /**
     * Alternative constructor for objects of class Student
     */
    public Student(String fullName, int id, int age, String addressLine1, String addressLine2)
    {
        int posOfSpace = fullName.indexOf(" ");
        
        if (posOfSpace > 0)
        {
            fullName = firstName + " " + lastName;
            name = firstName + " " + lastName;
        }
        else
        {
            name = lastName;
        }
        setAddress(addressLine1, addressLine2);
        
        this.id = id;
        this.age = age;
        
    }
    
    public void printAddressLabel()
    {   
        System.out.println(firstName + " " + lastName + " (#" + id + ")");
        System.out.println(addressLine1);
        System.out.println(addressLine2);
    }

    public String getFirstName()
    {
        return firstName;
    }
    
    public String getLastName()
    {
        return lastName;
    }
    
    public int getId()
    {
        return id;
    }
    
    public int getAge()
    {
        return age;
    }
    
    public String addressLine1()
    {
        return addressLine1;
    }
    
    public String addressLine2()
    {
        return addressLine2;
    }
    
    public void setName(String firstName, String lastName)
    {
        
       this.firstName = standardiseCase(firstName);
       this.lastName = standardiseCase(lastName);
    }
    
    public void setAddress(String addressLine1, String addressLine2)
    {
       this.addressLine1 = addressLine1;
       this.addressLine2 = addressLine2;
    } 
    
    private String standardiseCase(String name)
    {
        if name.length()
        {
            name = firstName + " " + lastName;
        }
        else if (length >= 1)
        {
            name = lastName;
        }
        String nameChar1 = name.substring(0, 1);
        String nameCharRest = name.substring(1);
        nameChar1 = nameChar1.toUpperCase();
        nameCharRest = nameCharRest.toLowerCase();
        
        return nameChar1 + nameCharRest;
    }
    
    public boolean canBuyAlcohol()
    {
        return(drinkingAge >= 18);
    }
}