Hi there! I am a beginner in Java, I am trying to complete this program which manipulates a database of product records.
my records are stored in a binary file and show the product name, price and quantity and look like this
Desktop Mac £499.99 25
I am trying to get the program to perform these 7 tasks
• Load the contents of the file into a suitable data structure
• Add a record
• Find and display product details for a specified product name
• Delete a product specified by product name
• Change the quantity and price of a specific product
• List products
• Store all changes back to the binary file
this is my code currently which is completely incorrect and does none of the above requirements.import java.io.*; import java.util.Scanner; public class Database { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); String fileName = null; String questionType; String question; String answerA; String answerB; String answerC; String answerD; String trueAnswer; int choice; String Delete; PrintWriter pWriter = null; //clears the print writer try { System.out.println("Your text file will be saved here: "); System.out.println("C:\\java\\records1.txt"); //text file will be saved in the stated directory pWriter = new PrintWriter(new FileWriter("C:\\java\\records.txt")); //where the text file is located } catch (IOException ex) { System.out.println("Doesn't exist, create a file and then try again"); } System.out.println("Product Database Menu"); System.out.println("******************************************"); System.out.println("1. Load File "); System.out.println("2. Add Product "); System.out.println("3. Find Product"); System.out.println("4. Delete Product "); System.out.println("5. Change product details "); System.out.println("6. List Products "); System.out.println("7. Quit and Store "); System.out.println(" *************************************** "); System.out.println(" Enter choice:> "); choice = input.nextInt(); if (choice == 1) String file_name = "C:/java/records.txt"; try { ReadFile file = new ReadFile (file_name); String[] aryLines = file.OpenFile(); int i; for (i=0; i < aryLines.length; i++) { System.out.println(aryLines[i]); } } catch (IOException e) { System.out.println( e.getMessage() ); } if (pWriter == null) { System.out.println("There is nothing to Save, returning to Menu"); } } else if (choice == 2) { } else if (choice == 3) { } else if (choice == 4) { { //if statement to delte questions System.out.println("*WARNING! THIS WILL DELETE ALL records, DO YOU WISH TO CONTINUE?*"); Delete = input.next(); if (Delete.equals("Y")) { pWriter.flush(); } } } else if (choice == 5) { } else if (choice == 6) { } else if (choice == 7) { } } } //end of program
please help!