Click here to Skip to main content
16,011,438 members
Home / Discussions / Java
   

Java

 
AnswerRe: How to resizethe backGround Image to JPanel? Pin
David Skelly9-Jun-10 5:22
David Skelly9-Jun-10 5:22 
GeneralRe: How to resizethe backGround Image to JPanel? Pin
002comp9-Jun-10 17:52
002comp9-Jun-10 17:52 
GeneralRe: How to resizethe backGround Image to JPanel? Pin
David Skelly9-Jun-10 22:26
David Skelly9-Jun-10 22:26 
GeneralRe: How to resizethe backGround Image to JPanel? Pin
002comp10-Jun-10 1:05
002comp10-Jun-10 1:05 
QuestionDrop Down Pin
Wcmedic8-Jun-10 11:39
Wcmedic8-Jun-10 11:39 
AnswerRe: Drop Down Pin
Nagy Vilmos8-Jun-10 20:16
professionalNagy Vilmos8-Jun-10 20:16 
GeneralRe: Drop Down Pin
Wcmedic9-Jun-10 6:05
Wcmedic9-Jun-10 6:05 
GeneralStudent Report Program Pin
CodeScribbler7-Jun-10 20:45
CodeScribbler7-Jun-10 20:45 
This is an assignment I'm trying to solve. I'm still fairly new to java and would like some assistance, if anyone is willing. Please ignore the modelAnswer() class, and focus on the getStudentAnswers. I was having trouble extracting chars from the array, and tried to use a switch statement instead.

For the moment our lecturer hasn't introduced Java GUI's and I've just used JOptionPane so far.

Please feel free to email me suggestions Wink | ;)


/**
*
*Create a program to mark a set of multiple choice test results. This is *a console program
*
*that uses JOptionPane dialog boxes as well.
*
*Read a set of ten correct answers useing JOptionPane dialog box and *store the entire answer
*
*as one string in one variable. There are no spaces between the letters *and the user may
*
*enter capital or small letters. Here's is the sample input box:
*
* JOptionPane.showInputDialog("Please enter the answers to the ten *multiple choice questions
*
*\nno spaces and all in Capital letters e.g. ABCDEABCDE");
*
*
*Extract each letter from this string and fill an array with 10 letter *answers. This is done
*
*in a method loadAnswers after the above. When the answers have been *written to the array,
*
*display the following confirmation box.
*
*
*JOptionPane.showConfirmDialog(null, "The information has been saved.");
*
*The program must then ask the user for the number of students to *process as shown below:
*
*
*JOptionPane.showInputDialog("Please enter the number of students :");
*
*Thereafter the program must prompt the user for a student name and *thereafter for the
*
*student's 10 answers. Use Input Dialog boxes to achieve this. The 10 *answers for the student
*
*must be saved in another array.
*
*JOptionPane.showInputDialog("Please enter the student name");
*
*Please ensure the wording in the dialog boxes is shown in the figures *above.
*
*After successful capture of the marks, show another success *confirmation dialog box as shown
*
*in the second figure above. Thereafer compare the student's answers *with the answers in the
*
*answer array. Keep a count of the number of answers from the student's *record that match the
*
*answers in the answer key.
*
*Store the student's name and the number of correct answers in another *array(s).
*Calculate the symbol based on the following table:
*
*SCORE GRADE
*
*9-10 - A Above Average
*8 - B Above Average
*7 - C Above Average
*6 - D Above Average
*5 - E Below Average
*0-4 - F Below Average
*
*
*For each student, display the student's name and the number of correct *answers and a symbol
*
*(letter grade). Calculate the average number of correct answers for the *class and report it
*
*in a format similiar to the one on the next page.
*
*Example:
*
*Jean 10 A
*Jack 7 C
*George 9 A
*Paul 5 E
*Steven 7 C
*Jackie 6 D
*Susan 0 F
*Greg 8 B
*Gabby 8 B
*Andrea 9 A
*
*Using the array of student records, display a list of all students. *Report if a student had
*
*an average, above average with the number of correct answers shown *below.
*
*To end the program display a dialog box asking the user for *confirmation of exit as shown
*
*below.
*
*JOptionPane.showConfirmDialogBox
*
*
*Generally you are required *to
*
*1. Follow good programming practices
*2. Add appropriate comments.
*3. You must use methods and appropriate parameter passing.
*4. Use variables, class and method naming standards.
*
*
*
*
*
*
*
*
*Project Name: Student Marks System
* Developer: Code Scribbler
* Date: 6 June 2010
* Aim: To store test marks of multiple students and
* display their Aggregates, including the symbol
* scored (e.g. Name: George Mark: 9 Symbol: A)
*
* Contact: madpoet19@gmail.com
*/

import java.util.*;
import javax.swing.*;
public class Question1 {

public static String modelAnswer;
public static String studentName;
public static String studentAnswers;
public static int ansPosition01;
public static int ansPosition02;
public static int ansPosition03;
public static int ansPosition04;
public static int ansPosition05;
public static int ansPosition06;
public static int ansPosition07;
public static int ansPosition08;
public static int ansPosition09;
public static int ansPosition10;
public static int numOfStudents;
public static int nameCount;
public static int answerCount;
public static int nameSize;
public static String[] arrNameOfStudent = new String [numOfStudents];
public static String[] arrStudentAnswers = new String [numOfStudents];

public static void main(String[] args) {

modelAnswer();
getStudentAnswers(studentName, studentAnswers, nameCount, answerCount);


}//end main

public static void modelAnswer()
{
modelAnswer = JOptionPane.showInputDialog("Please enter the answers to the ten multiple choice questions \nno spaces and all in Capital letters e.g. ABCDEABCDE");

int init1;
int init2;

init1 = modelAnswer.indexOf(" ");
init2 = modelAnswer.indexOf(" ", init1 +1);

//System.out.println("Answers: " + modelAnswer.charAt(0) + " " + modelAnswer.charAt(init1 +1) + " " + modelAnswer.charAt(init2 +1) + " ");
//return modelAnswer();
}//end modelAnswer

public static void getStudentAnswers(String studentName, String studentAnswers, int nameCount, int answerCount)
{

numOfStudents = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of students :"));
char caseSymbol;
String finalSymbol = "";
String finalResult = "";
int questionScore = 0;
double questionScoreAvg = 0;

for (nameCount = 1; nameCount < 11; nameCount++)
{
studentName = JOptionPane.showInputDialog("Please enter the student name:");
Arrays.fill(arrNameOfStudent, studentName);

for (answerCount = 1; answerCount < 11; answerCount++)
{
studentAnswers = JOptionPane.showInputDialog("Please enter " + studentName + "'s answer for Question " + answerCount);
Arrays.fill(arrStudentAnswers, studentAnswers);

if (answerCount == 1)
{
ansPosition01 = studentAnswers.indexOf(" ");
caseSymbol = studentAnswers.charAt(1);
switch (caseSymbol)
{
case 'A':
questionScore = (questionScore +1);
break;
}//end switch statment
}//end if

else if (answerCount == 2)
{
ansPosition02 = studentAnswers.indexOf(" ", ansPosition01 +1);
caseSymbol = studentAnswers.charAt(2);
switch (caseSymbol)
{
case 'B':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 3)
{
ansPosition03 = studentAnswers.indexOf(" ", ansPosition02 +2);
caseSymbol = studentAnswers.charAt(3);
switch (caseSymbol)
{
case 'C':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 4)
{
ansPosition04 = studentAnswers.indexOf(" ", ansPosition03 +3);
caseSymbol = studentAnswers.charAt(4);
switch (caseSymbol)
{
case 'D':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 5)
{
ansPosition05 = studentAnswers.indexOf(" ", ansPosition04 +4);
caseSymbol = studentAnswers.charAt(5);
switch (caseSymbol)
{
case 'E':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 6)
{
ansPosition06 = studentAnswers.indexOf(" ", ansPosition05 +5);
caseSymbol = studentAnswers.charAt(6);
switch (caseSymbol)
{
case 'A':
questionScore = (questionScore +1);
break;


}//end switch statment
}//end elseif

else if (answerCount == 7)
{
ansPosition07 = studentAnswers.indexOf(" ", ansPosition06 +6);
caseSymbol = studentAnswers.charAt(7);
switch (caseSymbol)
{

case 'B':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 8)
{
ansPosition08 = studentAnswers.indexOf(" ", ansPosition07 +7);
caseSymbol = studentAnswers.charAt(8);
switch (caseSymbol)
{
case 'C':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 9)
{
ansPosition09 = studentAnswers.indexOf(" ", ansPosition08 +8);
caseSymbol = studentAnswers.charAt(9);
switch (caseSymbol)
{
case 'D':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif

else if (answerCount == 10)
{
ansPosition10 = studentAnswers.indexOf(" ", ansPosition09 +9);
caseSymbol = studentAnswers.charAt(10);
switch (caseSymbol)
{
case 'E':
questionScore = (questionScore + 1);
break;

}//end switch statment
}//end elseif



if (questionScore == 0 || questionScore == 1 || questionScore == 2 || questionScore == 3 || questionScore == 4)
{
finalSymbol = "F";
}
else if (questionScore == 5)
{
finalSymbol = "E";
}
else if (questionScore == 6)
{
finalSymbol = "D";
}
else if (questionScore == 7)
{
finalSymbol = "C";
}
else if (questionScore == 8)
{
finalSymbol = "B";
}
else if (questionScore == 9 || questionScore == 10)
{
finalSymbol = "A";
}

if (questionScore > 5)
{
finalResult = "Above Average";
}//end final result if
else if (questionScore < 5)
{
finalResult = "Below Average";
}//end final result elseif


questionScoreAvg = (questionScoreAvg + questionScore);

System.out.println(studentName + "\t" + questionScore + "\t" + finalSymbol + "\t" + finalResult);



}//end inner loop

questionScoreAvg = (questionScoreAvg / 100);

System.out.println("\n" + "\n" + "The class average is: " + questionScoreAvg);

}//end outer loop

}//end getStudentAnswers

}//end class
GeneralRe: Student Report Program Pin
Richard MacCutchan7-Jun-10 21:47
mveRichard MacCutchan7-Jun-10 21:47 
GeneralStudent Report Program Pin
CodeScribbler7-Jun-10 22:46
CodeScribbler7-Jun-10 22:46 
GeneralRe: Student Report Program Pin
Richard MacCutchan8-Jun-10 3:42
mveRichard MacCutchan8-Jun-10 3:42 
GeneralRe: Student Report Program Pin
CodeScribbler9-Jun-10 3:34
CodeScribbler9-Jun-10 3:34 
GeneralRe: Student Report Program Pin
Richard MacCutchan9-Jun-10 4:29
mveRichard MacCutchan9-Jun-10 4:29 
QuestionHow to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
PJanaki6-Jun-10 20:48
PJanaki6-Jun-10 20:48 
AnswerRe: How to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
David Skelly6-Jun-10 22:24
David Skelly6-Jun-10 22:24 
GeneralRe: How to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
PJanaki6-Jun-10 23:11
PJanaki6-Jun-10 23:11 
GeneralRe: How to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
David Skelly7-Jun-10 2:41
David Skelly7-Jun-10 2:41 
GeneralRe: How to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
PJanaki8-Jun-10 3:48
PJanaki8-Jun-10 3:48 
GeneralRe: How to clone(Deep clone) instance variables in a class and it to the clone object of that class? Pin
David Skelly8-Jun-10 5:25
David Skelly8-Jun-10 5:25 
QuestionAltering .class files or recompiling isolated .java ones Pin
Abrojus3-Jun-10 14:38
Abrojus3-Jun-10 14:38 
AnswerRe: Altering .class files or recompiling isolated .java ones Pin
Richard MacCutchan3-Jun-10 22:01
mveRichard MacCutchan3-Jun-10 22:01 
AnswerRe: Altering .class files or recompiling isolated .java ones Pin
CodingLover8-Jun-10 6:29
CodingLover8-Jun-10 6:29 
GeneralRe: Altering .class files or recompiling isolated .java ones Pin
Upendra Jariya28-Jul-10 4:57
Upendra Jariya28-Jul-10 4:57 
QuestionI want some ideas guys Pin
B.Sudhir2-Jun-10 17:13
B.Sudhir2-Jun-10 17:13 
AnswerRe: I want some ideas guys Pin
Dr.Walt Fair, PE2-Jun-10 17:35
professionalDr.Walt Fair, PE2-Jun-10 17:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.