Developing an Arabic Learning Terminal-Based App!

RMAG news

Backstory

Since I am currently in the process of self-teaching Arabic, I thought this project would be a good idea. It has allowed me to combine two of my hobbies: languages and programming, and overall, it has been a very enjoyable experience. Being new to Java, this project has enabled me to explore more complex programming features such as JUnit testing, encapsulation, inheritance, polymorphism, etc. Additionally, I’ve had the opportunity to learn some more Arabic words. A definite win-win!

Brief Overview

This project can be broken down into four main components.

A signup feature that validates inputted information, maintains data integrity by avoiding duplicates, and securely stores user data for future access. This data is crucial not only for logins but also for populating leaderboards and tracking XP progression.
Flashcards that display the word, its Arabic spelling, phonetic pronunciation, English translation, and audible pronunciation.
Arabic listening exams where users listen to a word and write its English meaning. Successful completion allows progression to more challenging modes, currently categorised as beginner, intermediate, and advanced
A global leaderboard featuring an XP system where users earn XP by completing tests and studying flashcards.

Login System Class:

registerUser Method:

// Method to register a new user
public static void registerUser(Scanner scanner) throws IOException {
String firstName = “”;
// Validating first name
while (firstName.isEmpty()) {
System.out.println(“Enter your first name: “);
firstName = scanner.nextLine();
if (firstName.isEmpty()) {
System.out.println(“This field cannot be left blank.”);
} else if (!isValidFirstName(firstName)) {
System.out.println(“Invalid first name, first name can only contain letters.”);
firstName = “”;
}
}

// Validating second name
String secondName = “”;
while (secondName.isEmpty()) {
System.out.println(“Enter your second name: “);
secondName = scanner.nextLine();
if (secondName.isEmpty()) {
System.out.println(“This field cannot be left blank.”);
} else if (!isValidSecondName(secondName)) {
System.out.println(“Invalid second name, second name can only contain letters.”);
secondName = “”;
}
}

String userName = “”;
String proficiency = “”;
// Validating username
while (userName.isEmpty()) {
System.out.println(“Enter your username: “);
userName = scanner.nextLine();
if (userName.isEmpty()) {
System.out.println(“This field cannot be left blank.”);
} else if (isUsernameAlreadyRegistered(userName)) {
System.out.println(“Username already exists, please enter a different one.”);
userName = “”;
}
}

// Validating proficiency level
while (proficiency.isEmpty()) {
System.out.println(“Enter your Arabic proficiency level (Beginner (B) | Intermediate (I) | Advanced (A)): “);
proficiency = scanner.nextLine().toLowerCase(Locale.ROOT);
switch (proficiency) {
case “b”:
proficiency = “Beginner”;
break;
case “i”:
proficiency = “Intermediate”;
break;
case “a”:
proficiency = “Advanced”;
break;
default:
System.out.println(“Please enter either B, I, or A.”);
proficiency = “”;
}
}

// Validating email
email = “”;
while (email.isEmpty() || !isValidEmail(email) || isEmailAlreadyRegistered(email)) {
System.out.println(“Enter your email address: “);
email = scanner.nextLine();
if (email.isEmpty()) {
System.out.println(“This field cannot be left blank.”);
} else if (!isValidEmail(email)) {
System.out.println(“Invalid email address. Please use a valid email address.”);
} else if (isEmailAlreadyRegistered(email)) {
System.out.println(“Email already exists. Please login or choose a different email address.”);
}
}

// Validating password
String password = “”;
while (password.isEmpty() || !isValidPassword(password)) {
System.out.println(“Please create a password: “);
password = scanner.nextLine();
if (password.isEmpty()) {
System.out.println(“This field cannot be left blank.”);
} else if (!isValidPassword(password)) {
System.out.println(“Invalid password. Password must be at least 8 characters long and contain at least one digit, one uppercase letter, and one lowercase letter.”);
}
}

// Initial experience points set to 0 for all users
int experiencePoints = 0;

// Writing user information to CSV file
try (PrintWriter writer = new PrintWriter(new FileWriter(CSV_FILE, true))) {
writer.println(email + “,” + password + “,” + firstName + “,” + secondName + “,” + proficiency + “,” + userName + “,” + experiencePoints);
System.out.println(“User registered successfully.”);

// Setting the registered email
Login_System.email = email;
} catch (IOException e) {
System.out.println(“Error: “ + e.getMessage());
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *