0% found this document useful (0 votes)
5 views8 pages

School Code IT

This Java program simulates a school management system where users can log in as either a teacher or a student. It allows for the management of teachers, students, subjects, and tuition fees, including the ability to add new entries and make payments. The program features a menu-driven interface for user interaction and handles user authentication and data management dynamically.

Uploaded by

carllorenz310
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

School Code IT

This Java program simulates a school management system where users can log in as either a teacher or a student. It allows for the management of teachers, students, subjects, and tuition fees, including the ability to add new entries and make payments. The program features a menu-driven interface for user interaction and handles user authentication and data management dynamically.

Uploaded by

carllorenz310
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

import java.util.

Scanner;
import java.util.ArrayList;

class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.println("----------------------------SCHOOL
PROGRAM----------------------------");

ArrayList<String> teach = new ArrayList<String>();


teach.add("Mr. Aizen");
teach.add("Mrs. Roberts");
teach.add("Ms. Davis");
teach.add("Dr. Clark");

ArrayList<String> students = new ArrayList<String>();


students.add("John Doe");
students.add("Jane Smith");
students.add("Alice Johnson");
students.add("Bob Brown");

double semesterFee = 30000.00;


double downPayment = 6000.00;
double balanceAmount = semesterFee - downPayment;
double balancePayment = balanceAmount / 4;
boolean[][] feePaidMonths = new boolean[students.size()][5];

String[] usernames = {"registrar", "student"};


String[] passwords = {"1234", "abcd"};

// Changed to ArrayList to allow dynamic addition of subjects


ArrayList<String> subjects = new ArrayList<String>();
subjects.add("Computer Programming");
subjects.add("Introduction to Computing");
subjects.add("Physical Education");
subjects.add("Computer Programming 2");

boolean continueProgram = true;

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;
}

int choice = sc.nextInt();


sc.nextLine();

if (choice == 1) {

System.out.println("---------------------------------------------------------------
");
System.out.print("Enter Username: ");
String username = sc.nextLine();
System.out.print("Enter Password: ");
String password = sc.nextLine();

boolean validLogin = false;


int loggedInUserIndex = -1;

for (int i = 0; i < usernames.length; i++) {


if (usernames[i].equals(username) &&
passwords[i].equals(password)) {
validLogin = true;
loggedInUserIndex = i;
if (i == 0) {
System.out.println("--------Welcome Teacher---------");
} else {
System.out.println("--------Welcome Student---------");
}
break;
}
}

if (!validLogin) {
System.out.println("Invalid username or password");
continue;
}

// Menu options after login


boolean menuActive = true;
while (menuActive) {
if (loggedInUserIndex == 0){
System.out.println("--------[1] Teachers---------");
System.out.println("--------[2] Students--------");
System.out.println("--------[3] Subjects----------");
System.out.println("--------[4] Tuition Fee
(Semester)--------------");
System.out.println("--------[5] Change
Username/Password--------------");
System.out.println("--------[6] Exit--------------");
}
else if (loggedInUserIndex == 1){
System.out.println("--------[1] Subjects----------");
System.out.println("--------[2] Tuition Fee
(Semester)--------------");
System.out.println("--------[3] Change
Username/Password--------------");
System.out.println("--------[4] Exit--------------");
}

System.out.print("Enter Number: ");


if (!sc.hasNextInt()) {
System.out.println("Invalid input. Please enter a valid
number.");
sc.next();
continue;
}

int menuChoice = sc.nextInt();


sc.nextLine(); // Consume the newline character after reading
integer input

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();

boolean usernameExists = false;


for (String u : usernames) {
if (u.equals(newUsername)) {
usernameExists = true;
break;
}
}

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 (studentChoice > 0 && studentChoice <=


students.size()) {
System.out.println("For which payment would
you like to pay?");
System.out.println("1. Down Payment");
for (int month = 1; month < 5; month++) {
System.out.printf("%d. Payment %d\n",
month + 1, month + 1);
}
int paymentChoiceMonth = 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();

boolean usernameExists = false;


for (String u : usernames) {
if (u.equals(newUsername)) {
usernameExists = true;
break;
}
}

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.");
}
}
}

private static String getMonthName(int monthIndex) {


String[] months = {"Payment 1", "Payment 2", "Payment 3", "Payment 4",
"Payment 5"};
return months[monthIndex];
}
}

You might also like