我需要创建一个名为box的类,它使用链表来存储包含两个字符串作为输入的flashcards。链接列表Java Lietner Flashcard
public class FlashCard {
public static String challenge;
public static String response;
public FlashCard(String front, String back)
{
double a = Math.random();
if(a > 0.5) challenge = front;
else challenge = back;
if(a < 0.5) response = front;
else response = back;
}
private static String getChallenge()
{
return challenge;
}
private static String getResponse(String in)
{
return response;
}
public static void main(String[] args)
{
FlashCard card = new FlashCard("Ryan Hardin", "Student at UAB");
System.out.print(challenge);
}
}
这是我的盒子类使用链表作为实例变量来存储卡,但不断收到错误消息。
import java.util.LinkedList;
public class Box {
private LinkedList<FlashCard> data;
public Box() {
this.data = new LinkedList<FlashCard>();
}
public Box addCard(FlashCard r) {
Box one = this;
one.data = data.add(0,r);
return one;
}
那里有问题吗?我不确定你想要什么。 – blm
我不知道如何去实际添加元素到我试过的盒子,但它不起作用。我不能将元素存储在框对象中。我想知道为什么。 –
您尚未在Box上提供任何方法来添加实例。如果你想对盒子做某些事情(比如添加东西,将东西排除在外,计算其中的东西等),则需要向Box类添加完成这些事情的方法。 – blm