dcsimg
need help with equivalent classes in JUnit..
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Neha_Behl
Posted On:   Thursday, April 10, 2008 06:13 PM

Hi, i have an assignment and have been trying hard to solve it.. maybe easy for some of u.. I have a Person.java class and have to create equivalent classes for the inputs of the methods and also write a test class named JUnit4PersonTester.. please help here is the code... package set5; /** * A class for storing a person's last name * and age. Meant for storing information * on active workers. * * @author Raine Kauppinen */ public class Person { // attributes private int age; private String lastName; // set and get methods for the attributes // method setAge is specified as follows: // - an age must be   More>>


Hi, i have an assignment and have been trying hard to solve it.. maybe easy for some of u.. I have a Person.java class and have to create equivalent classes for the inputs of the methods and also write a test class named JUnit4PersonTester.. please help here is the code...



			
package set5;

/**
* A class for storing a person's last name
* and age. Meant for storing information
* on active workers.
*
* @author Raine Kauppinen
*/

public class Person {
// attributes
private int age;
private String lastName;

// set and get methods for the attributes

// method setAge is specified as follows:
// - an age must be between 16 and 68
// - if the age is ok, the method sets the age
// and returns true
// - if the age is not ok, the method does not
// set the age and returns false

public boolean setAge(int age) {
boolean ageOk = false;
if (age >= 16 || age <= 68) {
this.age = age;
ageOk = true;
}
return ageOk;
}

// method setLastName is specified as follows:
// - a last name must have at least one character and
// all the characters in the name have to be letters
// (for example, there may not be any numbers in
// the last name)
// - if the last name name is ok, the method sets the
// last name and returns true
// - if the last name is not ok, the method does not
// set the last name and returns false
public boolean setLastName(String lastName) {
boolean lastNameOk = true;
if (lastName.length() < 1) {
lastNameOk = false;
} else {
for (int i=0; i
if (!(Character.isLetter(lastName.charAt(i)) == true)) {
lastNameOk = false;
}
}
if (lastNameOk == true) {
this.lastName = lastName;
}
}
return lastNameOk;
}

public int getAge() {
return age;
}

public String getLastName() {
return lastName;
}
}
   <<Less
About | Sitemap | Contact