/** * 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) { 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) { setName(fullName.substring(0, posOfSpace), fullName.substring(posOfSpace + 1)); } else { setName( "" , fullName ); } setAddress(addressLine1, addressLine2); this.id = id; this.age = age; } public void printAddressLabel() { if (firstName.length() > 0 ) { System.out.println(firstName + " " + lastName + " (#" + id + ")"); } else { System.out.println(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) { String nameChar1; String nameCharRest; if (name.length() > 1) { nameChar1 = name.substring(0, 1); nameCharRest = name.substring(1); nameChar1 = nameChar1.toUpperCase(); nameCharRest = nameCharRest.toLowerCase(); } else { nameChar1 = name.toUpperCase(); nameCharRest = ""; } return nameChar1 + nameCharRest; } public boolean canBuyAlcohol() { return(age >= 18); } }