Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I have this assignment: Modify your code so that instructors can also use yo

ID: 3719921 • Letter: H

Question

Hi, I have this assignment:

Modify your code so that instructors can also use your program. Change your login method to recognize if the username/password entered belong to a student or instructor (based on the last column in the UsersInfo.txt file). If the user is a student, you will need to go with the regular path (start the quiz). If the user is an instructor, display the following options as a menu:

Register a new student.

Ask the instructor to enter a student’s information: first name, last name, username, email. The password needs to be generated automatically. All the information will then be added to the Users_Info.txt file.

2) Display stats

Display on screen the following stats: the student with the shortest duration, highest grade, the lowest grade and average grade of the class. (Hint: upon a successful completion of each quiz, write the student’s name, elapsed time and score to a file, use this to extract the stats listed above).

3) Add new questions

Allow the instructor to add new questions to the test bank. The questions can be added in two ways: 1) manually by typing the question and the answer. 2) by providing a file name to be read and appended to the original test bank.

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

The UsersInfo.txt contains info like this (seperated by tab):

The TestBank.txt file contains questions seperated by a line break like this:

question1

question2

question3

The Answers.txt file contains the TRUE/FALSE answers designated to the certain questions sequentially:

TRUE

TRUE

FALSE

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

Here is my code so far:

import java.util.*;
import java.io.*;
import java.text.*;

public class QuizMaker {  
final int QUESTION_COUNT = 125;
class User{
String firstname;   
String lastname;   
String username;   
String password;   
String email;
  
public String getFirstname() {   
return firstname;   
}   
public void setFirstname(String firstname) {   
this.firstname = firstname;   
}   
public String getLastname() {
return lastname;   
}   
public void setLastname(String lastname) {
this.lastname = lastname;   
}
public String getUsername() {   
return username;   
}   
public void setUsername(String username) {   
this.username = username;   
}   
public String getPassword() {   
return password;   
}   
public void setPassword(String password) {   
this.password = password;   
}   
public String getEmail() {   
return email;   
}   
public void setEmail(String email) {   
this.email = email;   
}   
}
static List method1() throws IOException{   
List userList = new ArrayList();   
BufferedReader br1 = new BufferedReader(new FileReader("UsersInfo.txt"));   
String line = "";
while((line = br1.readLine()) !=null) {
  
String[] u = line.split(" ");
  
User user = new QuizMaker().new User();
  
user.setUsername(u[0]);
  
user.setPassword(u[1]);
  
user.setFirstname(u[2]);
  
user.setLastname(u[3]);
  
user.setEmail(u[4]);
  
userList.add(user);
  
}
br1.close();   
return userList;   
}
static List method2() throws IOException{
List questionList = new ArrayList();   
BufferedReader br1 = new BufferedReader(new FileReader("TestBank.txt"));
  
String line = "";
  
while((line = br1.readLine()) !=null) {
  
questionList.add(line);
  
}
  
  
  
br1.close();
  
return questionList;
  
}
  
static List method3() throws IOException{
  
List answerList = new ArrayList();
  
BufferedReader br1 = new BufferedReader(new FileReader("Answers.txt"));
  
String line = "";
  
while((line = br1.readLine()) !=null) {
  
answerList.add(line);
  
}
  
br1.close();
  
return answerList;
  
}
  
static String method4(){
  
@SuppressWarnings("resource")
  
Scanner scan = new Scanner(System.in);
  
System.out.print("Do you want to take the quiz with another user name?"

+ " If so, enter YES, otherwise enter done. ");
  
String opt = scan.nextLine();
  
return opt;
  
}
  
public static void main(String[] args) throws IOException {
  
List userList = new ArrayList();
  
List questionList = new ArrayList();
  
List answerList = new ArrayList();
  
User userAcc = null;
  
int score = 0;
  
int[] ranQns = new int[10];
  
userList = method1();
  
questionList = method2();
  
answerList = method3();
  
  
  
Scanner scan = new Scanner(System.in);
  
int attempt = 1;
  
boolean loginSuccess = false;
  
do {
  
System.out.print("Enter Username: ");
  
String uname = scan.nextLine();
  
for(User user : userList) {
  
if(user.getUsername().equals(uname)) {
  
do {
  
System.out.print("Enter password: ");
  
String password = scan.nextLine();
  
if(user.getPassword().equals(password)) {
  
loginSuccess = true;
  
System.out.println("Login accepted, welcome " + user.getFirstname() +".");
  
userAcc = user;
  
break;
  
}
  
else {
  
System.out.println("Invalid password: ");
  
attempt++;
  
}
  
}while(attempt<=3);
  
}
  
}
  
if(attempt>3) {
  
System.out.println("3 Failed attempt. Closing application");
  
System.exit(0);
  
}
  
if(loginSuccess) {
  
Random rand = new Random();
  
int cnt = 0;
  
  
  
while(cnt<=9) {
  
boolean found = false;
  
int randNo = rand.nextInt(125);
  
for(int i=0;i<=cnt;i++) {
  
if(randNo == ranQns[i]) {
  
found = true;
  
break;
  
}
  
}
  
if(!found) {
  
ranQns[cnt] = randNo;
  
cnt++;
  
}
  
}
  
System.out.println("Get Ready to take Quiz. Type Either True/False or T/F ");
  
long startTime = System.currentTimeMillis();
  
if(loginSuccess) {
  
for(int i=0;i   
System.out.println(questionList.get(ranQns[i]));
  
while(true) {
  
System.out.print("Answer: ");
  
String res = scan.nextLine();
  
if(res.equalsIgnoreCase("true") || res.equalsIgnoreCase("false")

|| res.equalsIgnoreCase("t") || res.equalsIgnoreCase("f")) {
  
if(res.equalsIgnoreCase("f") || res.equalsIgnoreCase("false")) {
  
res = "FALSE";
  
}else if(res.equalsIgnoreCase("t") || res.equalsIgnoreCase("true")) {
  
res = "TRUE";
  
}
  
if(res.equalsIgnoreCase(answerList.get(i))) {
  
score++;
  
}
  
break;
  
}else {
  
System.out.println("Wrong answer Type Either True/False or T/F");
  
}
  
}
  
  
  
}
  
}
  
long endTime = System.currentTimeMillis();
  
StringBuilder sb = new StringBuilder();
  
  
  
sb.append("First name: " + userAcc.getFirstname()+" ");
  
sb.append("Last Name: " + userAcc.getLastname()+" ");
  
sb.append("Score: " + score+" ");
  
sb.append("Elapsed Time: " + (endTime - startTime)/1000 +" seconds" +" ");
  
System.out.println(sb.toString());
  
  
  
Calendar cal = Calendar.getInstance();
  
  
  
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  
String date = dateFormat.format(cal.getTime());
  
  
  
date = date.replaceAll(":", ".");
  
String filename = userAcc.getUsername() + "_COSC_236_Quiz_"+date+".txt";
  
BufferedWriter br = new BufferedWriter(new FileWriter(filename));
  
br.write(sb.toString());
  
br.flush();
  
br.close();
  
  
  
String opt = method4();
  
if(!opt.equalsIgnoreCase("yes"))

break;
}else
break;   
}while(true);
}
  
}

Thank you!

Username Password FirstName LastName Email Role kingkrule1 fjsdklfjs King Krule kk1@sfsdf.com Instructor katy1 jdjskfdkfh Katy Perry kp2@sdfdsf.com Student post1 sdsdfsf Post Malone pm3@sdsf.com Student

Explanation / Answer

import java.util.*;
import java.io.*;
import java.text.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class QuizMaker {  
final int QUESTION_COUNT = 125;


class User{
String firstname;   
String lastname;   
String username;   
String password;   
String email;

String role;
  
public String getFirstname() {   
return firstname;   
}   
public void setFirstname(String firstname) {   
this.firstname = firstname;   
}   
public String getLastname() {
return lastname;   
}   
public void setLastname(String lastname) {
this.lastname = lastname;   
}
public String getUsername() {   
return username;   
}   
public void setUsername(String username) {   
this.username = username;   
}   
public String getPassword() {   
return password;   
}   
public void setPassword(String password) {   
this.password = password;   
}   
public String getEmail() {   
return email;   
}   
public void setEmail(String email) {   
this.email = email;   
}   

public String getRole() {   
return rolel;   
}   
public void setRole(String role) {   
this.role = role;

String x = JcomboBox.getSelectedItem().toString();

}   

}
static List method1() throws IOException{   
List userList = new ArrayList();   
BufferedReader br1 = new BufferedReader(new FileReader("UsersInfo.txt"));   
String line = "";
while((line = br1.readLine()) !=null) {
String[] u = line.split(" ");
  
User user = new QuizMaker().new User();
  
user.setUsername(u[0]);
  
user.setPassword(u[1]);
  
user.setFirstname(u[2]);
  
user.setLastname(u[3]);
  
user.setEmail(u[4]);

user.setRole(u[5]);
  
userList.add(user);
  
}
br1.close();   
return userList;   
}
static List method2() throws IOException{
List questionList = new ArrayList();   
BufferedReader br1 = new BufferedReader(new FileReader("TestBank.txt"));
  
String line = "";
  
while((line = br1.readLine()) !=null) {
  
questionList.add(line);
}
br1.close();
  
return questionList;
  
}
  
static List method3() throws IOException{
  
List answerList = new ArrayList();
  
BufferedReader br1 = new BufferedReader(new FileReader("Answers.txt"));
  
String line = "";
  
while((line = br1.readLine()) !=null) {
  
answerList.add(line);
  
}
  
br1.close();
  
return answerList;
  
}
  
static String method4(){
  
@SuppressWarnings("resource")
  
Scanner scan = new Scanner(System.in);
  
System.out.print("Do you want to take the quiz with another user name?"

+ " If so, enter YES, otherwise enter done. ");
  
String opt = scan.nextLine();
  
return opt;
  
}
  
public static void main(String[] args) throws IOException {
  
List userList = new ArrayList();
  
List questionList = new ArrayList();
  
List answerList = new ArrayList();
  
User userAcc = null;
  
int score = 0;
  
int[] ranQns = new int[10];
  
userList = method1();
  
questionList = method2();
  
answerList = method3();
Scanner scan = new Scanner(System.in);
  
int attempt = 1;
  
boolean loginSuccess = false;
  

if(role.equals("Student")){
do {
  
System.out.print("Enter Username: ");
  
String uname = scan.nextLine();
  
for(User user : userList) {
  
if(user.getUsername().equals(uname)) {
  
do {
  
System.out.print("Enter password: ");
  
String password = scan.nextLine();
  
if(user.getPassword().equals(password)) {
  
loginSuccess = true;
  
System.out.println("Login accepted, welcome " + user.getFirstname() +".");
  
userAcc = user;
  
break;
  
}
  
else {
  
System.out.println("Invalid password: ");
  
attempt++;
  
}
  
}while(attempt<=3);
  
}
  
}
  
if(attempt>3) {
  
System.out.println("3 Failed attempt. Closing application");
  
System.exit(0);
  
}
  
if(loginSuccess) {
  
Random rand = new Random();
  
int cnt = 0;
while(cnt<=9) {
boolean found = false;
int randNo = rand.nextInt(125);
for(int i=0;i<=cnt;i++) {
if(randNo == ranQns[i]) {
  
found = true;
break;
}
}

if(!found) {
  
ranQns[cnt] = randNo;
  
cnt++;
  
}
  
}
  
System.out.println("Get Ready to take Quiz. Type Either True/False or T/F ");
  
long startTime = System.currentTimeMillis();
  
if(loginSuccess) {
  
for(int i=0;i   
System.out.println(questionList.get(ranQns[i]));
  
while(true) {
  
System.out.print("Answer: ");
  
String res = scan.nextLine();
  
if(res.equalsIgnoreCase("true") || res.equalsIgnoreCase("false")

|| res.equalsIgnoreCase("t") || res.equalsIgnoreCase("f")) {
  
if(res.equalsIgnoreCase("f") || res.equalsIgnoreCase("false")) {
  
res = "FALSE";
  
}else if(res.equalsIgnoreCase("t") || res.equalsIgnoreCase("true")) {
  
res = "TRUE";
  
}
  
if(res.equalsIgnoreCase(answerList.get(i))) {
  
score++;
  
}
  
break;
  
}else {
  
System.out.println("Wrong answer Type Either True/False or T/F");
  
}
  
}
  
  
  
}
  
}
  
long endTime = System.currentTimeMillis();
  
StringBuilder sb = new StringBuilder();
  
  
  
sb.append("First name: " + userAcc.getFirstname()+" ");
  
sb.append("Last Name: " + userAcc.getLastname()+" ");
  
sb.append("Score: " + score+" ");
  
sb.append("Elapsed Time: " + (endTime - startTime)/1000 +" seconds" +" ");
  
System.out.println(sb.toString());
  
  
  
Calendar cal = Calendar.getInstance();
  
  
  
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  
String date = dateFormat.format(cal.getTime());
  
  
  
date = date.replaceAll(":", ".");
  
String filename = userAcc.getUsername() + "_COSC_236_Quiz_"+date+".txt";
  
BufferedWriter br = new BufferedWriter(new FileWriter(filename));
  
br.write(sb.toString());
  
br.flush();
  
br.close();
  
  
  

String opt = method4();
  
if(!opt.equalsIgnoreCase("yes"))

break;
}else
break;   
}while(true);

}

else if(role.equals("Instructor"))

{

do {
  
System.out.print("Enter Username: ");
  
String uname = scan.nextLine();
  
for(User user : userList) {
  
if(user.getUsername().equals(uname)) {
  
do {
  
System.out.print("Enter password: ");
  
String password = scan.nextLine();
  
if(user.getPassword().equals(password)) {
  
loginSuccess = true;
  
System.out.println("Login accepted, welcome " + user.getFirstname() +".");
  
userAcc = user;
  
break;
  
}
  
else {
  
System.out.println("Invalid password: ");
  
attempt++;
  
}
  
}while(attempt<=3);
  
}
  
}
  
if(attempt>3) {
  
System.out.println("3 Failed attempt. Closing application");
  
System.exit(0);
  
}
  
if(loginSuccess) {

class RegistrationFormDesign {

JLabel label1,label2,label3,label4,label5,label6;
JPanel panel;
JFrame jf;
JButton register;
JTextField textfield1,textfield2,textfield3,textfield4,textfield5;
JPasswordField passwordfield1;

public RegistrationFormDesign()
{
initComponents();
event();

}

public void initComponents() {
jf=new javax.swing.JFrame("Registration Form");
panel=new javax.swing.JPanel();
jf.add(panel);
panel.setBackground(new Color(191,239,255));
panel.setLayout(null);
jf.setSize(970,700);
jf.show();

label1=new javax.swing.JLabel("Registration Form");
label1.setFont(new Font("Dialog", Font.ITALIC, 24));
label1.setBounds(300,20,400,40);
panel.add(label1);

label2=new javax.swing.JLabel("Name");
panel.add(label2);

label3=new javax.swing.JLabel("Password");
panel.add(label3);

label4=new javax.swing.JLabel("First Name");
panel.add(label4);

label5=new javax.swing.JLabel("Last Name");
panel.add(label5);

label6=new javax.swing.JLabel("Email");
panel.add(label6);

textfield2=new javax.swing.JPasswordField();
panel.add(textfield2);

} );

register.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{

getUserInformation();
validation();
registerUserData();

}
});

try {

String directoryName = "c:\javacode\Notepad";

String fileName = "program.txt";

File output = new File(directoryName,fileName);

output.createNewFile();

BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));

}

class RegistrationForm {
public static void main(String args[]) {
RegistrationFormDesign form = new RegistrationFormDesign();
System.out.println("Registration Form");

}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote