By Akshay Hire
Student Enrollment Program written in Java will allow getting students enrolled for the various semester and will allow to choose them there subjects for a semester and will generate fees.
The above code is designed for educational institutes and coaching classes where students will be able to select their subjects according to their choice in the semester.
The students can select their semester accordingly n also can select their subjects according to their interests.
If more subjects have been selected by the students then they have to pay more accordingly and if less are selected they have to pay less.
In this code fake currency has been provided to pay the fees to the respected institute. It also gives the remaining balance of the fake currency.
The code uses various concepts of JAVA such as Constructors, function overriding, the array of objects, exception handling, etc.
import studentdatabaseapp.Student; import studentdatabaseapp.ConsOverload; import studentdatabaseapp.overriding; import java.util.Scanner; public class StudentDatabaseApp { public static void main (String[]args) { //String class char welcome[]={'W','e','l','c','o','m','e'}; //converting char array welcome[] to string welStrng //this will print welcome String welStrng = new String(welcome); System.out.println("\t\t" + welStrng); // ConsOverload file ConsOverload a = new ConsOverload("\t\tStudent"); ConsOverload b = new ConsOverload(); a.printName(); b.printName(); // overriding file overriding ov = new overriding(); ov.myMethod(); // Ask how many new student we want to add System.out.print("Enter number of new students to enroll: "); Scanner in = new Scanner(System.in); int numOfStudents = in.nextInt(); Student[] students = new Student[numOfStudents]; // Create n number of new students for (int n = 0; n < numOfStudents; n++) { students[n] = new Student(); students[n].enroll(); students[n].totalpay(); students[n].payTuition(); System.out.println(students[n].toString()); } } }
package studentdatabaseapp; import java.util.Scanner; public class Student { private String firstName; private String lastName; private int semester; private String paymentID; private String courses = null; private int tuitionBalance = 500; private static int costOfCourse = 600; private static int id = 1000; public Student(){ //Constructor: prompt user to enter student's name and semester int x = 1; //For do while loop do{ //Do while loop, so process will repeat if user input wrong input try{ //Exception handling start Scanner in = new Scanner(System.in); System.out.print("Enter student first name: "); this.firstName = in.nextLine(); System.out.print("Enter student last name: "); this.lastName = in.nextLine(); System.out.println("----------------------------------------"); System.out.print("1 - Semester 1\n2 - Semester 2\n3 - Semester 3\n4 - Semester 4\n5 - Semester 5\nEnter your semester: "); this.semester = in.nextInt(); System.out.println("----------------------------------------"); setStudentID(); x=2; //When user input all the right input, the do while loop stop } catch(Exception e){ //Catch statement when error happened System.out.println("\n\tOops! Wrong input. PleaseTry Again\n"); } }while(x==1); //Restart the process if user input the wrong input } //Constructor: Generate an receipt ID private void setStudentID() { // Semester level + ID id++; this.paymentID = semester + "" + id; } //Enroll in courses public void enroll() { do { System.out.print("Enter course to enroll (Q to quit when finish.): "); Scanner in = new Scanner(System.in); String course = in.nextLine(); if (!course.equals("q")) { courses = courses + "\n " + course; tuitionBalance = tuitionBalance + costOfCourse; } else { break; } } while (1 != 0); System.out.println("----------------------------------------"); System.out.println("\n"); System.out.println("*****************************************"); } //Display total amount to pay public void totalpay(){ int totPayment = 0; totPayment = tuitionBalance - 500; System.out.println("Total payment for the courses is: RM" + totPayment); System.out.println("*****************************************"); } // View balance public void viewBalance(){ System.out.println("Your current account balance: RM" + tuitionBalance); } // Pay tuition public void payTuition() { int x = 1; do{ try{ //Exception handling start viewBalance(); //To show balance in account System.out.print("Enter your payment: RM"); Scanner in = new Scanner(System.in); int payment = in.nextInt(); tuitionBalance = tuitionBalance - payment; System.out.print("\n"); System.out.println("----------------------------------------"); System.out.println("Thank you for your payment of RM" + payment); viewBalance(); x=2; //When user input all the right input, the do while loop stop } catch(Exception e){ //Catch statement when error happened System.out.println("\n\tOops! Wrong input. PleaseTry Again\n"); } }while(x==1); } // Show status public String toString(){ return "Name: " + firstName + " " + lastName + "\nSemester: " + semester + "\nReceipt ID: " + paymentID + "\nCourses Enrolled:" + courses + "\nBalance: RM" + tuitionBalance + "\n----------------------------------------"; } }
package studentdatabaseapp; // Overriding method public class overriding{ public void myMethod() { System.out.println("***************************************************"); } } //Inheritance class Demo extends overriding{ public void myMethod(){ //Super keyword super.myMethod(); } }
package studentdatabaseapp; // Constructor overloading public class ConsOverload{ private String name; // Method overloading public ConsOverload(String n){ name = n; } public ConsOverload(){ name = "\t\tEnrollment App"; } public void printName(){ System.out.println(name); } }
Submitted by Akshay Hire (akshayjhire)
Download packets of source code on Coders Packet
Comments