Professional Documents
Culture Documents
Problem 1 (2 points)
Given the following constructor definitions, write the
statement to create an object using each constructor.
a. public Customer(String inCustName, String inCustPhone)
{
}
c. public Account()
{
Problem 2 (2 points)
Given the following method definitions for the Date class,
write the statement to call each method, assuming the object
name is newDate. Be sure to pass in appropriate explicit
parameters and to put any returned values into an
appropriate variable.
a. public void setMonth(int newMonth)
private int month;
public void setMonth (int newMonth)
{
this.month = newMonth;
}
monthNew.setMonth(8);
int returnMonth = monthNew.getMonth();
Problem 3 (2 points)
Given the following constructor and method definitions,
write the unit test cases for each constructor. Remember
that before testing you must first create the object. Be
sure to include tests for the following:
object has been created (assertNotNull)
instance variables have been correctly set to a value
a. public Customer(String inCustName, String inCustPhone)
public String getCustName()
public String getCustPhone()
Customer tmpCust = new Customer ("Matt", 5555555555);
assertNotNull(tmpCust);
assertEquals("Matt", tmpCust.getCustName());
assertEquals(5555555555, tmpCust.getPhone());
b. public
public
public
public
c. public Account()
public double getBalance() default value = 0.0
Problem 4 (2 points)
Given the following method definitions for the Date class,
write the unit test statements to test each method. Assume
that the following object has been created and use this in
your testing:
public Time(int inHour, int inMinute, int inSecond)
Time tmpTime = new Time(04, 14, 43);
When writing your test cases, it may be necessary to first
call the method and then to call a get or accessor method to
verify the expected action has occurred.
a. public void setHour(int newHour)
Corresponding get method is:
i. public int getHour()
public void setHour (int newHour)
{
this.hour = newHour;
}
public int getHour()
{
return this.hour;
}
public Time (int inHour, int inMinute, int inSecond)
Time tmpHour = new Time(04, 14, 43);
assertEquals(04, tmpHour.getHour());
Problem 5 (2 points)
For the class code:
a) public Class Box()
b) {
c)
private int height;
d)
private int length;
e) }
f) public Box()
g) {
h)
this.height = 0;
i)
this.length = 0;
j) }
k) public void setHeight(int inHeight)
l) {
m)
this.height = inHeight;
n) }
o) public void setLenght(int inLength)
p) {
q)
this.height = inLength;
r) }
s) public int computeArea()
t) {
u)
int area = this.height * this.length;
v)
return area
w) }
Instance
ud
Ud
Ud
Ud
Ud
Ud
10
this.addr = inAddr;
}
public String getAddr()
{
return this.addr;
}
}
11
12