I need to fix my Study Aid Program

DarkTetrad

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>();
}
 
  • +1
Reactions: Deleted member 22354
OH MAN all the identation got fucked by this site, dammit I'll have to put it on github later
 
Are you a hacker ? What do you plan to do with computer science?
 
Are you a hacker ? What do you plan to do with computer science?
That's what I'm trying to do. The only reason I know Java is because I thought learning high level languages would help with hacking and it soon became apparent that was far from the truth (or at least high level programming alone would provide next to zero hacking capabilities). So now I'm studying the x86 Instruction Set Architecture. But this is going to be a long process because there is also ARM (used by macOS, iOS, and Android). And servers use different ISAs. And I know next to nothing about network protocols.
 
  • Woah
Reactions: RAITEIII
My tip, subscribe to chatgpt plus, so you can use gpt4. Then you just have to copy paste your code and tell him what you want. Works very well in my experience and you save so much time. It will also improve your code
 
Code with gpt sair
 

Similar threads

Abhorrence
Replies
37
Views
926
SlavicGeneral
SlavicGeneral
BucketCrab
Replies
65
Views
6K
yue
yue
Baban
Replies
29
Views
4K
Allornothing
Allornothing
lestoa
Replies
47
Views
5K
W3ak
W3ak

Users who are viewing this thread

Back
Top