Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.util.LinkedList;
- import java.util.Random;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Main {
- static LinkedList<String> text1 = new LinkedList<>();
- static LinkedList<String> text2 = new LinkedList<>();
- static String word;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int rounds;
- pop1();
- pop2();
- System.out.print("How many times do you want to play? ");
- rounds = input.nextInt();
- for(int i = 0; i < rounds; i++)
- display();
- }
- public static void pop1(){
- try {
- Scanner input = new Scanner(new FileInputStream("text1.txt"));
- while(input.hasNextLine()){
- word = input.nextLine();
- text1.add(word);
- }
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void pop2(){
- try {
- Scanner input = new Scanner(new FileInputStream("text2.txt"));
- while(input.hasNextLine()){
- word = input.nextLine();
- text2.add(word);
- }
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void display(){
- Random random = new Random();
- int randomNumber = random.nextInt(text1.size()); //7
- int i = -1;
- do {
- i++;
- if(i == randomNumber)
- System.out.println(text1.get(i));
- } while (i != randomNumber + 1);
- System.out.print("The corresponding word in Italian is: ");
- try {
- Thread.sleep(3000);
- } catch (InterruptedException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println(text2.get(i-1));
- for(int a = 0; a < 5; a++)
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment