Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: BlueJ

  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BlueJ

    Hello all,

    Making a multiple choice quiz using Blue J.

    My task is to enable the user to add questions and answers.
    Replace and remove specific answers and questions.
    Print out all the questions and answers once they are finished.
    Then quit the program.

    The user will also need to be able to quit the program at anytime.

    I am having trouble understanding how i would go about doing this, i figured i would store all the questions using an array or array list?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Depends on your level of knowledge with the language. Given that you have an unknown number of questions and answers, an ArrayList or Vector make sense to me. You can have two to track sets together. You could be creative and use a LinkedHashSet (? I think thats what its called in Java), and link a question -> answer combination as well. HashSets take more practice to use though.
    I would avoid a flat array if you can. The only problem with them is that if you don't know how many elements there are to start with, you'll need to manually resize them as well which is a pain. ArrayLists and Vectors do this for you.

    Also, in the future please select a thread title better suiting to the question itself. BlueJ is simply an IDE, it has no relevance to the task. This can be done in any IDE capable of Java programming such as eclipse, BlueJ, Netbeans, Dr.Java or even VI/Notepad with a manual compile.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well my knowledge on java at the moment is rather basic im still in the learning process. I dont no much about Hashset but i no a little about the ArrayList do you think it will be possible for you to spend 5 minutes on skype and talk me through how i could go about using this.

    lastly sorry about the thread title.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't have skype, and I don't do IM's either.
    The idea is simple, use two ArrayList's, one for questions and one for answers. You will end up needing an interface of some sort (viewable I mean, like enter a number to pick a choice, not an object skeleton), then you simply ask the user to enter a question, and immediately follow up with asking an answer. Store these one by one in the associated arrayList. Use Scanner for ease, unless you are using a gui then its a text input of some sorts.
    To print, simply iterate each item in the questions list, and draw at the same time from the answers:
    PHP Code:
    int iLength alQuestions.size();
    for (
    int i 0iLength; ++i)
    {
        
    System.out.println("Question: " alQuestions.get(i) + "; answer: " alAnswers.get(i));

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because i'm using bluej, the interface i will be using is the terminal window.
    Luckily i have the scanner class however, I'm not sure on how to code it so that it will ask the user a question and then store their response to an arraylist.
    I also don't know how to store an answer so that it links to the question in the other array list.

    Sorry to be a pain but my knowledge is very basic.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Scanner uses the nextLine method to return an entire line. This is nice since its always a string and you don't need to worry about it leaving linefeeds on the scanner.
    PHP Code:
    ArrayList<StringalQuestions = new ArrayList<String>();
    ArrayList<StringalAnswers = new ArrayList<String>();

    Scanner s = new Scanner(System.in);
    System.out.print("Enter a question: ");
    alQuestions.add(s.nextLine());
    System.out.print("Enter an answer: ");
    alAnswers.add(s.nextLine()); 
    There is no link between a question and an answer, that is programatically controlled. The index associated with a question is the same index for the answer.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey thanks for all the help, i didn manage to get it done because i forgot to mention that i already have a question class which the user can call the method to add the answer in an array. But i dont wanna bother you anymore lool thanks for everything.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •