Advertisement
gdog2u

KBowlOpps

Feb 21st, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. //reads text from the line at rI
  2.     public static String getQuestion(String in, int rI){
  3.         LineNumberReader br = null;
  4.         String doc = in;
  5.         String thisLine ="";
  6.         while(rI%2==0){
  7.             rI++;
  8.         }
  9.         try{
  10.             br = new LineNumberReader(new FileReader(doc));
  11.             while((thisLine = br.readLine()) != null){
  12.                     if(br.getLineNumber() == rI){
  13.                         return thisLine;
  14.                     }  
  15.             }
  16.         }catch(IOException ee){
  17.             System.err.println("Error: " + ee);
  18.         }finally{
  19.             try{
  20.                 if(br != null){
  21.                     br.close();
  22.                 }  
  23.             }catch(IOException ex){
  24.            
  25.             }
  26.         }
  27.         System.out.println(rI);
  28.         return thisLine;
  29.     }
  30.     //reads text from the line down from rI
  31.     public static String getAnswer(String in, int rI){
  32.         String doc = in;
  33.         String thisLine="";
  34.         LineNumberReader br = null;
  35.         try{
  36.             br = new LineNumberReader(new FileReader(doc));
  37.             while((thisLine = br.readLine()) != null){
  38.                 if(br.getLineNumber() == rI +1){
  39.                     return "The correct answer was: " + thisLine + "\nIf you feel your answer might be questioned, please see Mr. Engel.";
  40.                 }
  41.             }
  42.         }catch(IOException ee){
  43.             System.err.println("Error: " + ee);
  44.         }finally{
  45.             try{
  46.                 if(br != null){
  47.                     br.close();
  48.                 }  
  49.             }catch(IOException ex){
  50.            
  51.             }
  52.         }
  53.         System.out.println(rI);
  54.         return thisLine;
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement