Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Text file into an array then print

  • 07-05-2011 05:32PM
    #1
    Registered Users, Registered Users 2 Posts: 108 ✭✭


    Hi, I am new to Java.I am looking for some code for my mock exam.I am using netbeans and need to code to do the following.

    1.Provide the code to declare and create a two-dimensional String array to store data from answers.txt. Also, develop the actionPerformed method for the load button. When the user presses the load button the information should be read from answers.txt into this array.

    2.Develop the actionPerformed method for the display button. When the user presses the display button the students’ ids of those students who answered all questions correctly are displayed. The correct solution is TTFFTTFFTT. (Hint use JOptionPane to display).
    :)


Comments

  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    If you attended all of your classes / tutorials you would know how to do this.

    Never has there been an exam which asks you stuff that has not been covered.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    We don't help with code unless we see some efforts that you have put in first.


  • Registered Users, Registered Users 2 Posts: 108 ✭✭HotP0pp3r


    2. Provide the code to declare and create a two-dimensional String array to store data from answers.txt. Also, develop the actionPerformed method for the load button. When the user presses the load button the information should be read from answers.txt into this array.
    (25 marks)
    this part is really confusing me , as i am unsure how to create an array that would link the answers.txt file to it and then load it ? :/

    This is my attempt where i am using a different approach in the load button which is this: , but i dont think its correct since there is no array the answers.txt is loading from :/

    try{
    file = new Scanner(new File("C:/Users/answers.txt"));
    while (file.hasNext()){
    count++;
    line = file.nextLine();

    System.out.println(+count+" "+line);
    }
    }catch (Exception e){
    System.out.println(e.getMessage());
    }finally{
    if (file != null)
    file.close();
    }


Advertisement