Photo AI

Easy-Secure is a digital certificate-issuing authority (CA) - NSC Information Technology - Question 2 - 2017 - Paper 1

Question icon

Question 2

Easy-Secure-is-a-digital-certificate-issuing-authority-(CA)-NSC Information Technology-Question 2-2017-Paper 1.png

Easy-Secure is a digital certificate-issuing authority (CA). Online traders can apply for a digital certificate. You need a program to test the validity of existing ... show full transcript

Worked Solution & Example Answer:Easy-Secure is a digital certificate-issuing authority (CA) - NSC Information Technology - Question 2 - 2017 - Paper 1

Step 1

Write code for a constructor method that will receive the name of the certificate holder, the expiry date, the security code and the issue number as parameters.

96%

114 rated

Answer

public TDigCertificate(String holder, String expiry, String security, int issue) {
    this.certHolder = holder;
    this.expiryDate = expiry;
    this.securityCode = security;
    this.issueNr = issue;
}

Step 2

Write active and a method called increasesIssueNr that will increment the issue number by 1.

99%

104 rated

Answer

public void increasesIssueNr() {
    issueNr += 1;
}

Step 3

Write code for a method called resetExpiryDate that will reset the expiry date attribute of the digital certificate to the new expiry date of the digital certificate as set by the system date. Ensure that it is valid FOR ONE year.

96%

101 rated

Answer

public void resetExpiryDate() {
    String newExpiry = $SysDate;
    // Add 1 year to the current expiry date logic here
    expiryDate = newExpiry;
}

Step 4

Write code to complete the method called hasExpired that will determine whether the expiry date attribute has expired by comparing it to the system date.

98%

120 rated

Answer

public boolean hasExpired() {
    // Compare expiryDate with current date logic here
    return expiryDate.compareTo($SysDate) < 0;
}

Step 5

Write code to complete the method called generateSecurityCode to compile a security code using randomly selected hexadecimal values.

97%

117 rated

Answer

public String generateSecurityCode() {
    StringBuilder securityCode = new StringBuilder();
    // Generate 10 random hex characters
    for(int i = 0; i < 10; i++) {
        securityCode.append("0123456789ABCDEF".charAt((int)(Math.random() * 16)));
    }
    // Insert 4 colons
    for(int i = 0; i < 3; i++) {
        securityCode.insert((i+1)*3, ':'); // Adds colons
    }
    return securityCode.toString();
}

Step 6

Write code to complete the given toString method that will return a string with attributes in the following format:

97%

121 rated

Answer

public String toString() {
    return "Digital certificate information:\n" +
           "Certificate holder: " + certHolder + "\n" +
           "Expiry date: " + expiryDate + "\n" +
           "Security code: " + securityCode + "\n" +
           "Issue number: " + issueNr + ";";
}

Step 7

If the text file exists, search for the name of the certificate holder in the text file.

96%

114 rated

Answer

boolean found = false;
try {
    BufferedReader reader = new BufferedReader(new FileReader("certificates.txt"));
    String line;
    while((line = reader.readLine()) != null) {
        if(line.contains(certHolderName)) {
            found = true;
            break;
        }
    }
    reader.close();
} catch (IOException e) {
    // Handle error
}

Step 8

Display a suitable message if the digital certificate has NOT expired.

99%

104 rated

Answer

if(!digCert.hasExpired()) {
    System.out.println("The digital certificate is valid.");
} else {
    System.out.println("The digital certificate has expired.");
}

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;