Skip to content

Instantly share code, notes, and snippets.

@colmulhall
Created November 8, 2019 10:52
Show Gist options
  • Save colmulhall/6f90c1912c42ecd0e23af255722f8c6f to your computer and use it in GitHub Desktop.
Save colmulhall/6f90c1912c42ecd0e23af255722f8c6f to your computer and use it in GitHub Desktop.
A very brief attempt at writing a mini Bond movie ranker
package com.analog.adi0480.extractor;
import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;
public class BondRanker {
static String[] bonds = {
"Dr No",
"From Russia With Love",
"Goldfinger",
"Thunderball",
"You Only Live Twice",
"On Her Majestys Secret Service",
"Diamonds Are Forever",
"Live And Let Die",
"The Man With The Golden Gun",
"The Spy Who Loved Me",
"Moonraker",
"For Your Eyes Only",
"Octopussy",
"A View To A Kill",
"The Living Daylights",
"License to Kill",
"Goldeneye",
"Tomorrow Never Dies",
"The World Is Not Enough",
"Die Another Day",
"Casino Royale",
"Quantum Of Solace",
"Skyfall",
"Spectre"
};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
for (int i=0; i<100; i++) {
System.out.println("\n\n\n===================================================================\n");
int randomNumOne = ThreadLocalRandom.current().nextInt(0, bonds.length);
System.out.println("A: " + bonds[randomNumOne]);
int randomNumTwo = ThreadLocalRandom.current().nextInt(0, bonds.length);
System.out.println("B: " + bonds[randomNumTwo]);
System.out.println("\nWhich movie do you prefer? [Enter number A or B]");
String choice = scanner.nextLine();
if (choice.equalsIgnoreCase("A")) {
swap(bonds, randomNumOne, randomNumTwo);
} else if (choice.equalsIgnoreCase("B")) {
swap(bonds, randomNumTwo, randomNumOne);
} else {
System.out.println("\nInvalid choice!");
}
}
System.out.println("\nYour ranking of the Bond movies\n");
Arrays.stream(bonds).forEach(System.out::println);
}
private static <T> void swap (T[] a, int i, int j) {
T t = a[i];
a[i] = a[j];
a[j] = t;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment