School Code IT
School Code IT
Scanner;
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("----------------------------SCHOOL
PROGRAM----------------------------");
while (continueProgram) {
System.out.println("[1] Login....");
System.out.println("[2] Exit.....");
System.out.print("Enter Number: ");
if (!sc.hasNextInt()) {
System.out.println("Invalid input. Please enter a number.");
sc.next();
continue;
}
if (choice == 1) {
System.out.println("---------------------------------------------------------------
");
System.out.print("Enter Username: ");
String username = sc.nextLine();
System.out.print("Enter Password: ");
String password = sc.nextLine();
if (!validLogin) {
System.out.println("Invalid username or password");
continue;
}
switch (menuChoice) {
case 1:
if (loggedInUserIndex == 0){
System.out.println("----------------------------
TEACHERS----------------------------");
for (String teacher : teach) {
System.out.println(teacher);
}
System.out.println("---------------------------------------------------------------
");
System.out.println("Do you want to add a new
teacher? [yes/no]");
String addTeacherChoice = sc.nextLine();
if (addTeacherChoice.equalsIgnoreCase("yes")) {
System.out.print("Enter the new teacher's name:
");
String newTeacher = sc.nextLine();
teach.add(newTeacher);
System.out.println("New teacher added
successfully!");
}
} else if (loggedInUserIndex == 1){
System.out.println("----------------------------
STUDENTS----------------------------");
for (String student : students) {
System.out.println(student);
}
}
System.out.println("---------------------------------------------------------------
");
break;
case 2:
if (loggedInUserIndex == 0){
System.out.println("----------------------------
STUDENTS----------------------------");
for (String student : students) {
System.out.println(student);
}
System.out.println("---------------------------------------------------------------
");
System.out.println("Do you want to add a new
student? [yes/no]");
String addStudentChoice = sc.nextLine();
if (addStudentChoice.equalsIgnoreCase("yes")) {
System.out.print("Enter the new student's name:
");
String newStudent = sc.nextLine();
students.add(newStudent);
System.out.println("New student added
successfully!");
}
} else if (loggedInUserIndex == 1){
System.out.println("--------TUITION FEES
--------");
for (int i = 0; i < students.size(); i++) {
double totalPaid = 0;
int paymentsMade = 0;
if (feePaidMonths[i][0]) {
totalPaid += downPayment;
paymentsMade++;
}
for (int j = 1; j < 5; j++) {
if (feePaidMonths[i][j]) {
totalPaid += balancePayment;
paymentsMade++;
}
}
double remainingBalance = semesterFee -
totalPaid;
System.out.printf("Student: %s\n",
students.get(i));
System.out.printf("Down Payment: %.2f,
Remaining Balance Payment: %.2f\n", downPayment, balancePayment);
System.out.printf("Total Paid: %.2f, Remaining
Balance: %.2f, Payments Made: %d/5\n",
totalPaid, remainingBalance,
paymentsMade);
}
}
System.out.println("---------------------------------------------------------------
");
break;
case 3:
if (loggedInUserIndex == 0){
System.out.println("----------------------------
SUBJECTS----------------------------");
for (String subject : subjects) {
System.out.println(subject);
}
System.out.println("---------------------------------------------------------------
");
System.out.println("Do you want to add a new
subject? [yes/no]");
String addSubjectChoice = sc.nextLine();
if (addSubjectChoice.equalsIgnoreCase("yes")) {
System.out.print("Enter the new subject name:
");
String newSubject = sc.nextLine();
subjects.add(newSubject);
System.out.println("New subject added
successfully!");
}
} else if (loggedInUserIndex == 1){
System.out.println("----------------------------
Change Credentials-------------------------");
System.out.println("Do you want to change your
username or password? [yes/no]");
String changeCredentialsChoice = sc.nextLine();
if
(changeCredentialsChoice.equalsIgnoreCase("yes")) {
System.out.print("Enter new username: ");
String newUsername = sc.nextLine();
System.out.print("Enter new password: ");
String newPassword = sc.nextLine();
if (usernameExists) {
System.out.println("This username already
exists. Please try again.");
} else {
usernames[0] = newUsername;
passwords[0] = newPassword;
System.out.println("Your username and
password have been updated successfully!");
}
}
}
System.out.println("---------------------------------------------------");
break;
case 4:
if (loggedInUserIndex == 0){
System.out.println("--------TUITION FEES
--------");
for (int i = 0; i < students.size(); i++) {
double totalPaid = 0;
int paymentsMade = 0;
if (feePaidMonths[i][0]) {
totalPaid += downPayment;
paymentsMade++;
}
for (int j = 1; j < 5; j++) {
if (feePaidMonths[i][j]) {
totalPaid += balancePayment;
paymentsMade++;
}
}
double remainingBalance = semesterFee -
totalPaid;
System.out.printf("Student: %s\n",
students.get(i));
System.out.printf("Down Payment: %.2f,
Remaining Balance Payment: %.2f\n", downPayment, balancePayment);
System.out.printf("Total Paid: %.2f, Remaining
Balance: %.2f, Payments Made: %d/5\n",
totalPaid, remainingBalance,
paymentsMade);
}
System.out.println("---------------------------------------------------------------
");
System.out.println("\nDo you want to make a payment
for any student? [yes/no]");
String paymentChoice = sc.nextLine();
if (paymentChoice.equalsIgnoreCase("yes")) {
System.out.println("Which student would you
like to pay for?");
for (int i = 0; i < students.size(); i++) {
System.out.println((i + 1) + ". " +
students.get(i));
}
int studentChoice = sc.nextInt();
sc.nextLine();
if (paymentChoiceMonth == 1 && !
feePaidMonths[studentChoice - 1][0]) {
feePaidMonths[studentChoice - 1][0] =
true;
System.out.println("Down payment for "
+ students.get(studentChoice - 1) + " is now paid.");
} else if (paymentChoiceMonth > 1 &&
paymentChoiceMonth <= 5) {
int balancePaymentMonth =
paymentChoiceMonth - 1;
if (!feePaidMonths[studentChoice - 1]
[balancePaymentMonth]) {
feePaidMonths[studentChoice - 1]
[balancePaymentMonth] = true;
System.out.println("Balance payment
for " + students.get(studentChoice - 1) + " (Payment " + paymentChoiceMonth + ") is
now paid.");
} else {
System.out.println("This payment
has already been made.");
}
} else {
System.out.println("Invalid payment
choice.");
}
} else {
System.out.println("Invalid student
choice.");
}
}
} else if (loggedInUserIndex == 1) {
System.out.println("Exiting program...");
menuActive = false;
}
System.out.println("---------------------------------------------------");
break;
case 5:
System.out.println("----------------------------Change
Credentials-------------------------");
System.out.println("Do you want to change your username
or password? [yes/no]");
String changeCredentialsChoice = sc.nextLine();
if (changeCredentialsChoice.equalsIgnoreCase("yes")) {
System.out.print("Enter new username: ");
String newUsername = sc.nextLine();
System.out.print("Enter new password: ");
String newPassword = sc.nextLine();
if (usernameExists) {
System.out.println("This username already
exists. Please try again.");
} else {
usernames[0] = newUsername;
passwords[0] = newPassword;
System.out.println("Your username and password
have been updated successfully!");
}
}
break;
case 6:
System.out.println("Exiting program...");
menuActive = false;
break;
default:
System.out.println("Invalid choice");
break;
}
}
} else if (choice == 2) {
System.out.println("Exiting program...");
continueProgram = false;
} else {
System.out.println("Invalid choice. Please try again.");
}
}
}