Hvordan laver jeg en test-driver?
Nu har jeg skrevet følgende program: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 ?
23/09-2007 01:34:52 Jeg skal nu lave en metode i Person-klassen, der kan afgøre om en person har en ven (dvs. en person i sin vennekreds) med et bestemt navn.
Mit bud:
public boolean hasFriend(String pName)
{
return (0 < pName);
}
Hvad gør jeg galt?
