public class Player implements Comparable<Player> {
//Fields
private Name name;
private Rollable rollable;
//Constructors
public Player() {
name = new Name();
rollable = new Rollable();
}
public Player(Name name) {
this.name = name;
rollable = new Rollable();
}
public Player(Name name, Rollable rollable) {
this.name = name;
this.rollable = rollable;
}
Здравствуйте, для моих конструкторов, куда я положил rollable = new Rollable();
Я получаю ошибку, которая утверждает, что это Cannot instantiate the type rollable
.Ниже я добавил тест JUnit, а также добавлю код для класса Rollable
@Test
public void testDefaultConstructor() {
Player p = new Player();
assertEquals("Name field should be initialised with a default Name object ", new Name(), p.
getName ());assertTrue («Поле, в котором может быть выполнено обновление игрока, должно быть инициализировано с помощью. реализующего экземпляра интерфейса Rollable», p.getRollable () instanceof Rollable);}
@Test
public void testCustomConstructor1arg() {
Name n = new Name("Joe", "Bloggs");
Player p = new Player(n);
assertSame("Player's name field should be initialised with and return the same object received by the constructor", n, p.getName());
assertTrue("Player's rollable field should be initialised with an implementing instance of the Rollable interface", p.getRollable() instanceof Rollable);
}
Ниже приведен тест JUnit для конструктора по умолчанию, который также дает мне ошибку Players rollable field should be initialised with an implementing instance of the Rollable interface
, однако все остальные мои тесты JUnit проходят.
@Test
public void testDefaultConstructor() {
Player p = new Player();
assertEquals("Name field should be initialised with a default Name object ", new Name(), p.getName());
assertTrue("Player's rollable field should be initialised with an implementing instance of the Rollable interface", p.getRollable() instanceof Rollable);
}
Код для моего класса Rollable приведен ниже;
public interface Rollable {
public void roll();
public int getScore();
}
Методы для моего кода Rollable следующие:
//Methods
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
public Rollable getRollable() {
return rollable;
}
public void rollDice() {
rollable.roll();
}
public int getDiceScore() {
return rollable.getScore();
}
Вся помощь будетспасибо, что борюсь с неудачами, спасибо.