Advertisement
gdog2u

2D ArrayList<Solution>

May 3rd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.08 KB | None | 0 0
  1. public class KBowlOpps{
  2.     public static ArrayList<QuestionAnswer> getChallengeQuestions(){
  3.         ArrayList<QuestionAnswer> questAns = new ArrayList<QuestionAnswer>();
  4.         /**
  5.          * for(int i=0;i<questAns.length;i++){
  6.             questAns[i] = new QuestionAnswer();
  7.         }
  8.          */
  9.         int j = 0;
  10.         int k = 0;
  11.         int rI;
  12.         for(int i = 0; i < 20;i++){
  13.             for(; j < (k+3) && j < 60; j++){
  14.                 Random r = new Random();
  15.                 try{
  16.                     rI = r.nextInt(arrays.get(i).size());
  17.                     while(rI%2 != 0){
  18.                         rI++;
  19.                     }
  20.                         //questAns[j].setQuestion(arrays[i][rI]);
  21.                         //questAns[j].setAnswer(arrays[i][(rI + 1)]);
  22.                     questAns.add(new QuestionAnswer(arrays.get(i).get(rI), arrays.get(i).get(rI + 1)));
  23.                 }catch(IndexOutOfBoundsException e){
  24.                    
  25.                 }
  26.             }
  27.             k = j;
  28.         }
  29.         questAns = shuffle(questAns);
  30.         for(int l = 0; l <questAns.size() && questAns.get(l).getQuestion() != null; l++){
  31.             System.out.println((l + 1)+") "+questAns.get(l).getQuestion());
  32.             System.out.println("    "+(l + 1)+") "+questAns.get(l).getAnswer());
  33.         }
  34.         return questAns;
  35.     }
  36.     public static ArrayList<QuestionAnswer> shuffle(ArrayList<QuestionAnswer> in){
  37.         ArrayList<QuestionAnswer> out = new ArrayList<QuestionAnswer>();
  38.         ArrayList<Integer> used = new ArrayList<Integer>();
  39.         int usedInt;
  40.         Random r = new Random();
  41.         for(int i = 0; i < in.size(); i++){
  42.             usedInt = r.nextInt(in.size());
  43.             while(used.contains(usedInt)){
  44.                 usedInt = r.nextInt(in.size());
  45.             }
  46.             out.add(in.get(usedInt));
  47.             used.add(usedInt);
  48.         }
  49.         return out;
  50.     }
  51. }
  52.  
  53. public class KBowlCats{
  54.     public final static File MATH = new File("src/assets/files/math.txt");
  55.     public final static File GLOBAL_TECH = new File("src/assets/files/gt.txt");
  56.     public final static File ARTS = new File("src/assets/files/arts.txt");
  57.     public final static File CAPITALS  = new File("src/assets/files/cap.txt");
  58.     public final static File ENGLISH = new File("src/assets/files/eng.txt");
  59.     public final static File DEFAULT = new File("src/assets/files/default.txt");
  60.     public final static File GEOGRAPHY = new File("src/assets/files/geo.txt");
  61.     public final static File GOVERNMENT = new File("src/assets/files/gov.txt");
  62.     public final static File HEALTH = new File("src/assets/files/hea.txt");
  63.     public final static File HISTORY = new File("src/assets/files/his.txt");
  64.     public final static File ITF = new File("src/assets/files/itf.txt");
  65.     public final static File LITERATURE = new File("src/assets/files/lit.txt");
  66.     public final static File OHIO_HISTORY = new File("src/assets/files/ohi.txt");
  67.     public final static File OUR_US = new File("src/assets/files/ous.txt");
  68.     public final static File POTPURRI = new File("src/assets/files/pot.txt");
  69.     public final static File SAFETY = new File("src/assets/files/saf.txt");
  70.     public final static File SCIENCE = new File("src/assets/files/sci.txt");
  71.     public final static File SPELLING = new File("src/assets/files/spe.txt");
  72.     public final static File SPORTS = new File("src/assets/files/spo.txt");
  73.     public final static File VIP = new File("src/assets/files/vip.txt");
  74.     public final static File WORK_LEADERSHIP = new File("src/assets/files/wor.txt");
  75.  
  76.     public static ArrayList<String> arts = new ArrayList<String>();
  77.     public static ArrayList<String> capitals = new ArrayList<String>();
  78.     public static ArrayList<String> english = new ArrayList<String>();
  79.     public static ArrayList<String> geography = new ArrayList<String>();
  80.     public static ArrayList<String> globalTech = new ArrayList<String>();
  81.     public static ArrayList<String> government = new ArrayList<String>();
  82.     public static ArrayList<String> health = new ArrayList<String>();
  83.     public static ArrayList<String> history = new ArrayList<String>();
  84.     public static ArrayList<String> itf = new ArrayList<String>();
  85.     public static ArrayList<String> literature = new ArrayList<String>();
  86.     public static ArrayList<String> math = new ArrayList<String>();
  87.     public static ArrayList<String> ohioHistory = new ArrayList<String>();
  88.     public static ArrayList<String> ourUS = new ArrayList<String>();
  89.     public static ArrayList<String> potpurri = new ArrayList<String>();
  90.     public static ArrayList<String> safety = new ArrayList<String>();
  91.     public static ArrayList<String> science = new ArrayList<String>();
  92.     public static ArrayList<String> spelling = new ArrayList<String>();
  93.     public static ArrayList<String> sports = new ArrayList<String>();
  94.     public static ArrayList<String> vip = new ArrayList<String>();
  95.     public static ArrayList<String> workLeadership = new ArrayList<String>();
  96.    
  97.     public static ArrayList<ArrayList<String>> fillArrays(){
  98.         ArrayList<ArrayList<String>> out = new ArrayList<ArrayList<String>>();
  99.         Scanner in;
  100.         try {
  101.             in = new Scanner(MATH);
  102.             while(in.hasNext()){
  103.                 math.add(in.nextLine());
  104.             }
  105.             out.add(math);
  106.         } catch (FileNotFoundException e) {
  107.             System.err.println("File: "+ MATH+" not found.");
  108.         }
  109.         try {
  110.             in = new Scanner(GLOBAL_TECH);
  111.             while(in.hasNext()){
  112.                 globalTech.add(in.nextLine());
  113.             }
  114.             out.add(globalTech);
  115.         } catch (FileNotFoundException e) {
  116.             System.err.println("File: "+ GLOBAL_TECH+" not found.");
  117.         }
  118.         try {
  119.             in = new Scanner(ARTS);
  120.             while(in.hasNext()){
  121.                 arts.add(in.nextLine());
  122.             }
  123.             out.add(arts);
  124.         } catch (FileNotFoundException e) {
  125.             System.err.println("File: "+ ARTS+" not found.");
  126.         }
  127.         try {
  128.             in = new Scanner(CAPITALS);
  129.             while(in.hasNext()){
  130.                 capitals.add(in.nextLine());
  131.             }
  132.             out.add(capitals);
  133.         } catch (FileNotFoundException e) {
  134.             System.err.println("File: "+ CAPITALS+" not found.");
  135.         }
  136.         try {
  137.             in = new Scanner(ENGLISH);
  138.             while(in.hasNext()){
  139.                 english.add(in.nextLine());
  140.             }
  141.             out.add(english);
  142.         } catch (FileNotFoundException e) {
  143.             System.err.println("File: "+ ENGLISH+" not found.");
  144.         }
  145.         try {
  146.             in = new Scanner(GEOGRAPHY);
  147.             while(in.hasNext()){
  148.                 geography.add(in.nextLine());
  149.             }
  150.             out.add(geography);
  151.         } catch (FileNotFoundException e) {
  152.             System.err.println("File: "+ GEOGRAPHY+" not found.");
  153.         }
  154.         try {
  155.             in = new Scanner(GOVERNMENT);
  156.             while(in.hasNext()){
  157.                 government.add(in.nextLine());
  158.             }
  159.             out.add(government);
  160.         } catch (FileNotFoundException e) {
  161.             System.err.println("File: "+ GOVERNMENT+" not found.");
  162.         }
  163.         try {
  164.             in = new Scanner(HEALTH);
  165.             while(in.hasNext()){
  166.                 health.add(in.nextLine());
  167.             }
  168.             out.add(health);
  169.         } catch (FileNotFoundException e) {
  170.             System.err.println("File: "+ HEALTH+" not found.");
  171.         }
  172.         try {
  173.             in = new Scanner(HISTORY);
  174.             while(in.hasNext()){
  175.                 history.add(in.nextLine());
  176.             }
  177.             out.add(history);
  178.         } catch (FileNotFoundException e) {
  179.             System.err.println("File: "+ HISTORY +" not found.");
  180.         }
  181.         try {
  182.             in = new Scanner(ITF);
  183.             while(in.hasNext()){
  184.                 itf.add(in.nextLine());
  185.             }
  186.             out.add(itf);
  187.         } catch (FileNotFoundException e) {
  188.             System.err.println("File: "+ ITF+" not found.");
  189.         }
  190.         try {
  191.             in = new Scanner(LITERATURE);
  192.             while(in.hasNext()){
  193.                 literature.add(in.nextLine());
  194.             }
  195.             out.add(literature);
  196.         } catch (FileNotFoundException e) {
  197.             System.err.println("File: "+ LITERATURE+" not found.");
  198.         }
  199.         try {
  200.             in = new Scanner(OHIO_HISTORY);
  201.             while(in.hasNext()){
  202.                 ohioHistory.add(in.nextLine());
  203.             }
  204.             out.add(ohioHistory);
  205.         } catch (FileNotFoundException e) {
  206.             System.err.println("File: "+ OHIO_HISTORY+" not found.");
  207.         }
  208.         try {
  209.             in = new Scanner(OUR_US);
  210.             while(in.hasNext()){
  211.                 ourUS.add(in.nextLine());
  212.             }
  213.             out.add(ourUS);
  214.         } catch (FileNotFoundException e) {
  215.             System.err.println("File: "+ OUR_US+" not found.");
  216.         }
  217.         try {
  218.             in = new Scanner(POTPURRI);
  219.             while(in.hasNext()){
  220.                 potpurri.add(in.nextLine());
  221.             }
  222.             out.add(potpurri);
  223.         } catch (FileNotFoundException e) {
  224.             System.err.println("File: "+ POTPURRI+" not found.");
  225.         }
  226.         try {
  227.             in = new Scanner(SAFETY);
  228.             while(in.hasNext()){
  229.                 safety.add(in.nextLine());
  230.             }
  231.             out.add(safety);
  232.         } catch (FileNotFoundException e) {
  233.             System.err.println("File: "+ SAFETY+" not found.");
  234.         }
  235.         try {
  236.             in = new Scanner(SCIENCE);
  237.             while(in.hasNext()){
  238.                 science.add(in.nextLine());
  239.             }
  240.             out.add(science);
  241.         } catch (FileNotFoundException e) {
  242.             System.err.println("File: "+ SCIENCE+" not found.");
  243.         }
  244.         try {
  245.             in = new Scanner(SPELLING);
  246.             while(in.hasNext()){
  247.                 spelling.add(in.nextLine());
  248.             }
  249.             out.add(spelling);
  250.         } catch (FileNotFoundException e) {
  251.             System.err.println("File: "+ SPELLING+" not found.");
  252.         }
  253.         try {
  254.             in = new Scanner(SPORTS);
  255.             while(in.hasNext()){
  256.                 sports.add(in.nextLine());
  257.             }
  258.             out.add(sports);
  259.         } catch (FileNotFoundException e) {
  260.             System.err.println("File: "+ SPORTS+" not found.");
  261.         }
  262.         try {
  263.             in = new Scanner(VIP);
  264.             while(in.hasNext()){
  265.                 vip.add(in.nextLine());
  266.             }
  267.             out.add(vip);
  268.         } catch (FileNotFoundException e) {
  269.             System.err.println("File: "+ VIP+" not found.");
  270.         }
  271.         try {
  272.             in = new Scanner(WORK_LEADERSHIP);
  273.             while(in.hasNext()){
  274.                 workLeadership.add(in.nextLine());
  275.             }
  276.             out.add(workLeadership);
  277.         } catch (FileNotFoundException e) {
  278.             System.err.println("File: "+ WORK_LEADERSHIP+" not found.");
  279.         }
  280.         return out;
  281.     }
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement