So I am making po a college admission system for our mid term project and di ko po alam kung anong best approach to connect two java files since by group activities po and divided ang activities
and
pa help po and pa suggest po what's the best way po
Java:
package admission;
import java.util.Scanner; // SCANNER CLASS
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.InputMismatchException;
public class AdmissionSystem { // MAIN CLASS DECLARATION
public static void main(String[] args) {
// Admission Variables
String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
double reqgpa = 93.0;
String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
int age;
String ci = "";
// Scheduling Variables
int year = 2024;
int month = 4;
int score = -1;
Scanner input = new Scanner(System.in);
Random random = new Random();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// INPUT KAY PARA MUBASA SA USER
System.out.println("Good day! Thank you for applying to Xavier University.");
System.out.println("Here are the offered courses of Xavier University:");
for (String course : courses) {
System.out.println(course);
}
// SAME RA GA DIPLAY SA QUESTION
System.out.print("Would you like to register? (Yes or No): ");
String answer = input.nextLine().trim();
System.out.println("----------------------------");
// KANI PARA IF YES ANG ANSWER SA USER MU PADAYON SHA SA CODE
if (answer.equalsIgnoreCase("Yes")) {
boolean detailsCorrect = false;
// WHILE LOOP
while (!detailsCorrect) {
System.out.println(info);
System.out.println("----------------------------");
System.out.print("Name: ");
String name = input.nextLine().trim();
// Age input validation
while (true) {
System.out.print("Age: ");
if (input.hasNextInt()) {
age = input.nextInt(); // Valid integer input
break; // Exit loop if valid input is received
} else {
System.out.println("Enter Valid Age"); // Prompt for valid input
input.nextLine(); // Consume the invalid input
}
}
// Consume newline character after nextInt()
input.nextLine();
System.out.print("Address: ");
String address = input.nextLine().trim();
boolean validCourse = false;
while (!validCourse) {
System.out.print("Course Intended: ");
ci = input.nextLine().trim();
for (String course : courses) {
if (ci.equalsIgnoreCase(course)) {
validCourse = true; // Set flag to true if valid course is found
break;
}
}
if (!validCourse) {
System.out.println("Invalid course selection. Please try again."); // Prompt for valid course
}
}
double gpa;
while (true) {
System.out.print("GPA: ");
if (input.hasNextDouble()) {
gpa = input.nextDouble();
break;
} else {
System.out.println("Enter a valid GPA.");
input.nextLine();
}
}
input.nextLine();
System.out.println("----------------------------");
System.out.println("Please double-check your details:");
System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
name, age, address, ci, gpa);
System.out.print("Are the information correct? (Yes or No): ");
String response = input.nextLine().trim();
if (response.equalsIgnoreCase("Yes")) {
detailsCorrect = true;+
System.out.println("----------------------------");
System.out.println("Thanks for applying. Please wait while we verify your details...");
try {
Thread.sleep(2000); // Pause for 2 seconds to simulate processing
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("----------------------------");
// IF ELSE STATEMENT
if (gpa >= reqgpa) {
System.out.println("Congratulations! You are eligible to take the entrance exam.");
// Scheduling Exam Process
boolean satisfied = false;
while (!satisfied) {
System.out.println("Scheduling your exam.");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
int day = random.nextInt(30) + 1;
LocalDate randomDate = LocalDate.of(year, month, day);
String formattedDate = randomDate.format(formatter);
System.out.println("Your Exam Date is " + formattedDate);
System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
String examAnswer = input.nextLine();
if (examAnswer.equalsIgnoreCase("Yes")) {
satisfied = true;
} else {
System.out.println("Scheduling a new exam date\n");
System.out.println("----------------------------\n");
}
}
while (true) {
System.out.print("Step 2: Input your exam score:");
try {
score = input.nextInt();
if (score < 0 || score > 100 ) {
System.out.println("Input valid score ");
continue;
}
break;
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter a valid number score.");
input.next();
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("----------------------------\n");
if (score > 80) {
System.out.println("Congratulations! You are qualified to be admitted to the University.");
} else {
System.out.println("Sorry your score did not qualify to be admitted to this University");
}
} else {
System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
}
} else {
System.out.println("Please re-enter your details.");
}
}
} else {
System.out.println("Thank you for checking out Xavier University. Have a great day!");
}
input.close();
}
and
Java:
package admission;
import java.util.Scanner;
import java.util.Arrays;
public class Courses {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] courses = {"BSIT", "Nursing", "BSCS", "BSChem"};
int[] reqscore = {65, 70, 75, 80};
String desiredCourse;
boolean validCourse;
int courseIndex = -1;
int score ;
System.out.println("The offered courses are:");
System.out.println(Arrays.toString(courses));
do {
System.out.print("Enter the desired course: ");
desiredCourse = scanner.nextLine();
validCourse = false;
for (int i = 0; i < courses.length; i++) {
if (desiredCourse.equalsIgnoreCase(courses[i])) {
validCourse = true;
courseIndex = i;
break;
}
}
if (!validCourse) {
System.out.println("Invalid course selected. Please choose from the available courses.");
}
} while (!validCourse);
while (true) {
System.out.print("Enter your score (out of 100): ");
if (scanner.hasNextInt()) {
score = scanner.nextInt();
break;
} else {
System.out.println("Input valid score number");
scanner.next();
}
}
boolean isQualified = score >= reqscore[courseIndex];
if (isQualified) {
System.out.println("You are qualified for the course");
System.out.println("You have successfully chosen: " + desiredCourse);
} else {
System.out.println("You are not qualified for the desired course.");
System.out.println("Please choose another course.");
scanner.nextLine();
String otherCourse = scanner.nextLine();
System.out.println("You have successfully chosen: " + otherCourse);
}
scanner.close();
}
}