DarkTetrad
I am above law enforcement
- Joined
- Oct 29, 2022
- Posts
- 2,027
- Reputation
- 2,482
I made a Flash Card study aid program (unironically using CS knowledge to study CS itself) using Java and I want to add a search and delete feature but I'm too busy studying the Intel x86 Instruction Set Architecture, and then I have to study assemble that I'm too lazy to go back into the source code to do it...
So I delegate this simple task to you suboordinates, please add a delete flash card and search feature to my program... here's the source code:
import java.io.*;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Commands.download();
System.out.println("You've opened FlashText. Use the help command at any time.");
Commands.prompt();
}
}
public class Commands {
public static void download() {
try {
File file = new File("mem.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String front;
String back;
do {
front = bufferedReader.readLine();
back = bufferedReader.readLine();
if (front != null && back != null) {
Card card = new Card(front, back);
Card.pile.add(card);
}
} while (front != null && back != null);
} catch (
IOException e) {
e.printStackTrace();
}
}
public static void prompt() {
Scanner scanner = new Scanner(System.in);
String response = " ";
while (!response.equals("exit")) {
System.out.print("Enter a command: ");
response = scanner.nextLine();
System.out.println();
if (response.equals("help")) {
System.out.println("The commands are man, load, draw, flip, primary, secondary, and exit.");
System.out.println("For more info, type commandName -help");
continue;
}
if (response.equals("man")) {
System.out.println();
System.out.println("Ommitted to save space);
continue;
}
if (response.equals("primary -help")) {
System.out.println("This will place the current NoteCard in the primary pile. This pile should only contain mastered terms and concepts.");
continue;
}
if (response.equals("secondary -help")) {
System.out.println("This will place the current NoteCard in the secondary pile. This pile should contain terms and concepts not yet mastered.");
continue;
}
if (response.equals("load -help")) {
System.out.println("Allows for adding new NoteCard to the pile. Follow the prompt");
}
if (response.equals("save -help")) {
System.out.println("Saves a currently loading card.");
}
if (response.equals("draw -help")) {
System.out.println("draws the content of the current card.");
continue;
}
if (response.equals("man -help")) {
System.out.println("Short for manual. This command provides a detailed description of the FlashText program.");
continue;
}
if (response.equals("exit -help")) {
System.out.println("FlashText will be terminated.");
continue;
}
if (response.equals("flip -help")) {
System.out.println("This will draw the content from the other side of the NoteCard.");
continue;
}
if (response.equals("draw") || response.equals("dr")) {
draw();
continue;
}
if (response.equals("flip") || response.equals("fl")) {
flip();
continue;
}
if (response.equals("load")) {
load();
continue;
}
if (response.equals("Load")) {
Load();
continue;
}
if (response.equals("secondary") || response.equals("sec")) {
secondary();
continue;
}
if (response.equals("primary") || response.equals("pr")) {
primary();
}else {
if (!response.equals("exit")) {
System.out.println(response.trim() + " is not a valid command. Use the help command to see all available commands.");
} else {
System.out.println("You have terminated FlashText.");
}
}
}
}
public static void draw() {
Collections.shuffle(Card.pile);
if (Card.secPile.size() == 0 && Card.pile.size() == 0 && Card.priPile.size() == 0) {
System.out.print("The deck is empty. Add some cards using the Load command.\n");
prompt();
}
if (Card.secPile.size() == 0 && Card.pile.size() == 0) {
System.out.print("This deck has been mastered. The deck is now shuffled.\n");
Card.priPile.clear();
download();
prompt();
}
if (Card.pile.size() == 0) {
System.out.println("The secondary pile will now be shuffled.");
Card.pile.addAll(Card.secPile);
Card.secPile.clear();
prompt();
}
System.out.println(Card.pile.get(0).front);
}
public static void flip() {
Card.side = !Card.side;
if (Card.side) {
System.out.println(Card.pile.get(Card.i).front);
prompt();
}
if (!Card.side) {
System.out.println(Card.pile.get(Card.i).back);
prompt();
}
}
public static void primary() {
Card.priPile.add(Card.pile.get(0));
Card.pile.remove(0);
Card.side = true;
draw();
}
public static void secondary() {
Card.secPile.add(Card.pile.get(0));
Card.pile.remove(0);
Card.side = true;
draw();
}
public static void load() {
Card.side = true;
System.out.print("Enter the front of the card: ");
Scanner scanner = new Scanner(System.in);
String fr = scanner.nextLine();
System.out.print("Enter the back of the card: ");
String bk = scanner.nextLine();
System.out.println("");
Card card = new Card(fr, bk);
try {
FileWriter writer = new FileWriter("mem.txt", true);
writer.write(fr + "\n");
writer.write(bk + "\n");
writer.close();
} catch (IOException var5) {
var5.printStackTrace();
}
Card.pile.add(card);
}
public static void Load() {
Card.side = true;
Scanner scanner = new Scanner(System.in);
String frontOfCard = "Don't stop";
while (!frontOfCard.equals("stop")) {
System.out.print("Enter the front of the card: ");
frontOfCard = scanner.nextLine();
if (frontOfCard.equals("stop")) {
System.out.println();
} else {
System.out.print("Enter the back of the card: ");
String backOfCard = scanner.nextLine();
System.out.println();
Card card = new Card(frontOfCard, backOfCard);
try {
FileWriter writer = new FileWriter("mem.txt", true);
writer.write(frontOfCard + "\n");
writer.write(backOfCard + "\n");
writer.close();
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
System.exit(1);
}
Card.pile.add(card);
}
}
}
}
import java.util.ArrayList;
public class Card {
public static int i = 0;
public String front;
public String back;
public static boolean side = true;
public Card(String front, String back) {
this.front = front;
this.back = back;
}
static ArrayList<Card> pile = new ArrayList<Card>();
static ArrayList<Card> priPile = new ArrayList<Card>();
static ArrayList<Card> secPile = new ArrayList<Card>();
}
So I delegate this simple task to you suboordinates, please add a delete flash card and search feature to my program... here's the source code:
import java.io.*;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Commands.download();
System.out.println("You've opened FlashText. Use the help command at any time.");
Commands.prompt();
}
}
public class Commands {
public static void download() {
try {
File file = new File("mem.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String front;
String back;
do {
front = bufferedReader.readLine();
back = bufferedReader.readLine();
if (front != null && back != null) {
Card card = new Card(front, back);
Card.pile.add(card);
}
} while (front != null && back != null);
} catch (
IOException e) {
e.printStackTrace();
}
}
public static void prompt() {
Scanner scanner = new Scanner(System.in);
String response = " ";
while (!response.equals("exit")) {
System.out.print("Enter a command: ");
response = scanner.nextLine();
System.out.println();
if (response.equals("help")) {
System.out.println("The commands are man, load, draw, flip, primary, secondary, and exit.");
System.out.println("For more info, type commandName -help");
continue;
}
if (response.equals("man")) {
System.out.println();
System.out.println("Ommitted to save space);
continue;
}
if (response.equals("primary -help")) {
System.out.println("This will place the current NoteCard in the primary pile. This pile should only contain mastered terms and concepts.");
continue;
}
if (response.equals("secondary -help")) {
System.out.println("This will place the current NoteCard in the secondary pile. This pile should contain terms and concepts not yet mastered.");
continue;
}
if (response.equals("load -help")) {
System.out.println("Allows for adding new NoteCard to the pile. Follow the prompt");
}
if (response.equals("save -help")) {
System.out.println("Saves a currently loading card.");
}
if (response.equals("draw -help")) {
System.out.println("draws the content of the current card.");
continue;
}
if (response.equals("man -help")) {
System.out.println("Short for manual. This command provides a detailed description of the FlashText program.");
continue;
}
if (response.equals("exit -help")) {
System.out.println("FlashText will be terminated.");
continue;
}
if (response.equals("flip -help")) {
System.out.println("This will draw the content from the other side of the NoteCard.");
continue;
}
if (response.equals("draw") || response.equals("dr")) {
draw();
continue;
}
if (response.equals("flip") || response.equals("fl")) {
flip();
continue;
}
if (response.equals("load")) {
load();
continue;
}
if (response.equals("Load")) {
Load();
continue;
}
if (response.equals("secondary") || response.equals("sec")) {
secondary();
continue;
}
if (response.equals("primary") || response.equals("pr")) {
primary();
}else {
if (!response.equals("exit")) {
System.out.println(response.trim() + " is not a valid command. Use the help command to see all available commands.");
} else {
System.out.println("You have terminated FlashText.");
}
}
}
}
public static void draw() {
Collections.shuffle(Card.pile);
if (Card.secPile.size() == 0 && Card.pile.size() == 0 && Card.priPile.size() == 0) {
System.out.print("The deck is empty. Add some cards using the Load command.\n");
prompt();
}
if (Card.secPile.size() == 0 && Card.pile.size() == 0) {
System.out.print("This deck has been mastered. The deck is now shuffled.\n");
Card.priPile.clear();
download();
prompt();
}
if (Card.pile.size() == 0) {
System.out.println("The secondary pile will now be shuffled.");
Card.pile.addAll(Card.secPile);
Card.secPile.clear();
prompt();
}
System.out.println(Card.pile.get(0).front);
}
public static void flip() {
Card.side = !Card.side;
if (Card.side) {
System.out.println(Card.pile.get(Card.i).front);
prompt();
}
if (!Card.side) {
System.out.println(Card.pile.get(Card.i).back);
prompt();
}
}
public static void primary() {
Card.priPile.add(Card.pile.get(0));
Card.pile.remove(0);
Card.side = true;
draw();
}
public static void secondary() {
Card.secPile.add(Card.pile.get(0));
Card.pile.remove(0);
Card.side = true;
draw();
}
public static void load() {
Card.side = true;
System.out.print("Enter the front of the card: ");
Scanner scanner = new Scanner(System.in);
String fr = scanner.nextLine();
System.out.print("Enter the back of the card: ");
String bk = scanner.nextLine();
System.out.println("");
Card card = new Card(fr, bk);
try {
FileWriter writer = new FileWriter("mem.txt", true);
writer.write(fr + "\n");
writer.write(bk + "\n");
writer.close();
} catch (IOException var5) {
var5.printStackTrace();
}
Card.pile.add(card);
}
public static void Load() {
Card.side = true;
Scanner scanner = new Scanner(System.in);
String frontOfCard = "Don't stop";
while (!frontOfCard.equals("stop")) {
System.out.print("Enter the front of the card: ");
frontOfCard = scanner.nextLine();
if (frontOfCard.equals("stop")) {
System.out.println();
} else {
System.out.print("Enter the back of the card: ");
String backOfCard = scanner.nextLine();
System.out.println();
Card card = new Card(frontOfCard, backOfCard);
try {
FileWriter writer = new FileWriter("mem.txt", true);
writer.write(frontOfCard + "\n");
writer.write(backOfCard + "\n");
writer.close();
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
System.exit(1);
}
Card.pile.add(card);
}
}
}
}
import java.util.ArrayList;
public class Card {
public static int i = 0;
public String front;
public String back;
public static boolean side = true;
public Card(String front, String back) {
this.front = front;
this.back = back;
}
static ArrayList<Card> pile = new ArrayList<Card>();
static ArrayList<Card> priPile = new ArrayList<Card>();
static ArrayList<Card> secPile = new ArrayList<Card>();
}