Solved

wanttobeamillionaire

Posted on 2001-06-18
8
323 Views
Last Modified: 2008-03-10
Write an application to make entries for the "Who wants to be a Millionaire?" game. The specification for the entry frame is given as a prototype, see Figure 1. The entry frame has three main components, the "Welcome" label, the question/answers panel and the buttons panel at the bottom.

 
Figure 1. Entry Frame for the questions.

The layout of the frame is defined within the attached java file. The functionality of each button is as follows:
Upon completion of an entry,
? If the <Add> button is pressed, then the data from the text fields and the radio button set is collected and used to create a new Question instance, then this question is added to the list(Vector) of questions. The fields are cleared.
? If the <Save> button is pressed, then all the data that was gathered within the list of questions(Vector) is written to a file. The fields are cleared. The list of questions are initialized to an empty list.
? If the <Read> button is pressed, then the list of questions is read from the file and used to set the data of the Vector.
The above scenario assumes the order of operation as <Add>?, <Save>, <Read>, <Next>?. If the user presses the <Save> before any <Add> happens, an empty Vector will be written to the file.

Project Part-I requires you to populate the saveQuestions() and readQuestions() methods.
Project Part-II requires you to add a <Next> button to the button panel with the following functionality:
? After a <Read> happens, if the <Next> button is pressed, then the next question in the Vector is displayed. You need to keep an index in order to remember the current position.
? Bonus: The <Next> button gets disabled when there are no elements in the Vector or if the end of Vector is reached.

The project should include:
 i. Error checking. Currently if there is no selection for the entry, an exception will be thrown. (Hint: You can place error checking for the missing elements in the constructor of the Question or elsewhere.)Exceptions handling (file io).
 ii. Full documentation using javadoc comments and the html files.
 iii. You can populate any of the components with explanatory text and modify the attributes.
 iv. No development environment tools are allowed. I do recognize the code generated by the IDE tools.
0
Comment
Question by:lawmer
  • 5
  • 2
8 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 6205734
Are you asking us to do your homework ?
0
 

Author Comment

by:lawmer
ID: 6206004
No I am not I just have never ever have taken a programming course and I was thrust into a graduate level java course in which had several prerequesits. A mistake from our advissor who was suppose to assign a programming appreciation course. On to top of that the professor is out of the country for questions.

Could you just get me in the ballpark this is way over my head.
0
 

Author Comment

by:lawmer
ID: 6206014
I have all of the templates I just need to know how to populate read and save
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 15

Accepted Solution

by:
ozymandias earned 75 total points
ID: 6207116
. Saving the vector to a file and restoring it from a file requires a technique called serialization. This is where an object is written (int this case to a file).

Look in the Java API documentation at the interface called Serializable.

Basically you create an ObjectOutputStream pointing to a file :

  File f = new File(your_file_name_goes_here);
  ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));

Then you call the writeObject method of the ObjectOutputStream and pass it the Vector :

  oos.writeObject(vector);

Getting the vector back from the file is thesame kind of thing but in reverse.

Here are a couple of examples :

SerialVector1 creates a vector of the arguments you pass it and serializes it to a file called serialvector.dat. SerialVector2 gets the vector back and prints out its contents.

0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6207117
import java.util.Vector;
import java.io.*;

public class SerialVector1{

     public static void main(String args[]){
          try{
               Vector v = new Vector();
               for (int i = 0; i < args.length; i++){
                    v.add(args[i]);
               }
               File f = new File("serialvector.dat");
               ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
               oos.writeObject(v);
          }catch(Exception e){
               e.printStackTrace(System.out);
          }
     }
}
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6207119
import java.util.Vector;
import java.io.*;

public class SerialVector2{

     public static void main(String args[]){
          try{
               File f = new File("serialvector.dat");
               ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
               Vector v = (Vector) ois.readObject();
               for (int i = 0; i < v.size(); i++){
                    System.out.println(((String)v.elementAt(i)));
               }
          }catch(Exception e){
               e.printStackTrace(System.out);
          }
     }
}
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6207137
Complie the above files and then run them like this :

  java SerialVector1 hello goodbye whatever etc

then

  java SerialVector2

The output from SerialVector2 should be :

  hello
  goodbye
  whatever
  etc

Cheers.


0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950803


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  points to ozymandias


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how do i compare an object based on two fields 6 54
jar file executable 12 52
by zero exception 10 41
Is there a simpler dropbox system? 10 21
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question