Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - DriverExam GUI

dickersonka
dickersonka 


Instead of doing Joe’s Automotive, develop a GUI that will get the answers from the user for the driver exam and then on the grading of the exam will reference the DriverExam class from Project 3 In Project 3 you were given a DriverExamDemo.java file that hardcoded answers and then validated the answers looked at attempt.passed(),attempt.totalCorrect(),attempt.totalIncorrect(), and attempt.questionsMissed() For this project you will capture the 20 answers from the user using JComboBox each filled with { " ", "A","B","C","D" }. When the user clicks grade, first confirm that they really want to grade, then you will instantiate a DriverExam object using the responses from the user. Hints: I used an array of combo boxes as a class field: private JComboBox[] questionBoxList = new JComboBox[NUM_QUESTIONS]; In the constructor for the Questions Panel I used a grid layout setLayout(new GridLayout(2, NUM_QUESTIONS)); Then in the constructor I initialized each combo box for(int i = 0; i < NUM_QUESTIONS; i++) questionBoxList[i] = new JComboBox(possibleAnswers); I also used an array of labels and then I used a loop to add all the labels to the panel and another loop to add all the combo boxes to the panel. On the Questions Panel I added a method that returned an array of Strings that was built from the ComboBoxes – that is what I called from the GradeButtonListener to get the questions to pass on to the instantiation of the DriverExam object: DriverExam attempt = new DriverExam(questionsPanel.getAnswers()); Attachments Tags Clarifications

Answers

Java - DriverExam GUI - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - DriverExam GUI assignment. Included is source and comments. Attachments
DriverExamGUI.zip (54 K) Download
Preview

Preview
} /** * Total incorrect on test * @return total incorrect */ public int totalIncorrect() { //test length - correct length return correctAnswers.length - totalCorrect(); } /** * Questions missed on test * @return questions missed

Preview
GradeExamListener()); //add button add(btnGradeExam); setSize(975, 175); } /** * Gets answers as string[] from combo boxes * @return */ private String[] getAnswers(){ //create array String[] answers = new String[questionBoxList.length]; //loop through each combo box

Screenshots
Screenshot
Purchase Answer