public class Person { private String name; private int age; private int iq; private int friend;
/** * The persons name. */ public Person (String newName)
{ name = newName; }
/** * = the intelligence qoutient of the person */ public int getIntelligence() { return iq; }
/** * Sets the intelligence qoutient to iq */ public void setIntelligence(int iq) { this.iq = iq; }
public String getName() { return name; }
public int getAge() { return age; }
public void setName(String n) {
}
public void setAge(int a) { age = a; }
/** * Add person p to this person's list of friends. * @param p the person add */ public void addFriend(Person p) { friend = (friend + 1); }
/** * Remove person p from this person's list of friends. * @param p the persons remove */ public void removeFriend(Person p) { friend = (friend - 1); }
/** * Prints a list of this person's friends */ public void printFriends() { System.out.println("The persons friends" + friend); }
/** * Is the person a Child? * @return true if the person is a Child, otherwise false */
public boolean isChild() { return (0 <= age && age <= 17); }
/** * Is the person a Pensioener? * @return true if the person is a pernsioner, otherwise false */
public boolean isPensioner() { return (67 <= age && age <= 250); }
/** * Is the person a Teenager? * @return true if the person is a Teenager, otherwise false */
public boolean isTeentager() { return (13 <= age && age <= 19); }
/** * Is the person a menzaner * @return true if the peson has an iq over 140. */ public boolean isMenzaner () { return (140 <= iq); }
}
Hvordan laver jeg et test-program der (i en Driver-klasse) tester min løsning ?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.