我有一個類Set
,我應該從Set
類兩點 用戶要求的閱讀。我如何檢查點是否是Set上的成員?
我有一些問題的方法member
和subset
。
我沒有任何想法是如何工作的,所以如果任何一個可以給我說,我能理解這種方法是如何工作的例子?
class Set {
private point[] p;
public Set(int n) {
p = new point[n];
readSet(n);
}
private void readSet(int n) {
System.out.println("Please enter " + n + " points");
for (int i = 0; i < n; i++) {
int x = 0;
int y = 0;
p[i] = new point(x, y);
}
}
public void printSet() {
for (int i = 0; i < p.length; i++) {
System.out.print(p[i]);
}
}
public void shiftSet(int dx, int dy) {
for (int i = 0; i < p.length; i++) {
p[i].shift(dx, dy);
}
}
// returns if P is in the set, making use of the equals method in class Point
public boolean member(point P) {
for (int i = 0; i < p.length; i++) {
// ...
}
return true;
}
// returns if current set is a subset of S, making use of the member method
public boolean subset (Set S) {
// ...
return true;
}
}
哦,哦,有一個名爲兩個變量'P'和'p'是危險的,或者至少非常混亂。如果你改變了,我會看看你的代碼。 –