Object Oriented Design In Java Application Development For Bright College Management System
Using Object Oriented Concepts in Java Programming Language
To develop the Bright College Management system, Java programming language is used. Java is an object-Oriented language and is the most appropriate language to use to develop the proposed system. By using different Object Oriented design patterns, the proposed application will be able to take advantage of most important object oriented design patterns like encapsulation and method overriding.
To demonstrate the design of the proposed system, a domain class diagram can be used to show the classes and objects that will make up the system.
the class diagram for the proposed system. The system will be made up of three classes; Course, Student and Bright class. The Student and Course classes are domain classes and model student and course respectively. The Bright class is the main class and contains the main method thus to run the application, the Bright class initialized and uses both the Student and course class.
The Course class has two private variables; name and fees.
Both of the variables are declared as private variables. Variables are then instantiated using the public constructor which takes parameters of both variables and then instantiates them in the body. For each variable there is a getter method which can also be referred to as accessor. This method is a public method which can be accessed by another class. The accessor is used to access the value of the variable held by the private variable. There is also another method called setter which is also referred to as a mutator. The mutator is used to set or change the value of the private variable and is declared as a public method to make it accessible outside the class.
The student class also has variables which are declared as private variables. The private variables defining the student class are; first name, surname, dob, address, phone, email, type, studentID and course.
This variables are passed as parameters in the public constructor of the student class. Each of the variable has a mutator and accessor method.
The process of using getter and setter methods for the two classes is done to achieve encapsulation. Encapsulation is the process of wrapping data and code together into a single using. A fully encapsulated class has data members all of which are declared as private and then setter and getter methods are used to set and get the data. Using encapsulation in java has a few advantages including;
- Using getters and setters for a class makes the class write –only and read-only. For read only classes only getter method are implemented while for write-only classes only setter methods are implemented. This provides more control over the data.
- Encapsulation helps achieve data hiding because by declaring private data members, other classes cannot access the data members unless getter methods are implemented.
- Encapsulation makes it easy to test the code especially for unit testing.
Domain Class Diagram for Bright College Management System
Apart from the getter and setter methods implemented in both classes, there are other methods that define each of the classes. Both classes have an overridden toString method which returns the data of the class as a string formatted in a specific format. Method overriding enables the subclasses to implement a different implementation of the overridden method from the implementation of the superclass. The overridden toString method enable the string to be returned in a specific format. The student class also has another two methods one which is get basic details which is used to get the names and email of the student while getBalance method is used to get the remaining balance of the student.
THe Bright class is the main class and contains the main method. The class has a declaration of two array lists for student and course objects. Array lists are preferred to arrays because they can grow exponentially and the size does not have to be declared during the declaration of the array list. The array list inherits abstract list class and also implements the list interface. This makes it easier to randomly access the list. Although they are generally slow that normal arrays, they are very useful especially because there is going to be a lot of manipulation of the objects held in both arrays.
- Add student
- Pay fees
- List students on a course
- Change course
- Show profile
- Management reporting
- Exit
- Implementation
The code for each of the class is shown below.
- Course
public class Course {
private String name;
private double fees;
public Course(String _name, double _fees){
this.name=_name;
this.fees=_fees;
public void setName(String _name){
this.name=_name;
public String getName(){
return this.name;
public void setFees(double _fees){
this.fees=_fees;
public double getFees(){
return this.fees;
@Override
public String toString(){
return this.name+”(£”+this.fees+”)”;
- Student
public class Student {
private String firstName, surname, dob, address, phone, email,type,studentID;
private Course course;
private double fees;
public Student(String _fname, String _surname, String _dob,String _address, String _email, String _type, String _id,Course _course, double _fees,String _phone){
this.firstName=_fname;
this.surname=_surname;
this.dob=_dob;
this.address=_address;
this.email=_email;
this.type=_type;
this.studentID=_id;
this.course=_course;
this.fees=_fees;
this.phone=_phone;
public void setFirstName(String _fname){
this.firstName=_fname;
public String getFirstName(){
return this.firstName;
public void setSurname(String _surname){
this.surname=_surname;
public String getSurname(){
return this.surname;
public void setDob(String _dob){
this.dob=_dob;
public String getDob(){
return this.dob;
public void setAddress(String _address){
this.address=_address;
Defining Classes and Variables in Course and Student Classes
public String getAddress(){
return this.address;
public void setPhone(String _phone){
this.phone=_phone;
public String getPhone(){
return this.phone;
public void setEmail(String _email){
this.email=_email;
public String getEmail(){
return this.email;
public void setType(String _type){
this.type=_type;
public String getType(){
return this.type;
public void setStudentID(String _id){
this.studentID=_id;
public String getStudentID(){
return this.studentID;
public void setCourse(Course _course){
this.course=_course;
public Course getCourse(){
return this.course;
public void setFees(double _fees){
this.fees=this.fees+_fees;
public double getFees(){
return this.fees;
@Override
public String toString(){
return “Name: “+this.firstName+” “+this.surname+”nStudent ID: “+this.studentID+”nStudentID: “+studentID+”nDate of birth: “+this.dob+”nType: “+this.type+”nCourse: “+this.course+”nFees: “+this.fees;
}
public String getBasicDetails(){
return “Name: “+this.firstName+” “+this.surname+”nEmail: “+email;
}
public double getBalance(){
double studentFee=0;
if(type.equalsIgnoreCase(“Home”)){
studentFee=course.getFees()/2;
}else{
studentFee=course.getFees();
}
return studentFee-fees;
Bright
public class Bright {
* @param args the command line arguments
static ArrayList students=new ArrayList<>();
static ArrayList courses=new ArrayList<>();
public static void main(String[] args) {
populate();
menu();
public static void populate(){
courses.add(new Course(“Computing”,6000));
courses.add(new Course(“Accounting”,6000));
courses.add(new Course(“Business Studies”,6000));
public static void menu(){
System.out.println(“*****************************”);
System.out.println(“* Bright – Future College *”);
System.out.println(“*****************************n”);
System.out.println(“1. Enroll Studentn2. Pay Feesn3. List students on a coursen4. Change coursen5. View Student profile n6. Remove Student from coursent8. ***Management Reporting***nt9.Exit”);
System.out.print(“Enter your option: “);
Scanner s=new Scanner(System.in);
String option=s.next();
switch(option){
case “1”:
addStudent();
menu();
break;
case “2”:
payFees();
menu();
break;
case “3”:
listStudentsOnCourse();
menu();
break;
case “4”:
changeCourse();
menu();
break;
case “5”:
viewStudentProfile();
menu();
break;
case “6”:
removeStudentFromCourse();
menu();
break;
case “8”:
adminMenu();
menu();
break;
case “9”:
System.exit(0);
break;
default:
System.out.println(“Invalid Option”);
menu();
break;
public static void payFees(){
System.out.println(“*** PAY FEES ***”);
Scanner s =new Scanner(System.in);
System.out.println(“Enter student id”);
String studentid=s.next();
Student student=getStudent(studentid);
if(student==null){
System.out.println(“No student under that id “);
payFees();
}else{
if(student.getBalance()<=0){
System.out.println(“Student has no pending balance”);
}else {
System.out.println(“Enter amount: “);
String value=s.next();
while(verifyDouble(value)==false){
System.out.println(“Enter the correct amount: “);
value=s.next();
Double fees=Double.parseDouble(value);
double balance=fees-student.getBalance();
student.setFees(fees);
Importance of Encapsulation in Java
saveStudent(student);
System.out.println(“Fees paid successfully”);
if(balance>0){
System.out.println(“Return £”+balance+” balance to the client”);
public static void listStudentsOnCourse(){
System.out.println(“*** Students on a course ***”);
Scanner s= new Scanner(System.in);
System.out.println(“Select course”);
for(int i=0;i<courses.size();i++){
int index=i+1;
System.out.println(index+”. “+courses.get(i).toString());
Course course=null;
System.out.print(“enter course id: “);
String value=s.next();
while(verifyInt(value)){
System.out.println(“Enter the correct course id:”);
value=s.next();
int courseid=Integer.parseInt(value);
while(verifyCourse(courseid)==false){
System.out.println(“Invalid option> Choose the correct course id: “);
value=s.next();
courseid=Integer.parseInt(value);
course=courses.get(courseid-1);
for(int i=0;i<students.size();i++){
if(students.get(i).getCourse().getName().equals(course.getName())){
System.out.println(students.get(i).getBasicDetails());
public static void changeCourse(){
Scanner s =new Scanner(System.in);
System.out.println(“*** CHANGE COURSE ***”);
System.out.println(“Enter student id”);
String studentid=s.next();
Student student=getStudent(studentid);
if(student==null){
System.out.println(“No student under that id “);
changeCourse();
}else{
for(int i=0;i<courses.size();i++){
int index=i+1;
System.out.println(index+”. “+courses.get(i).toString());
}
Course course=null;
System.out.print(“choose the new course id: “);
String value=s.next();
while(verifyInt(value)){
System.out.println(“Enter the correct course id:”);
value=s.next();
}
int courseid=Integer.parseInt(value);
while(verifyCourse(courseid)==false){
System.out.println(“Invalid option!!! choose the correct course id: “);
value=s.next();
}
courseid=Integer.parseInt(value);
course=courses.get(courseid-1);
student.setCourse(course);
saveStudent(student);
System.out.println(“Course changed successfully”);
public static void viewStudentProfile(){
Scanner s =new Scanner(System.in);
System.out.println(“*** VIEW STUDENT PROFILE ***”);
System.out.println(“Enter student id”);
String studentid=s.next();
Student student=getStudent(studentid);
if(student==null){
System.out.println(“No student under that id “);
viewStudentProfile();
}else{
student.toString();
public static void removeStudentFromCourse(){
Scanner s =new Scanner(System.in);
System.out.println(“***REMOVE STUDENT FROM COURSE ***”);
System.out.println(“Enter student id”);
String studentid=s.next();
Student student=getStudent(studentid);
if(student==null){
System.out.println(“No student under that id “);
changeCourse();
}else{
student.setCourse(null);
System.out.println(“Student removed from course successfully”);
saveStudent(student);
public static void addStudent(){
Scanner s=new Scanner(System.in);
try{
System.out.println(“First name: “);
String firstName=s.next();
System.out.println(“Surname: “);
String surname=s.next();
System.out.println(“Date of Birth:(yyyy/mm/dd) :”);
String dob=s.next();
System.out.println(“Address (address, postcode): “);
String address=s.next();
System.out.println(“Phone number: “);
String phone=s.next();
System.out.println(“Email: “);
String email=s.next();
System.out.println(“Type (f)foreign or (h)home”);
String choice=s.next();
String type=””;
if(choice.equalsIgnoreCase(“f”)){
type=”Foreign”;
}else if(choice.equalsIgnoreCase(“h”)){
type=”Home”;
}else{
System.out.println(“invalid choice”);
addStudent();
}
System.out.println(“Select the course to enroll student”);
for(int i=0;i<courses.size();i++){
int index=i+1;
System.out.println(index+”. “+courses.get(i).toString());
}
Course course=null;
System.out.print(“choose the new course id: “);
String value=s.next();
while(verifyInt(value)){
Implementation of Getter and Setter Methods in Java
System.out.println(“Enter the correct course id:”);
value=s.next();
}
int courseid=Integer.parseInt(value);
while(verifyCourse(courseid)==false){
System.out.println(“Invalid option!!! choose the correct course id: “);
value=s.next();
}
courseid=Integer.parseInt(value);
course=courses.get(courseid-1);
double studentFee=0;
if(type.equalsIgnoreCase(“Home”)){
studentFee=course.getFees()/2;
}else{
studentFee=course.getFees();
}
double athird=studentFee/3;
System.out.println(“Enter the amount of fees to pay (if not complete the amount should be greater than £”+athird);
double fees=s.nextDouble();
if(fees!=course.getFees() && fees<athird){
System.out.println(“The fee amount should be equal to £”+studentFee+” or greater than a third which is £”+athird);
addStudent();
}
Student student=new Student(firstName,surname,dob,address,email,type,genStudentid(),course,fees,phone);
students.add(student);
System.out.println(“Students enrolled successfully”);
}catch(NumberFormatException e){
System.out.println(e.getMessage());
public static String genStudentid(){
if(students.isEmpty()){
return “S1”;
}else{
int id=students.size()+1;
return “S”+id;
public static boolean verifyInt(String value){
try{
Integer.parseInt(value);
return false;
}catch(NumberFormatException e){
return true;
public static boolean verifyCourse(int courseid){
if(courseid<0 || courseid>=courses.size()){
return false;
}else{
return true;
public static boolean verifyDouble(String value){
try{
Double.parseDouble(value);
return true;
}catch(NumberFormatException e){
return false
public static Student getStudent(String studentID){
Student student=null;
for(int i=0;i<students.size();i++){
if(students.get(i).getStudentID().equalsIgnoreCase(studentID)){
student=students.get(i);
return student;
public static void saveStudent(Student student){
for(int i=0;i<students.size();i++){
if(students.get(i).getStudentID().equalsIgnoreCase(student.getStudentID())){
students.remove(students.get(i));
students.add(student);
public static void adminMenu(){
Scanner s=new Scanner(System.in);
System.out.println(“*** ADMIN ***”);
System.out.println(“1. Course statisticsn2. Total Fees paid to daten3. Total Fees Yet to be paidn4. Main menu”);
System.out.print(“Enter your choice: “);
String option=s.next();
switch(option){
case “1”:
courseStatistics();
adminMenu();
break;
case “2”:
getFeesPaid();
adminMenu();
break;
case “3”:
getBalancePending();
adminMenu();
break;
case “4”:
menu();
break;
default:
System.out.println(“Invalid option”);
adminMenu();
break;
public static void courseStatistics(){
HashMap<Course,String> stats=new HashMap<>();
for(int i=0;i<courses.size();i++){
Course course=courses.get(i);
int counter=0;
for(int j=0;j<students.size();j++){
if(students.get(j).getCourse().getName().equals(course.getName())){
counter+
stats.put(course, Integer.toString(counter));
HashMap.Entry<Course,String> entry1 = stats.entrySet().iterator().next();
String standardCount = entry1.getValue();
Course standardCourse=entry1.getKey();
String standardCountMin = entry1.getValue();
Course standardCourseMin=entry1.getKey();
for (HashMap.Entry<Course, String> entry : stats.entrySet()) {
Course key = entry.getKey();
String value = entry.getValue();
if(Integer.parseInt(value)>Integer.parseInt(standardCount)){
standardCount=value;
standardCourse=key;
}
if(Integer.parseInt(value)<Integer.parseInt(standardCountMin)){
standardCountMin=value;
standardCourseMin=key;
System.out.println(“The course with the most number of enrollments is “+ standardCourse.getName()+” with “+ standardCount+” enrollments”);
System.out.println(“The course with the least number of enrollments is “+ standardCourseMin.getName()+” with “+ standardCountMin+” enrollments”);
}
public static void getFeesPaid(){
double total=0;
for(int i=0;i<students.size();i++){
total=total+students.get(i).getFees();
}
public static void getBalancePending(){
double total=0;
for(int i=0;i<students.size();i++){
total=total+students.get(i).getBalance();
System.out.println(“The total amount fees paid to date is £”+total);