Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:01:28+00:00 2026-05-17T03:01:28+00:00

I’m building a CLI survey app in Java that lets users answer multiple-choice questions.

  • 0

I’m building a CLI survey app in Java that lets users answer multiple-choice questions. Please tell me how my approach can be improved.

Each answer to a question is recorded as an int, which is the index of that choice in the array of choices for that question. All answers for a survey are saved as an int array. I’m thinking of serializing this int array using ObjectOutputStream. Then when I need to display the results, I’ll restore the array and print each element after a tab.

The problem with this approach is (I believe) the second set of responses overwrites the first. I thought of two alternatives, both of which sound bad as well. One is saving each response set to a separate file. But then come display time, I’ll have to read all the files at once to keep responses for the same question together. The other is saving the int array as a tab-separated line in a plain text file (so each response set makes a new line), then tokenize and parse it back to an int array for displaying. But then the tokenizing/parsing code is a horror to read (currently it looks like this):

EDIT: Whoops, this code isn’t even right. My point is just that parsing is a mess, so I’m looking for a way not to have to parse.

File savedResults = new File(Main.surveyResultsFolder, surveyFileName);
try {
    BufferedReader br = new BufferedReader(new FileReader(savedResults));
    int[] currentResponseSet = new int[noOfQuestions];
    String currentResponseString = "";
    String[] currentResponseStrArray = null;
    while((currentResponseString = br.readLine()) != null) {
        currentResponseStrArray = currentResponseString.split("\t");

    for (int i = 0; i < currentResponseStrArray.length; i++) {
        currentResponseSet[i] = Integer.parseInt(currentResponseStrArray[i]);
}
    }
     //then I'll print currentResponseSet here.
    }
catch (IOException ex) {
    System.out.println("Error reading results file " + surveyFileName);
}

I’m out of ideas. As you can see, my knowledge of data handling techniques is limited. Any takers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:01:29+00:00Added an answer on May 17, 2026 at 3:01 am

    Several points:

    1. Saving data using an ObjectOutputStream is generally a bad idea. Saving data in human readable form is a superior choice.
    2. I don’t understand why you think the parsing logic you have there is ‘a horror’ — sure you can clean the code up a bit, but fundamentally, it seems ok.
    3. Have you considered storing the data in a database… relational or otherwise?
    4. Instead of using the array index position to tie an answer to a question, I would use question IDs. That way, the survey can evolve over time and you will still have semi-usable data. At the very least, you will have a partially complete answers. If you want minimalistic persistence form for such a structure, one idea is to store { record, question, answer } in each line of text. Reading the data would produce Map<record, Map<question, answer>>. You may find an ‘automap’ construct useful here:
        public abstract class AutoMap<K extends Comparable, V> 
        extends TreeMap<K, V> {
          protected abstract V createValue();
    
          public V getOrCreate(K key) {
            V value = get(key);
            if (value == null) {
              value = createValue();
              put(key, value);
            }
            return value;
          }
        }
    
        public class MapOfMaps<J extends Comparable, K extends Comparable, V> 
        extends AutoMap<J, Map<K, V>> {
          protected Map<K, V> createValue() {
            return new TreeMap<K, V>();
          }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.