首页 > > 详细

调试Bag java 、迭代讲解、讲解Bag java设计、java编程辅导、调试java

Question 1)
public void f(int arr[]) {
int total=0;
for (int i=0;i5) {
return 0;
}
if (v=0
*/
public abstract int getVar();
/**
* @require v1=0
* @ensure \result !=0
*/
public abstract int process(int v1, int v2);
}
Suppose:
class Y extends X
class W extends X
class Z extends Y
Which of the following obey the substitution principle?
A) Y.getVar | @ensure \result>0
B) Y.getVar | @ensure \result>2
W.getVar | @ensure \result>=0
C) Y.getVar | @ensure \result>2
Z.getVar | @ensure \result>1
D) Y.process | @require v10
3
Question 4)
public class V {
...
public static double f(int v);
...
}
Write a single JUnit4 test method which checks that:
f(2) returns a value greater than 0.
f(0) returns 0:5
f(-1) throws a NullPointerException
4
Question 5)
int f(int a, int b) {
if (a>b) {
return a;
}
int x=0;
for (int i=a;i<=b;++i) {
if (i%2==0) {
x+=a;
}
x+=a;
}
return x;
}
A) What values would f need to be tested with to ensure statement coverage? You are not being
asked to write test code or compute answers, just give the function calls. Try to use as few calls as
possible.
5
Question 6) A Bag is an unordered collection of ints where each value can appear multiple times.
For example a bag could contain 1, 5 and seven 3s.
public class Bag {
/**
* Create an empty Bag
*/
public Bag();
/**
* @param num number to search for
* @return number of times num appears in the Bag (0 if not present).
*/
public int getCount(int num);
/**
* @param num number to add to Bag
*/
public void add(int num);
/**
* @param num number to remove (If present multiple times, only remove one instance)
*/
public void remove(int num);
/**
* @return a String containing comma separated value:times pairs (where ‘‘times’’ is the number of times the value occurs in the Bag.
* for example: "1:1,5:1,3:7"
*/
@Override
public String toString();
}
A) What member variables would you need to add to the class?
B) Implement the constructor.
C) Implement add
D) Implement remove
E) Implement getCount
6
F) Implement toString
7
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!