链表Java Lietner抽认卡
我需要创建一个名为box的类,该类使用链接列表存储包含两个字符串作为输入的抽认卡链表Java Lietner抽认卡,java,unix,Java,Unix,我需要创建一个名为box的类,该类使用链接列表存储包含两个字符串作为输入的抽认卡 public class FlashCard { public static String challenge; public static String response; public FlashCard(String front, String back) { double a = Math.random(); if(a > 0
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);
}
}
公共类抽认卡{
公共静态字符串挑战;
公共静态字符串响应;
公共闪存卡(前串、后串)
{
double a=Math.random();
如果(a>0.5)挑战=正面;
否则挑战=返回;
如果(a<0.5)响应=前部;
else响应=返回;
}
私有静态字符串getChallenge()
{
回归挑战;
}
私有静态字符串getResponse(字符串输入)
{
返回响应;
}
公共静态void main(字符串[]args)
{
抽认卡=新抽认卡(“Ryan Hardin”,“UAB学生”);
系统输出打印(挑战);
}
}
这是我的box类,它使用链表作为实例变量来存储卡,但不断收到错误消息
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;
}
import java.util.LinkedList;
公共类箱{
私有链接列表数据;
公用信箱(){
this.data=新的LinkedList();
}
公用箱添加卡(FlashCard r){
框一=这个;
1.data=data.add(0,r);
返回一个;
}
- 将链表作为Box类的实例变量放在构造函数之外-我们称它为boxList
- 在您的主要方法框中,执行boxList.add(新建FlashCard())