这是我的代码:
public class SmartCard {
private String name;
//Constructor for SmartCard class
public SmartCard(String name) {
this.name = name;
}
//the getOwner() method which returns the owner's name
public String getOwner() {
return name;
}
//setStaff() method to set staff status
public boolean setStaff(boolean status) {
return true;
}
//isStaff() method returns true if card belongs to member of staff
public boolean isStaff() {
boolean staff;
if (setStaff(true)) {
staff = true;
} else staff = false;
return staff;
}
}
public class Tester {
public static void main(String... args) {
testPart1a();
testPart1b();
testPart1c();`enter code here`
}
public static void testPart1a() {
System.out.println("Part 1 - Accessor methods");
System.out.println("======");
System.out.println("--- Part 1a ---");
System.out.println();
System.out.println("* Creating a new SmartCard for student Anna Undergrad...");
SmartCard card = new SmartCard("Anna Undergrad");
System.out.println("Owner is: " + card.getOwner());
System.out.println();
}
public static void testPart1b() {
System.out.println("--- Part 1b ---");
System.out.println();
SmartCard card = new SmartCard("Anna Undergrad");
System.out.println("Is " + card.getOwner() + " staff? " + card.isStaff());
System.out.println();
}
当我运行程序时,我的 isStaff() 方法总是返回 true,而它应该为 Anna Undergrad 返回 false,而为 Bob Lecturer 返回 true。也许我做错了,应该改变我的 setStaff() 方法。
慕码人2483693
慕桂英546537
幕布斯7119047
相关分类