Alright I've pretty much exhausted all other sources of information and still can't seen to understand how to do this, so here is my question:

I have a program that loads up a txt file, then displays a menu and allows people to choose options from that menu. If they choose option 1 for example, they are allowed to enter a persons name, and then it scans the array or the .txt file, however it works, and if it is there allows them to do other things, and if it is not there reports that it isn't.

How do you do this? I have no clue whatsoever. I'm not even 100% sure I did the loading in of the .txt file into an array properly. So can someone help me out? Here is what I have so far (the first if statement was where I began to attempt the option 1 that will scan for the name and allow changes):

// look up CASE SWITCH function

import java.lang.*;
import type.lib.Student;
import java.util.*;
import java.io.*;
import java.util.Scanner;

public class database {

   public static void main (String[] args) throws java.io.IOException{

         Scanner inputFile = new Scanner(new File("whatever.txt"));
    int sizeOfArray = inputFile.nextInt();
    int[] a = new int[sizeOfArray];

    for(int i = 0; inputFile.hasNextInt() && i < a.length; i++){
      a[i] = inputFile.nextInt();
    }
     
     
   {
     PrintStream output = System.out;
    Scanner input = new Scanner(System.in);
    
    final int TOTAL_RECORDS = 10;
    
    String []menu = { "1 - Add Courses and Grades" ,
                      "2 - View a Course Grade",
                      "3 - View GPA",
                      "4 - View all Courses and Grades",
                      "5 - View student record",
                      "6 - Output entire databse to a file",
                         "Quit - Exit databse"};

for (int i = 0; i < menu.length; i++)
System.out.println(menu[i]);


System.out.print("Enter menu option: ");
String choice = input.next();

if (choice.equals("1"))  { output.println("Enter the full name of the student:");
String name = input.next();}

while (!choice.equals("Quit"))
{
try
{
int intChoice = Integer.parseInt(choice);
System.out.println("Choice was: " + intChoice);
if ((intChoice < 1) || (intChoice > 4))
System.out.println("Invalid choice made. Choose again.");
}
catch (Exception e)
{
System.out.println("Invalid choice made. Choose again.");
}

System.out.print("Enter menu option: ");
choice = input.next();


   }
}
}
}

And just as a side note, I'm only supposed to use 2 for statements, one to load up the .txt and the other to handle the menu using control structures.

Recommended Answers

All 2 Replies

-

It compiles fine for me...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.