codeXecutable

Language Game

Mar 3rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1.  
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.util.LinkedList;
  5. import java.util.Random;
  6. import java.util.Scanner;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9.  
  10.  
  11. public class Main {
  12.    
  13.     static LinkedList<String> text1 = new LinkedList<>();
  14.     static LinkedList<String> text2 = new LinkedList<>();
  15.     static String word;
  16.    
  17.     public static void main(String[] args) {
  18.         Scanner input = new Scanner(System.in);
  19.         int rounds;
  20.         pop1();
  21.         pop2();
  22.        
  23.         System.out.print("How many times do you want to play? ");
  24.         rounds = input.nextInt();
  25.        
  26.         for(int i = 0; i < rounds; i++)
  27.             display();
  28.     }
  29.    
  30.     public static void pop1(){
  31.         try {
  32.             Scanner input = new Scanner(new FileInputStream("text1.txt"));
  33.             while(input.hasNextLine()){
  34.                 word = input.nextLine();
  35.                 text1.add(word);
  36.             }                
  37.         } catch (FileNotFoundException ex) {
  38.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  39.         }
  40.     }
  41.    
  42.     public static void pop2(){
  43.         try {
  44.             Scanner input = new Scanner(new FileInputStream("text2.txt"));
  45.             while(input.hasNextLine()){
  46.                 word = input.nextLine();
  47.                 text2.add(word);
  48.             }                
  49.         } catch (FileNotFoundException ex) {
  50.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  51.         }
  52.     }
  53.    
  54.     public static void display(){
  55.         Random random = new Random();
  56.         int randomNumber = random.nextInt(text1.size()); //7
  57.         int i = -1;
  58.        
  59.         do {            
  60.             i++;
  61.            
  62.             if(i == randomNumber)
  63.                 System.out.println(text1.get(i));            
  64.         } while (i != randomNumber + 1);
  65.        
  66.         System.out.print("The corresponding word in Italian is: ");
  67.        
  68.         try {
  69.             Thread.sleep(3000);
  70.         } catch (InterruptedException ex) {
  71.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  72.         }
  73.        
  74.         System.out.println(text2.get(i-1));
  75.        
  76.         for(int a = 0; a < 5; a++)
  77.             System.out.println();
  78.     }
  79. }
Add Comment
Please, Sign In to add comment