Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ca.roumani.i2c.*;
- import java.util.*;
- public class Game {
- private CountryDB db;
- public Game() {
- this.db = new CountryDB();
- }
- public String qa() {
- String result;
- List<String> capitals = db.getCapitals();
- int n = capitals.size();
- int index = (int) (n * Math.random());
- String c = capitals.get(index);
- Map<String, Country> data = db.getData();
- Country ref = data.get(c);
- if (Math.random() < 0.5) {
- result = "What is the capital of " + ref.getName() + "? " + "\n" + ref.getCapital();
- }
- else {
- result = ref.getCapital() + " is the capital of?" + "\n" + ref.getName();
- }
- return result;
- }
- public static void main(String[] args) {
- Game game = new Game();
- System.out.println(game.qa());
- String regex = "\n";
- String[] split = game.qa().split(regex);
- String question = split[0];
- String answer = split[1];
- System.out.println(question);
- System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement