d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Can Someone Write A Program For Me? > 500 Fg
Prev123
Add Reply New Topic New Poll
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 19 2016 10:59pm
Code
import java.util.ArrayList;
import java.util.Scanner;

/**
* Created by user on 3/19/2016.
*/
public class JSPrequest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);


System.out.println("How many sections are in this exam?");
int numOfSections = input.nextInt();

int[] numOfQuestions = new int[numOfSections];

for (int i = 0; i < numOfSections; i++) {
System.out.printf("How many questions in section %d?\n", (i + 1));
numOfQuestions[i] = input.nextInt();
}


ArrayList<ArrayList<String>> answers = new ArrayList<>();

for (int i = 0; i < numOfSections; i++) {
answers.add(new ArrayList<>());
System.out.printf("What are the correct answers for section %d?\n", (i + 1));
for (int j = 0; j < numOfQuestions[i]; j++) {
System.out.printf("%d :", j + 1);
String answer = input.next();
answers.get(i).add(answer);
}
}

ArrayList<ArrayList<ArrayList<String>>> studentAnswers = new ArrayList<>();
Boolean anotherStudent = true;
int n = 0;

ArrayList<String> studentNames = new ArrayList<>();

while (anotherStudent) {
System.out.println("Enter Student Name: ");
String name=input.next();
studentNames.add(name);
System.out.println();
studentAnswers.add(new ArrayList<>());

for (int i = 0; i < numOfSections; i++) {
studentAnswers.get(n).add(new ArrayList<>());
System.out.printf("What are %s\'s answers for section %d?\n", studentNames.get(n),(i + 1));
for (int j = 0; j < numOfQuestions[i]; j++) {
System.out.printf("%d :", j + 1);
String answer = input.next();
studentAnswers.get(n).get(i).add(answer);
}
}
n++;
System.out.println("Would you like to grade another student's exam? (y/n)");
String sentinel = input.next();
if(sentinel.equalsIgnoreCase("n")){
anotherStudent=false;
}
}

System.out.println("\nSummary");
int rightAnswers = 0;
int totalQuestions = 0;
int rightAnswersSection = 0;
int totalQuestionsSection = 0;

for (int i = 0; i < studentNames.size(); i++) {
System.out.printf("%s\'s answers: ", studentNames.get(i));

for (int j = 0; j < numOfSections; j++) {
for (int k = 0; k < numOfQuestions[j]; k++) {
System.out.print(studentAnswers.get(i).get(j).get(k));
}
}

System.out.print("\nCorrect Answers: ");
for (int j = 0; j < numOfSections; j++) {
for (int k = 0; k < numOfQuestions[j]; k++) {
System.out.print(answers.get(j).get(k));
}
}
System.out.println();
for (int j = 0; j < numOfSections; j++) {
System.out.printf("\nSection %d: ", j);
for (int k = 0; k < numOfQuestions[j]; k++) {
if (studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
rightAnswers++;
rightAnswersSection++;
}
totalQuestions++;
totalQuestionsSection++;
}
System.out.printf("\nScore: %d\\%d \n", rightAnswersSection, totalQuestionsSection);
System.out.printf("Percentage: %5.2f%s\n", (double) rightAnswersSection / (double) totalQuestionsSection, "%");
System.out.println("\nAnswer Analysis");
for (int k = 0; k < numOfQuestions[j]; k++) {
if (!studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
System.out.printf("#%d: %s marked: %s. Correct Answer: %s.\n", k + 1, studentNames.get(i), studentAnswers.get(i).get(j).get(k), answers.get(j).get(k));
}
}
System.out.println();
}


totalQuestionsSection = 0;
rightAnswersSection = 0;
}

System.out.println("Overall: ");
System.out.printf("Number of Sections: %d\n", numOfSections);
System.out.printf("Total Score: %d\\%d\n", rightAnswers, totalQuestions);
System.out.printf("SAT score: %5.2f\\%d", (totalQuestions - rightAnswers) / 4.0, totalQuestions);
}
}


Code

How many sections are in this exam?
3
How many questions in section 1?
12
How many questions in section 2?
4
How many questions in section 3?
2
What are the correct answers for section 1?
1 :a
2 :a
3 :b
4 :c
5 :d
6 :b
7 :c
8 :b
9 :a
10 :a
11 :a
12 :a
What are the correct answers for section 2?
1 :e
2 :e
3 :e
4 :e
What are the correct answers for section 3?
1 :a
2 :b
Enter Student Name:
joe

What are joe's answers for section 1?
1 :a
2 :a
3 :b
4 :c
5 :d
6 :b
7 :c
8 :b
9 :d
10 :b
11 :b
12 :c
What are joe's answers for section 2?
1 :d
2 :d
3 :d
4 :d
What are joe's answers for section 3?
1 :a
2 :a
Would you like to grade another student's exam? (y/n)
n

Summary
joe's answers: aabcdbcbdbbcddddaa
Correct Answers: aabcdbcbaaaaeeeeab

Section 0:
Score: 8\12
Percentage: 0.67%

Answer Analysis
#9: joe marked: d. Correct Answer: a.
#10: joe marked: b. Correct Answer: a.
#11: joe marked: b. Correct Answer: a.
#12: joe marked: c. Correct Answer: a.


Section 1:
Score: 8\16
Percentage: 0.50%

Answer Analysis
#1: joe marked: d. Correct Answer: e.
#2: joe marked: d. Correct Answer: e.
#3: joe marked: d. Correct Answer: e.
#4: joe marked: d. Correct Answer: e.


Section 2:
Score: 9\18
Percentage: 0.50%

Answer Analysis
#2: joe marked: a. Correct Answer: b.

Overall:
Number of Sections: 3
Total Score: 9\18
SAT score: 2.25\18
Process finished with exit code 0


got bored

o good idea i should make it read from a file

This post was edited by Ideophobe on Mar 19 2016 11:15pm
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 20 2016 01:56am
keyfile.txt
Code
A
A
B
C
D
B
C
B
A
A
A
A
new_section
E
E
E
E
new_section
A
B

studentanswers.txt
Code
Joe Schmoe
A
A
B
C
D
B
C
B
D
B
B
C
D
D
D
D
A
A
Jane Smith
b
b
b
b
b
b
b
b
b
B
B
b
b
b
b
b
b
b

summaryfile.txt
Code

SUMMARY

Joe Schmoe's answers: AABCDBCBDBBCDDDDAA
Correct Answers: AABCDBCBAAAAEEEEAB

Section 1:

Score: 8/12
Percentage: 66.67%
Answer Analysis
#9: Joe Schmoe marked: D. Correct Answer: A.
#10: Joe Schmoe marked: B. Correct Answer: A.
#11: Joe Schmoe marked: B. Correct Answer: A.
#12: Joe Schmoe marked: C. Correct Answer: A.


Section 2:

Score: 0/4
Percentage: 0.00%
Answer Analysis
#1: Joe Schmoe marked: D. Correct Answer: E.
#2: Joe Schmoe marked: D. Correct Answer: E.
#3: Joe Schmoe marked: D. Correct Answer: E.
#4: Joe Schmoe marked: D. Correct Answer: E.


Section 3:

Score: 1/2
Percentage: 50.00%
Answer Analysis
#2: Joe Schmoe marked: A. Correct Answer: B.

Overall:
Number of Sections: 3
Total Score: 9/18
SAT score: 6.75/18

-------------------------------------------------------

Jane Smith's answers: bbbbbbbbbBBbbbbbbb
Correct Answers: AABCDBCBAAAAEEEEAB

Section 1:

Score: 3/12
Percentage: 25.00%
Answer Analysis
#1: Jane Smith marked: b. Correct Answer: A.
#2: Jane Smith marked: b. Correct Answer: A.
#4: Jane Smith marked: b. Correct Answer: C.
#5: Jane Smith marked: b. Correct Answer: D.
#7: Jane Smith marked: b. Correct Answer: C.
#9: Jane Smith marked: b. Correct Answer: A.
#10: Jane Smith marked: B. Correct Answer: A.
#11: Jane Smith marked: B. Correct Answer: A.
#12: Jane Smith marked: b. Correct Answer: A.


Section 2:

Score: 0/4
Percentage: 0.00%
Answer Analysis
#1: Jane Smith marked: b. Correct Answer: E.
#2: Jane Smith marked: b. Correct Answer: E.
#3: Jane Smith marked: b. Correct Answer: E.
#4: Jane Smith marked: b. Correct Answer: E.


Section 3:

Score: 1/2
Percentage: 50.00%
Answer Analysis
#1: Jane Smith marked: b. Correct Answer: A.

Overall:
Number of Sections: 3
Total Score: 4/18
SAT score: 0.50/18

-------------------------------------------------------


fixed some of the math shit and formatting too

right now i'm running console input that works looks like this... i shold make a little swing box for it

Code
enter path to the answer key txt file
C:\Users\user\IdeaProjects\JSPrequest\keyfile.txt
enter path to the Student Answers txt file
C:\Users\user\IdeaProjects\JSPrequest\studentsanswersheets.txt
enter path to the blank final summary txt file
C:\Users\user\IdeaProjects\JSPrequest\summaryFile.txt


Code
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
* Created by user on 3/19/2016.
*/
public class JSPrequest {
public static void main(String[] args) {
Scanner consoleInput = new Scanner(System.in);
System.out.println("enter path to the answer key txt file");
String keyInFileLocation = consoleInput.nextLine();
File keyInFile = new File(keyInFileLocation);

System.out.println("enter path to the Student Answers txt file");
String studentInFileLocation = consoleInput.nextLine();
File studentInFile = new File(studentInFileLocation);

System.out.println("enter path to the blank final summary txt file");
String summaryFileLocation = consoleInput.nextLine();
File summaryFile = new File(summaryFileLocation);

ArrayList<ArrayList<String>> answers = new ArrayList<>();

int numOfSections=0;
try {
Scanner input = new Scanner(keyInFile);

int n = 0;

while (input.hasNextLine()) {
answers.add(new ArrayList<>());
String answer = input.nextLine();
if (answer.equals("new_section")) {
n++;
numOfSections++;
} else {
answers.get(n).add(answer);
}
}
} catch (FileNotFoundException e) {
System.err.printf("no file found at %s", keyInFileLocation);
} catch (IOException e) {
System.err.print("somethings up with your input it doesn't look like what it should");
}

ArrayList<ArrayList<ArrayList<String>>> studentAnswers = new ArrayList<>();
ArrayList<String> studentNames = new ArrayList<>();

try {
Scanner input = new Scanner(studentInFile);

int numOfStudents = 0;

while (input.hasNextLine()) {

String name = input.nextLine();
studentNames.add(name);
studentAnswers.add(new ArrayList<>());

for (int i = 0; i < answers.size(); i++) {
studentAnswers.get(numOfStudents).add(new ArrayList<>());
for (int j = 0; j < answers.get(i).size(); j++) {
String answer = input.nextLine();
studentAnswers.get(numOfStudents).get(i).add(answer);
}
}
numOfStudents++;
}
} catch (FileNotFoundException e) {
System.err.printf("no file found at %s", studentInFileLocation);
} catch (IOException e) {
System.err.print("somethings up with your input it doesn't look like what it should");
}


try {
PrintWriter printer = new PrintWriter(summaryFile);

printer.println("\nSUMMARY");
printer.println();

int rightAnswers = 0;
int totalQuestions = 0;
int rightAnswersSection = 0;
int totalQuestionsSection = 0;

for (int i = 0; i < studentNames.size(); i++) {
printer.printf("%s\'s answers: ", studentNames.get(i));

for (int j = 0; j < studentAnswers.get(i).size(); j++) {
for (int k = 0; k < studentAnswers.get(i).get(j).size(); k++) {
printer.print(studentAnswers.get(i).get(j).get(k));
}
}

printer.println();
printer.print("Correct Answers: ");
for (int j = 0; j < answers.size(); j++) {
for (int k = 0; k < answers.get(j).size(); k++) {
printer.print(answers.get(j).get(k));
}
}

printer.println();
for (int j = 0; j <= numOfSections; j++) {
printer.println();
printer.printf("Section %d: ", j+1);
printer.println();
for (int k = 0; k < answers.get(j).size(); k++) {
if (studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
rightAnswers++;
rightAnswersSection++;
}
totalQuestions++;
totalQuestionsSection++;
}
printer.printf("\nScore: %d/%d", rightAnswersSection, totalQuestionsSection);
printer.println();
printer.printf("Percentage: %5.2f%s", (double) rightAnswersSection * 100 / (double) totalQuestionsSection, "%");
printer.println();
printer.println("Answer Analysis");
for (int k = 0; k < answers.get(j).size(); k++) {
if (!studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
printer.printf("#%d: %s marked: %s. Correct Answer: %s.", k + 1, studentNames.get(i), studentAnswers.get(i).get(j).get(k), answers.get(j).get(k));
printer.println();
}
}
rightAnswersSection=0;
totalQuestionsSection=0;

printer.println();
}
printer.println("Overall: ");
printer.printf("Number of Sections: %d", numOfSections+1);
printer.println();
printer.printf("Total Score: %d/%d", rightAnswers, totalQuestions);
printer.println();
printer.printf("SAT score: %5.2f/%d", rightAnswers - (totalQuestions - rightAnswers) / 4.0, totalQuestions);
printer.println();
printer.println();
printer.println("-------------------------------------------------------");
printer.println();

totalQuestionsSection = 0;
rightAnswersSection = 0;
}
printer.close();
} catch (FileNotFoundException e) {
System.err.printf("no file found at %s", summaryFileLocation);
}
}
}


This post was edited by Ideophobe on Mar 20 2016 02:01am
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 20 2016 03:57am


This post was edited by Ideophobe on Mar 20 2016 04:13am
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 20 2016 04:06am
if you want me to compile it into a runnable lmk, idk if you even want this thing anymore

if you do use it i will give you 1 warning, you can overwrite just about any file with this i think so be careful what you go saving it as lol
i probably coulda added a save as new feature instead of just copying the listener again but tbh i did not expect to spend so long playing around with this thing

shit... for that matter i should have saved all the student summaries individually in their own files and made you a teachers summary with class stats
Code
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
* Created by user on 3/19/2016.
*/
public class JSPrequest extends JPanel implements ActionListener {

static File keyInFile;
static File studentInFile;
static File summaryFile;

JButton openKeyButton, openStudentInButton, saveSummaryButton;
static JTextArea log;
JFileChooser fc;

static int numOfSections=0;

public JSPrequest(){
super(new BorderLayout());

log = new JTextArea(5,20);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(log);
fc = new JFileChooser();

openKeyButton = new JButton("Key File");
openKeyButton.addActionListener(this);
openStudentInButton = new JButton("Student Answers");
openStudentInButton.addActionListener(this);
saveSummaryButton = new JButton("Save it");
saveSummaryButton.addActionListener(this);

JPanel buttonPanel = new JPanel();
buttonPanel.add(openKeyButton);
buttonPanel.add(openStudentInButton);
buttonPanel.add(saveSummaryButton);

add(buttonPanel, BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == openKeyButton) {
int returnVal = fc.showOpenDialog(JSPrequest.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {
keyInFile = fc.getSelectedFile();
log.append("Answer Key SET: " + keyInFile.getName() + "\n");
} else {
log.append("Open command cancelled by user.\n");
}
log.setCaretPosition(log.getDocument().getLength());
} else if (e.getSource() == openStudentInButton) {
int returnVal = fc.showSaveDialog(JSPrequest.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
studentInFile = fc.getSelectedFile();
log.append("Student Answers SET: " + studentInFile.getName() + "\n");
} else {
log.append("Open command cancelled by user.\n");
}
log.setCaretPosition(log.getDocument().getLength());
}else if (e.getSource() == saveSummaryButton) {
int returnVal = fc.showSaveDialog(JSPrequest.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
summaryFile = fc.getSelectedFile();
log.append("Saved: " + summaryFile.getName() + ".\n");
summarizeIt();
} else {
log.append("Save command cancelled by user.\n");
}
log.setCaretPosition(log.getDocument().getLength());
}
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("TestGrader");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JSPrequest());

frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
createAndShowGUI();
}

public static ArrayList<ArrayList<String>> getCorrectAnswers(File keyInFile){
ArrayList<ArrayList<String>> answers = new ArrayList<>();

try {
Scanner input = new Scanner(keyInFile);

int n = 0;

while (input.hasNextLine()) {
answers.add(new ArrayList<>());
String answer = input.nextLine();
if (answer.equals("new_section")) {
n++;
numOfSections++;
} else {
answers.get(n).add(answer);
}
}

} catch (FileNotFoundException e) {
log.append("no file found");
}

return answers;
}
public static void summarizeIt(){

ArrayList<ArrayList<String>> answers = getCorrectAnswers(keyInFile);

ArrayList<ArrayList<ArrayList<String>>> studentAnswers = new ArrayList<>();
ArrayList<String> studentNames = new ArrayList<>();

try {
Scanner input = new Scanner(studentInFile);

int numOfStudents = 0;

while (input.hasNextLine()) {

String name = input.nextLine();
studentNames.add(name);
studentAnswers.add(new ArrayList<>());

for (int i = 0; i < answers.size(); i++) {
studentAnswers.get(numOfStudents).add(new ArrayList<>());
for (int j = 0; j < answers.get(i).size(); j++) {
String answer = input.nextLine();
studentAnswers.get(numOfStudents).get(i).add(answer);
}
}
numOfStudents++;
}
} catch (FileNotFoundException e) {
log.append("no file found");
}
try {
PrintWriter printer = new PrintWriter(summaryFile);

printer.println("\nSUMMARY");
printer.println();

int rightAnswers = 0;
int totalQuestions = 0;
int rightAnswersSection = 0;
int totalQuestionsSection = 0;

for (int i = 0; i < studentNames.size(); i++) {
printer.printf("%s\'s answers: ", studentNames.get(i));

for (int j = 0; j < studentAnswers.get(i).size(); j++) {
for (int k = 0; k < studentAnswers.get(i).get(j).size(); k++) {
printer.print(studentAnswers.get(i).get(j).get(k));
}
}

printer.println();
printer.print("Correct Answers: ");
for (int j = 0; j < answers.size(); j++) {
for (int k = 0; k < answers.get(j).size(); k++) {
printer.print(answers.get(j).get(k));
}
}

printer.println();
for (int j = 0; j <= numOfSections; j++) {
printer.println();
printer.printf("Section %d: ", j+1);
printer.println();
for (int k = 0; k < answers.get(j).size(); k++) {
if (studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
rightAnswers++;
rightAnswersSection++;
}
totalQuestions++;
totalQuestionsSection++;
}
printer.printf("\nScore: %d/%d", rightAnswersSection, totalQuestionsSection);
printer.println();
printer.printf("Percentage: %5.2f%s", (double) rightAnswersSection * 100 / (double) totalQuestionsSection, "%");
printer.println();
printer.println("Answer Analysis");
for (int k = 0; k < answers.get(j).size(); k++) {
if (!studentAnswers.get(i).get(j).get(k).equalsIgnoreCase(answers.get(j).get(k))) {
printer.printf("#%d: %s marked: %s. Correct Answer: %s.", k + 1, studentNames.get(i), studentAnswers.get(i).get(j).get(k), answers.get(j).get(k));
printer.println();
}
}

rightAnswersSection=0;
totalQuestionsSection=0;

printer.println();
}
printer.println("Overall: ");
printer.printf("Number of Sections: %d", numOfSections+1);
printer.println();
printer.printf("Total Score: %d/%d", rightAnswers, totalQuestions);
printer.println();
printer.printf("SAT score: %5.2f/%d", rightAnswers - (totalQuestions - rightAnswers) / 4.0, totalQuestions);
printer.println();
printer.println();
printer.println("-------------------------------------------------------");
printer.println();
totalQuestions = 0;
rightAnswers = 0;
}
printer.close();
} catch (FileNotFoundException e) {
log.append("no file found");
}
}
}


This post was edited by Ideophobe on Mar 20 2016 04:34am
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll