Click here to Skip to main content
15,123,367 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
 The UsersInfo_003.txt file contains the following columns
(UserName FirstName LastName Email Role)
Write a Java code to add a new column to the UsersInfo_003.txt file, this column should be a randomly generated password for each of the users in the file. The updated file should contain the following columns:
(UserName Password FirstName LastName Email Role)

 Write a Java documented program to perform the role of a quiz maker. The program should work as follows:
1. Prompt the student to enter their user name and password. Read a file that contains a list of all students’ information to validate the login credentials. Start the quiz only when the credentials are correct. After 3 failed attempts, exit the program.
2. Randomly pick ten questions from the TestBank.txt file.
3. Display one question at a time. Get the answer then move to the next question.
4. Do not accept answers other than true or false (T or F should be fine too). The answers should not be case sensitive.
5. When the user is done with the quiz, print out a report (On screen and on a file) with the below information in it:
• First name
• Last name
• Score
• Elapsed time
• User’s answers and the correct answer.
6. Name the file from step 5 as follows: (userName_COSC_236_Quiz_Date_Time), where:
• userName is the actual user name of the student who took the quiz.
• Date_Time is the date and time of the start of the test.
7. Prompt for another user name and password or done as a user name to exit.


What I have tried:

Java
import java.util.Scanner;
import java.io.*;

public class project
{
  public static void main(String[] args) throws IOException
  {
    //Create Arrays
    final int SIZE=125;
    String[]Test
    //Open the test bank
    File test = new File("answers.txt");
    Scanner inputAnswers = new Scanner(test);
    
    //Open the answer file
    File answers = new File("testbank.txt");
    Scanner inputTest = new Scanner(answers);
    
    //line counters
    int testcounter = 0;
    int answercounter = 0;
    
    //correct answer counter
    int correctcounter = 0;
    
    //Create a string for question and answer
    
    
    while (testcounter < 10 && answercounter < 10)
    {
      String answer;
      String answerUpper;
      Scanner keyboard = new Scanner(System.in);
      String str = inputTest.nextLine();
      System.out.println(str);
      String str2 = inputAnswers.nextLine();
      answer = keyboard.nextLine();
      answerUpper = answer.toUpperCase();
      if (answerUpper.equals(str2))
      {
        System.out.println("Correct");
        correctcounter++;
      }
      else 
      {
        System.out.println("Incorrect");
      }
      testcounter++;
      answercounter++;
    }
    while (testcounter == 10 && answercounter == 10)
    {
      System.out.println("Test completed.");
      System.out.println("Your score was " + correctcounter + " out of 10");
      if (correctcounter >= 9)
      {
        System.out.println("Letter grade: A");
        break;
      }
      else if (correctcounter == 8)
      {
        System.out.println("Letter grade: B");
        break;
      }
      else if (correctcounter == 7)
      {
        System.out.println("Letter grade: C");
        break;
      }
      else if (correctcounter == 6)
      {
        System.out.println("Letter grade: D");
        break;
      }
      else if (correctcounter <= 6)
      {
        System.out.println("Letter grade: F");
        break;
      }
    }
  }
}
Posted
Updated 25-Oct-17 21:24pm
v2
Comments
Rick York 25-Oct-17 18:50pm
   
All right then. What is your question?
Patrice T 25-Oct-17 20:45pm
   
And you probably have a question or a problem?

1 solution

Read the question: It clear tells you exactly what to do at each stage.
For example, it starts off by telling you to get the username and password - you don't do that.
It says to validate the user - you don't do that.
It tells you only to accept specific values as answers - you don't do that.
It tells you to randomly select ten questions - you don't do that.
It ends by telling you to prompt for another name and go round again - you don't do that.

It doesn't tell you to loop round printing out the result forever - you do do that.

Basically, that code does nothing I recognise from the question!

Start again - read the question really carefully, and write a function to perform each task: A function to read the questions (which probably contains the answers as well - have a look at the file, and see how it's organised); a function to select ten questions at random from the Q&A you read; a function to get user info; a function to validate it; a function to ask and get the answer to one question; and so forth.

Test each function carefully before moving on to the next: when they all work, start writing the code to make them work as requested.

And most important of all: don't miss the word "documented" from the question.

Give it a try: this isn't complicated if you sit down and read the question then think about it, instead of throwing something together and hoping as your existing code would appear you did...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900