在java混淆中建模加载的数据

时间:2016-11-29 06:16:19

标签: java arraylist

所以我目前正处于我的任务的一部分,专注于“建模加载数据”。到目前为止,我已经创建了一个使用BufferedReader和FileReader读取外部文件内容的类。接下来我创建了一个FlashCard类,它有一个flashcards的ArrayList。一组有一堆问题,另一组有一堆答案。在我提出问题之前,我会告诉你我的程序目前是什么样的,这样你就可以更好地理解我的问题。

FlashCardReader类

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.");
    }      
}
}

FlashCard类

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 Quiz 
{

    FlashCard hold = new FlashCard("","");
public FlashCard flashCardHolder = hold;

}

这是我接下来要做的事情:

  • 创建一个测验类。该类将处理与用户的交互。它应该有一个FlashCardReader和一个实例变量,它将保存FlashCards的ArrayList。
  • 构造函数使用getFlashCards()方法,在其声明的FlashCardReader实例中,使用FlashCards创建并填充ArrayList。

所以我在Quiz中创建了一个实例变量来创建一个新的FlashCard对象。接下来要问的是我不清楚所以我有以下问题:

  • hold持有什么以包含cardlist ArrayList的元素?
  • “创建一个测验类”是什么意思。这个类将处理与用户的交互。它应该有一个FlashCardReader 和一个将保存FlashCards的ArrayList的实例变量。“?< / LI>
  • 如何实施第二个要点?构造函数如何使用getFlashCards()方法创建并使用FlashCards填充ArrayList?

这些说明对我来说似乎有点模糊,我不明白需要做些什么来实现这一点,所以如果有人可以提供帮助,那将非常感谢,谢谢。

0 个答案:

没有答案