daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ca.roumani.i2c.*;
  2. import java.util.*;
  3.  
  4. public class Game {
  5.  
  6.     private CountryDB db;
  7.  
  8.     public Game() {
  9.         this.db = new CountryDB();
  10.  
  11.     }
  12.  
  13.     public String qa() {
  14.  
  15.         String result;
  16.  
  17.         List<String> capitals = db.getCapitals();
  18.         int n = capitals.size();
  19.         int index = (int) (n * Math.random());
  20.         String c = capitals.get(index);
  21.         Map<String, Country> data = db.getData();
  22.         Country ref = data.get(c);
  23.  
  24.         if (Math.random() < 0.5) {
  25.             result = "What is the capital of " + ref.getName() + "? " + "\n" + ref.getCapital();
  26.         }
  27.         else {
  28.             result = ref.getCapital() + " is the capital of?" + "\n" + ref.getName();
  29.         }
  30.             return result;
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.  
  35.         Game game = new Game();
  36.         System.out.println(game.qa());
  37.         String regex = "\n";
  38.         String[] split = game.qa().split(regex);
  39.         String question = split[0];
  40.         String answer = split[1];
  41.         System.out.println(question);
  42.         System.out.println(answer);
  43.     }
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top