Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Student.
- */
- public class Student {
- private int absences = 0;
- private String name;
- private String address;
- @Override
- public boolean equals(Object o){
- if(o == this){
- return true;
- }
- if(!(o instanceof Student)){
- return false;
- }
- Student other = (Student) o;
- return name == other.name && address == other.address;
- }
- @Override
- public int hashCode(){
- int result = 7;
- result = 31 * result + Double.valueOf(name.length()).hashCode();
- result = 31 * result + Double.valueOf(address.length()).hashCode();
- return result;
- }
- /**
- * Constructor for class Student
- *
- * @param name name of the student
- * @param address address of the student
- * @throws IllegalArgumentException if name or address are empty
- */
- public Student(String name, String address) {
- if (name == null || name.isEmpty()) throw new IllegalArgumentException("name");
- if (address == null || address.isEmpty()) throw new IllegalArgumentException("address");
- this.name = name;
- this.address = address;
- }
- /**
- * Add absence.
- *
- * @param hourse absence in hours
- * @throws IllegalArgumentException if hours is <= 0
- */
- public void addAbsence(int hours){
- if(hours <= 0)throw new IllegalArgumentException("hours <= 0");
- this.absences += hours;
- }
- /**
- * @return absence (in hours)
- */
- public int getAbsences(){
- return absences;
- }
- /**
- * @return name
- */
- public String getName() {
- return name;
- }
- /**
- * @return address
- */
- public String getAddress() {
- return address;
- }
- @Override
- public String toString(){
- return name + " /" + address + "/: " + absences;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement