Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help me fix the error #445

Open
sandy8669 opened this issue Apr 23, 2024 · 5 comments
Open

Help me fix the error #445

sandy8669 opened this issue Apr 23, 2024 · 5 comments

Comments

@sandy8669
Copy link

import java.util.Random;

import java.time.LocalDate;
public class SP2024_DriverLicenseCandidate_Dahal {
private String candidateName;
private String SSNumber;
private String address;
private char[] keyArray;
private char[] answerArray;

// no-argument constructor
public SP2024_DriverLicenseCandidate_Dahal() {
this.keyArray = new char[25];
this.answerArray = new char[25];
}

// parameterized constructor
public SP2024_DriverLicenseCandidate_Dahal(String candidateName,String SSNumber, String address, char[] answerArray) {
this.candidateName = candidateName;
this.SSNumber = SSNumber;
this.address = address;
this.keyArray = new char[25];
this.answerArray = answerArray;
}

// method to evaluate the test result
public int[] evaluateResult() {
int[] resultArray = new int[25];
for (int i = 0; i < 25; i++) {
if (keyArray[i] == answerArray[i]) {
resultArray[i] = 1;
}
}
return resultArray;
}

// method to generate the Driver License Number
public String generateDriverLicenseNumber() {
Random random = new Random();
StringBuilder licenseNumber = new StringBuilder();
for (int i = 0; i < 8; i++) {
licenseNumber.append(random.nextInt(10));
}
return licenseNumber.toString();
}

// method to convert the resultArray to a string
public String getResultString(int[] resultArray) {

   int correctCount = 0;
   StringBuilder failedQuestions = new StringBuilder();
   for (int i = 0; i < 25; i++) {
       if (resultArray[i] == 0) {
           failedQuestions.append((i + 1)).append(" ");
       } else {
           correctCount++;
       }
   }

   String result = correctCount >= 20 ? "PASSED" : "FAILED";
   String licenseNumber = result.equals("PASSED") ? generateDriverLicenseNumber() : "";
   
    
    String resultString =String.format("DRIVER LICENSE COMPUTER TEST RESULT\n" +
           "Test Date:%s\n" +
           "Candidate: %s %s\n" +
           "SS Number: %s\n" +
           "Address: %s\n" +
           "Result: %s\n" +
           "Number of correct answers: %d\n" +
           "Failed questions: %s\n" +
           "Driver License Number: %s\n"+
           java.time.LocalDate.now() ,candidateName, SSNumber, address, result, correctCount, failedQuestions, licenseNumber);
    return resultString ;

}

// method to convert the answerArray to a string
public String getAnswerString() {
StringBuilder answerString = new StringBuilder();
for (int i = 0; i < 25; i++) {
answerString.append(answerArray[i]).append(" ");
}
return answerString.toString();
}

// toString method to display the test result
public String toString() {
int[] resultArray = evaluateResult();
return getResultString(resultArray);
}
}

@Kapil2017
Copy link

Kapil2017 commented Apr 23, 2024 via email

@ghost
Copy link

ghost commented Apr 23, 2024 via email

@Tinovaz
Copy link

Tinovaz commented Apr 23, 2024 via email

@Lebongay
Copy link

Lebongay commented Apr 23, 2024 via email

@Smithcrystal-tech
Copy link

Smithcrystal-tech commented Apr 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants