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

Create an application that reads the contents of the file into an array or a Lis

ID: 3677951 • Letter: C

Question

Create an application that reads the contents of the file into an array or a List. The application should then let the user enter a charge account number. The program should determine whether the number is valid by searching for it in the array or List that contains the valid charge account numbers. If the number is in the array or List, the program should display a message indicating the number is valid. If the number is not in the array or List, the program should display a message indicating the number is invalid. 4. Driver's License Exam The local driver's license office has asked you to create an application that grades the written portion of the driver's license exam. The exam has 20 multiple-choice questions. Here are the correct answers: Your program should store these correct answers in an array. The program should read the student's answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student's answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam.

Explanation / Answer

import java.io.*;

public class Score {
//store the answers in this array
static char answer[]={'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};
public static void main(String [] args) {
//checkout the file path and enter the answers in the file in capitals
String fileName = "I://answers.txt";
try {
//read the buffer
FileReader fileReader =
new FileReader(fileName);

BufferedReader bufferedReader =
new BufferedReader(fileReader);
handleCharacters(bufferedReader);
Reader read=new BufferedReader(bufferedReader);
//passing it to read buffer to read char by char to check the answers
handleCharacters(read);
bufferedReader.close();   
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");

}
}
private static void handleCharacters(Reader reader)
throws IOException {
int r,i=0,marks=0;
while ((r = reader.read()) != -1) {
char ch = (char) r;
if(ch==answer[i])
{
marks++;
i++;
}
}
System.out.println(marks);
//if the marks are >15 pass
if(marks>15)
{
System.out.println("PASS");
}
}
}

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