在java中建模加载的数据
因此,我目前在我的任务的一部分,重点是“建模加载的数据”。到目前为止,我已经创建了一个类,它使用BufferedReader和FileReader读取外部文件的内容。接下来,我创建了一个FlashCard类,它有一个FlashCard的ArrayList。一组有一堆问题,另一组有一堆答案。在我提出我的问题之前,我将向您展示我的程序当前的样子,以便您能够更好地理解我所坚持的内容 FlashCardReader类在java中建模加载的数据,java,arraylist,Java,Arraylist,因此,我目前在我的任务的一部分,重点是“建模加载的数据”。到目前为止,我已经创建了一个类,它使用BufferedReader和FileReader读取外部文件的内容。接下来,我创建了一个FlashCard类,它有一个FlashCard的ArrayList。一组有一堆问题,另一组有一堆答案。在我提出我的问题之前,我将向您展示我的程序当前的样子,以便您能够更好地理解我所坚持的内容 FlashCardReader类 public class FlashCardReader { BufferedRe
public class FlashCardReader
{
BufferedReader reader = null;
String line;
Scanner sc = new Scanner(System.in);
public void getLine()
{
System.out.println("Please enter a file to read");
try {
reader = new BufferedReader(
new FileReader("C:\\Users\\lee-pc\\Documents\\University\\Programming\\Lab9\\" + sc.next()));
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
System.out.println(
ex.getMessage() + "File did not read correctly");
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
System.out.println("File was not found.");
}
}
public void isReady()
{
System.out.println("Please enter a file to read");
try {
reader = new BufferedReader(
new FileReader("C:\\Users\\lee-pc\\Documents\\University\\Programming\\Lab9\\" + sc.next()));
try {
if(reader.ready())
{
System.out.println("Is ready");
}else
System.out.println("Not ready");
} catch (IOException ex) {
System.out.println(
ex.getMessage() + "File did not read correctly");
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
System.out.println("File was not found.");
}
}
}
import java.util.ArrayList;
public class FlashCard
{
ArrayList<String> cardlist = new ArrayList<>();
FlashCard(String question, String answer)
{
}
public void getQuestion()
{
cardlist.add("1Q - By what initials was Franklin Roosevelt better known?");
cardlist.add("2Q - Which number president was Franklin Roosevelt?");
cardlist.add("3Q - Which state was Franklin Roosevelt born in?");
cardlist.add("4Q - In which year did Roosevelt become Governor of New York?");
cardlist.add("5Q - What was the name of Franklin Roosevelt's wife?");
cardlist.add("6Q - How many children did Franklin Roosevelt have?");
cardlist.add("7Q - From which university did Franklin Roosevelt graduate with an A.B in history?");
cardlist.add("8Q - What was the first name of Franklin Roosevelt's 5th cousin, who was also President?");
cardlist.add("9Q - Which disease is believed to be the causes of Franklin Roosevelt's paralysis?");
cardlist.add("10Q - At what age did Franklin Roosevelt die?");
}
public void getAnswer()
{
cardlist.add("1A - FDR");
cardlist.add("2A - 32");
cardlist.add("3A - New York");
cardlist.add("4A - 1929");
cardlist.add("5A - Elenor");
cardlist.add("6A - 6");
cardlist.add("7A - Hrrvard");
cardlist.add("8A - Theodore");
cardlist.add("9A - Polio");
cardlist.add("10A - 63");
}
public ArrayList<String> getFlashCard()
{
return cardlist;
}
}
抽认卡类
public class FlashCardReader
{
BufferedReader reader = null;
String line;
Scanner sc = new Scanner(System.in);
public void getLine()
{
System.out.println("Please enter a file to read");
try {
reader = new BufferedReader(
new FileReader("C:\\Users\\lee-pc\\Documents\\University\\Programming\\Lab9\\" + sc.next()));
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
System.out.println(
ex.getMessage() + "File did not read correctly");
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
System.out.println("File was not found.");
}
}
public void isReady()
{
System.out.println("Please enter a file to read");
try {
reader = new BufferedReader(
new FileReader("C:\\Users\\lee-pc\\Documents\\University\\Programming\\Lab9\\" + sc.next()));
try {
if(reader.ready())
{
System.out.println("Is ready");
}else
System.out.println("Not ready");
} catch (IOException ex) {
System.out.println(
ex.getMessage() + "File did not read correctly");
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
System.out.println("File was not found.");
}
}
}
import java.util.ArrayList;
public class FlashCard
{
ArrayList<String> cardlist = new ArrayList<>();
FlashCard(String question, String answer)
{
}
public void getQuestion()
{
cardlist.add("1Q - By what initials was Franklin Roosevelt better known?");
cardlist.add("2Q - Which number president was Franklin Roosevelt?");
cardlist.add("3Q - Which state was Franklin Roosevelt born in?");
cardlist.add("4Q - In which year did Roosevelt become Governor of New York?");
cardlist.add("5Q - What was the name of Franklin Roosevelt's wife?");
cardlist.add("6Q - How many children did Franklin Roosevelt have?");
cardlist.add("7Q - From which university did Franklin Roosevelt graduate with an A.B in history?");
cardlist.add("8Q - What was the first name of Franklin Roosevelt's 5th cousin, who was also President?");
cardlist.add("9Q - Which disease is believed to be the causes of Franklin Roosevelt's paralysis?");
cardlist.add("10Q - At what age did Franklin Roosevelt die?");
}
public void getAnswer()
{
cardlist.add("1A - FDR");
cardlist.add("2A - 32");
cardlist.add("3A - New York");
cardlist.add("4A - 1929");
cardlist.add("5A - Elenor");
cardlist.add("6A - 6");
cardlist.add("7A - Hrrvard");
cardlist.add("8A - Theodore");
cardlist.add("9A - Polio");
cardlist.add("10A - 63");
}
public ArrayList<String> getFlashCard()
{
return cardlist;
}
}
以下是我接到的指示:
- 创建一个测验类。此类将处理与用户的交互。它应该有一个FlashCardReader和一个实例变量来保存FlashCard的ArrayList
- 构造函数在其声明的FlashCardReader实例中使用getFlashCards()方法创建并用FlashCards填充ArrayList
- 要使hold包含cardlist ArrayList的元素,需要执行哪些操作
- 什么是“创建一个测验类。这个类将处理与用户的交互。它应该有一个FlashCardReader和一个实例变量来保存FlashCard的ArrayList。”
- 第二个要点是如何实施的?构造函数如何使用getFlashCards()方法创建并用FlashCards填充ArrayList