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

2.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

To create the constructor method, you would include parameters for the certificate holder's name, expiry date, security code, and issue number. The constructor will assign the values to the class attributes as follows:

public DCertificate(String cFertHolder, String expiryDate, String securityCode, int issueNr) {
    this.cFertHolder = cFertHolder;
    this.expiryDate = expiryDate;
    this.securityCode = securityCode;
    this.issueNr = issueNr;
}

Step 2

2.1.2 Write code for a method called increaseIssueNr that will increase the current issue number by 1.

99%

104 rated

Answer

This method will be defined as follows:

public void increaseIssueNr() {
    this.issueNr += 1;
}

Step 3

2.1.3 Write code for a method called resetExpiryDate that will reset the expiry date attribute of the digital certificate to the new expiry date based on the system date.

96%

101 rated

Answer

To reset the expiry date to a date one year from now, the method can be implemented as follows:

public void resetExpiryDate() {
    String currentDate = $SysDate;
    // Assuming you have a method to add a year
    this.expiryDate = addOneYearToDate(currentDate);
}

Step 4

2.1.4 Write code to complete the method called hasExpired that will determine whether the expiry date attribute of the certificate has expired or not.

98%

120 rated

Answer

The implementation for checking if the certificate has expired is:

public boolean hasExpired() {
    // Convert string dates to comparable date types
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date expiry = sdf.parse(this.expiryDate);
    Date current = sdf.parse($SysDate);
    return current.after(expiry);
}

Step 5

2.1.5 Write code to complete the method called generateSecurityCode to compile a security code for the digital certificate.

97%

117 rated

Answer

The method to generate a security code may look like this:

public void generateSecurityCode() {
    String characters = "0123456789ABCDEFG";
    StringBuilder securityCode = new StringBuilder();
    Random rand = new Random();
    for (int i = 0; i < 10; i++) {
        securityCode.append(characters.charAt(rand.nextInt(16)));
    }
    securityCode.append(":"); // Add colon
    for (int i = 0; i < 4; i++) {
        securityCode.append(characters.charAt(rand.nextInt(16)));
    }
    this.securityCode = securityCode.toString();
}

Step 6

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

97%

121 rated

Answer

The toString method can be written as follows:

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

Step 7

2.2.1 Write code to search for the name of the certificate holder in the text file.

96%

114 rated

Answer

To implement the search, the code can be structured as follows:

public void searchCertificateHolder(String holderName) {
    boolean found = false;
    // Read from the text file, error handling here...
    // If found, instantiate objDigCert and set pnq2_Buttons
    if (found) {
        objDigCert = new objDigCert(...);
        pnq2_Buttons.setVisible(true);
    } else {
        System.out.println("No digital certificate issued.");
        pnq2_Buttons.setVisible(false);
    }
}

Step 8

2.2.2 Write code to clear output area and display info using toString method.

99%

104 rated

Answer

To clear the output area and display the certificate information, you can implement:

public void displayCertificateInfo() {
    redOutput.setText(""); // Clear output area
    redOutput.setText(objDigCert.toString());
}

Step 9

2.2.3 Write code to determine if the certificate has expired and display a message.

96%

101 rated

Answer

This method will check for expiration and handle user interaction as follows:

public void checkValidity() {
    if (objDigCert.hasExpired()) {
        // Ask user if to renew
        // Renew logic to be handled here...
    } else {
        System.out.println("The digital certificate is valid.");
    }
}

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

;