Question: This is a Java program. I will attach the template code at the bottom that needs to be implemented. Everything that needs to be added
This is a Java program. I will attach the template code at the bottom that needs to be implemented. Everything that needs to be added is marked with a /* TODO: complete implementation */, so I think the Box and FlashCard classes are complete. The FlashCard class says it's immutable. The Box class doesn't however. Please include comments in your code explaining functionality and approach decisions. If you don't know what the Leitner system is (I didn't), a quick youtube search of "Leitner flashcards" will make the program objective much more clear. Please read the assignment and follow the parameters (haven't had much success lately on here with that). Much appreciated.


FLASHCARFD CLASS /** * Represents a text based flashcard. * * This class is immutable. * @invariant front != null && back != null */ public class FlashCard { /** * Constructor setting up a flashcard object. * * @param challenge front of the card * @param response back of the card * @precondition challenge != null && response != null */ FlashCard(String challenge, String response) { assert challenge != null && response != null;
front = challenge; back = response; }
/** Returns the front side. */ public String getChallenge() { return front; }
/** Returns the back side. */ public String getResponse() { return back; }
/** * Produces a textual representation of this flashcard. * * @return a string containing two lines, one for front and one for back. */ public String toString() { return front + ' ' + back + ' '; }
private final String front; private final String back; }
-----------------------------------------------------------------------------------------------------------------------------
BOX CLASS
import java.util.List; import java.util.ArrayList; import java.util.Iterator;
/** * Implements a Leitner box holding flashcards. * * @invariant boxnum > 0 && cards != null */ public class Box { /** * Constructs a new Box. * * @param num Leitner box number * @precondition num > 0 */ public Box(int num) { assert num > 0;
boxnum = num; cards = new ArrayList
/** returns current number of flashcards in the box. */ public int size() { return cards.size(); }
/** * returns specific flashcard from the box. * * @param idx flashcard index * @return the queried Flashcard * @precondition 0
/** * Adds a new flashcard to this box. * * @param card the new flashcard * @precondition card is not yet in the box */ public void add(FlashCard card) { cards.add(card); }
/** * Removes a flashcard from the box. * * @param card the card to be removed * @precondition card is in this box */ public void remove(FlashCard card) { cards.remove(card); }
/** * Removes a flashcard from the box. * * @param idx of the card to be removed * @precondition 0
/** * Returns an ArrayList
for (FlashCard card : cards) copy.add(card);
return copy; }
/** Returns the Leitner-ID of this box. */ public int id() { return boxnum; }
private final int boxnum; /// Leitner id private final ArrayList
-------------------------------------------------------------------------------------------------------------------------------
FLASHCARD APP CLASS
import java.util.ArrayList;
/** * Class implementing a flashcard application * * @invariant boxes != null && boxes.size() > 0 */ public class FlashCardApp { /** Number of boxes. */ private final int MAX_BOXES = 5;
/** Constructs a new flashcard app object and initializes the boxes. */ public FlashCardApp() { /* TODO: complete implementation */ }
/** Returns an object according to the Leitner study method. */ public Leitner leitner() { /* TODO: complete implementation */ return null; }
/** * Returns an arraylist containing all flashcards in the system. * * @return ArrayList
/** * Returns an arraylist containing all flashcards that contain a pattern. * * @param pattern search pattern for texts on flashcards. * @return ArrayList
/* TODO: complete implementation */ return null; }
/** * Returns an arraylist that contains all flash cards in a given box. * * @param boxid Leitner box id. * @return ArrayList /* TODO: complete implementation */ return null; } /** * Creates a new flashcard and adds it to the first box. * * @precondition challenge != null && response != null */ public void create(String challenge, String response) { assert challenge != null && response != null; /* TODO: complete implementation */ } /* TODO: add private data members. */ } -------------------------------------------------------------------------------------------------------------------------- LEITNER CLASS import java.util.ArrayList; /** * A class implementing the Leitner system for flashcard boxes. * * @invariant boxes != null */ public class Leitner { /** * Constructs a new Leitner object. * * @precondition theBoxes != null */ public Leitner(ArrayList /** * Picks a random card and side from all boxes. * * Cards in lower boxes receive higher weight (priority). The method * returns void, but the picked card's sides can be accessed through * getQuestion and getAnswer, the answer tested using checkAnswer. * * @precondition there must be at least one box with one card. */ public void pickCard() { /* TODO: complete implementation */ } /** * Returns the question for the last picked card. * * @return the question * * @precondtion a card has been picked and not been tested. */ public String getQuestion() { /* TODO: complete implementation */ return null; } /** * Returns the answer for the last picked card. * * @return the answer * * @precondtion a card has been picked and not been tested. */ public String getAnswer() { /* TODO: complete implementation */ return null; } /** * Validates the response against the last picked card. * * @param s the response. * @return true, iff s was correct. s is assumed to be correct, if it is empty * or the string returned by getAnswer equals s. * * @precondition s != null */ public boolean testAnswer(String s) { /* TODO: complete implementation */ return true; } /** * Computes the box number where the card will be placed * * @param box current box number * @param correct indicates whether response was correct. * * @precondition box is a valid box number */ public int getTargetBox(int box, boolean correct) { /* TODO: computes the box where the current card needs to be placed. * 1 iff !correct * min(box+1, boxes.size()) iff correct */ return 0; } /** * Moves card to the target box, depending on whether succ indicates * a correct/incorrect response. * * @param correct, indicates whether the last response was correct. */ public void moveCard(boolean correct) { /* TODO: complete implementation */ } /* TODO: add data members */ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
