Skip to content

Instantly share code, notes, and snippets.

@AHaliq
Last active October 4, 2019 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AHaliq/7e90fa90ec77ca2189c4664024364ad4 to your computer and use it in GitHub Desktop.
Save AHaliq/7e90fa90ec77ca2189c4664024364ad4 to your computer and use it in GitHub Desktop.
Classes to model flashcards
abstract class CodeCard implements FlashCard {
protected String question;
protected String output;
public JavascriptCard(String q, String o) {
question = q;
output = o;
}
abstract render...
public JSONValue toJSON() { ... }
abstract Boolean evaluate(String code);
}
class Deck {
ArrayList<FlashCard> cards;
public Deck(ArrayList<FlashCard> initialCards) {
cards = initialCards;
}
public Node renderListView() {
// render all cards in one box
}
public Node renderTileView() {
//render tile of deck summary
}
}
interface FlashCard {
public JSONValue toJSON();
public Node renderFront();
public Node renderBack();
public Boolean evaluate(String in);
}
class FrontBackCard implements FlashCard {
protected String back;
protected String front;
public FrontBackCard(String f, String b) {
back = b;
front = f;
}
public Node renderFront() {
// creates javafx node and setup gui components
}
public Node renderBack() {
// like renderFront
}
public JSONValue toJSON() {
// my json class method calls
// create a json object and storing:
// type, front, back
}
public Boolean evaluate(String in) {
return in.equals(back);
}
}
public JavascriptCard extends CodeCard {
public JavascriptCard(String f, String o) {
super(f, s);
}
...render and tojson...
public Boolean evaluate(String code) {
return TimothyUtil.evalJS(code).equals(output);
}
}
public class Main
{
public static void main(String[] args) {
FlashCard c = new FrontBackCard("Which year did the NASA first land on the moon", "1969");
System.out.println(c.evaluate("1969")); \\ true
}
}
class MultipleChoiceCard extends FrontBackCard {
protected ArrayList<String> choices;
public MultipleChoiceCard(String f, String b, ArrayList<String> c) {
super(f, b);
choices = c;
}
public override renderFront() {
// show choices as well
}
public override JSONValue toJSON() {
// store choices and different type name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment