[CT414]: Add Assignment 1
This commit is contained in:
32
year4/semester2/CT414/assignments/assignment1/code/.gitignore
vendored
Normal file
32
year4/semester2/CT414/assignments/assignment1/code/.gitignore
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
||||
code.iml
|
@ -0,0 +1,13 @@
|
||||
package exceptions;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public class InvalidCredentialsException extends RemoteException {
|
||||
public InvalidCredentialsException() {
|
||||
super("Invalid username or password.");
|
||||
}
|
||||
|
||||
public InvalidCredentialsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package exceptions;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public class InvalidSessionIDException extends RemoteException {
|
||||
public InvalidSessionIDException() {
|
||||
super("Invalid or expired session ID.");
|
||||
}
|
||||
|
||||
public InvalidSessionIDException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package implementations;
|
||||
|
||||
import interfaces.*;
|
||||
import java.util.*;
|
||||
import java.rmi.*;
|
||||
|
||||
public class ApplicationFormV1 implements ApplicationForm {
|
||||
private String formInfo = "University of Galway Application Form - Version 1";
|
||||
private String[] questions = new String[5];
|
||||
private String[] answers = new String[5];
|
||||
|
||||
public ApplicationFormV1() {
|
||||
questions[0] = "What is your full name?";
|
||||
questions[1] = "What is your address?";
|
||||
questions[2] = "What is your e-mail address?";
|
||||
questions[3] = "What is your contact number?";
|
||||
questions[4] = "Provide a personal statement (e.g., additional details about yourself, a summary of your existing qualifications or results).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormInfo() throws RemoteException {
|
||||
return formInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalQuestions() throws RemoteException {
|
||||
return questions.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuestion(int questionNumber) throws RemoteException, IllegalArgumentException {
|
||||
if (questionNumber < 0 || questionNumber > questions.length) {
|
||||
throw new IllegalArgumentException("Invalid question number: " + questionNumber);
|
||||
}
|
||||
return questions[questionNumber];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void answerQuestion(int questionNumber, String answer) throws RemoteException, IllegalArgumentException {
|
||||
if (questionNumber < 0 || questionNumber > questions.length) {
|
||||
throw new IllegalArgumentException("Invalid question number: " + questionNumber);
|
||||
}
|
||||
answers[questionNumber] = answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < questions.length; i++) {
|
||||
sb.append("Q").append(i).append(": ").append(questions[i]).append("\n");
|
||||
sb.append("A").append(i).append(": ").append(answers[i]).append("\n\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package interfaces;
|
||||
|
||||
import java.rmi.*;
|
||||
|
||||
public interface ApplicationForm extends Remote {
|
||||
|
||||
// method to retrieve general information about the form
|
||||
String getFormInfo() throws RemoteException;
|
||||
|
||||
// method to retrieve the total number of questions in the application form
|
||||
int getTotalQuestions() throws RemoteException;
|
||||
|
||||
// method to retrieve a specific question based on its number
|
||||
String getQuestion(int questionNumber) throws RemoteException, IllegalArgumentException;
|
||||
|
||||
// method to provide a String answer to a question based off its questionNumber
|
||||
void answerQuestion(int questionNumber, String answer) throws RemoteException, IllegalArgumentException;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package interfaces;
|
||||
|
||||
import exceptions.InvalidCredentialsException;
|
||||
import exceptions.InvalidSessionIDException;
|
||||
|
||||
import java.rmi.*;
|
||||
|
||||
public interface ApplicationHandler extends Remote {
|
||||
long login(String username, String password) throws RemoteException, InvalidCredentialsException;
|
||||
|
||||
ApplicationForm downloadApplicationForm(long sessionID) throws RemoteException, InvalidSessionIDException;
|
||||
|
||||
void submitApplicationForm(long sessionID, ApplicationForm applicationForm) throws RemoteException, InvalidSessionIDException;
|
||||
}
|
Reference in New Issue
Block a user