Header Ads Widget

Ticker

6/recent/ticker-posts

PRACTICAL-15 Java

 

PRACTICAL-15

Case Study 3:

NalSarovar college is a popular college in Gandhinagar city of Gujarat. The college has decided to automate its Department, Student and Faculty management activities so as to improve their operation efficiency. The proposed system needs to be developed as per the Class diagram shown below:


Person object can only be created by specifying person’s name, gender(M / F) and the state he/she belongs to. Unless a student is added to a department, he/she will neither have roll number nor a department. Hence Student object can be created without passing these arguments. Every faculty has some qualification and certain experience. Hence, faculty object can be created only by passing these attribute values. Department object can only be created by providing its name, student capacity and corresponding faculty in-charge. College object can only be created by specifying its name and city. College class to be defined as a public class.

package com.company;
import java.util.ArrayList;

class Student extends Person{
    private int rollNo;
    private String dept;
    public Student(String name, char gender, String state, int rollNo, String dept) {
        super(name, gender, state);
        this.rollNo = rollNo;
        this.dept = dept;
    }
    public int getRollNo() {
        return rollNo;
    }
    public String getDept() {
        return dept;
    }
    public void setDept(String dept) {
        this.dept = dept;
    }
    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }
    public String getState() {
        String state = super.getState();
        return state;
    }
}

class Person {
    private String name;
    private char gender;
    private String state;
    public Person(String name, char gender, String state) {
        this.name = name;
        this.gender = gender;
        this.state = state;
    }
    public String getName() {
        return name;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public char getGender() {
        return gender;
    }
    public void setGender(char gender) {
        this.gender = gender;
    }
    public void setName(String name) {
        this.name = name;
    }
}

class Faculty extends Person{
    private String qualification;
    private double experience;
    public Faculty(String name, char gender, String state, String qualification, double experience) {
        super(name, gender, state);
        this.qualification = qualification;
        this.experience = experience;
    }
    public String getQualification() {
        return qualification;
    }
    public double getExperience() {
        return experience;
    }
    public void setExperience(double experience) {
        this.experience = experience;
    }
    public void setQualification(String qualification) {
        this.qualification = qualification;
    }
}

class Department {
    private String dName;
    private int dCapacity;
    private Faculty dFaculty;
    private ArrayList<Student> dStudents;
    public Department(String dName, int dCapacity, Faculty dFaculty) {
        this.dName = dName;
        this.dCapacity = dCapacity;
        this.dFaculty = dFaculty;
    }
    public String getdName() {
        return dName;
    }
    public ArrayList<Student> getdStudents() {
        return dStudents;
    }
    public void setdStudents(ArrayList<Student> dStudents) {
        this.dStudents = dStudents;
    }
    public Faculty getdFaculty() {
        return dFaculty;
    }
    public void setdFaculty(Faculty dFaculty) {
        this.dFaculty = dFaculty;
    }
    public int getdCapacity() {
        return dCapacity;
    }
    public void setdCapacity(int dCapacity) {
        this.dCapacity = dCapacity;
    }
    public void setdName(String dName) {
        this.dName = dName;
    }
}

class College {
    private String cName;
    private String cCity;
    private final ArrayList<Department> cDepts;
    public College(String cName, String cCity, ArrayList<Department> cDepts) {
        this.cName = cName;
        this.cCity = cCity;
        this.cDepts = cDepts;
    }
    public ArrayList<Department> getcDepts() {
        return cDepts;
    }
    public String getcName() {
        return cName;
    }
    public String getcCity() {
        return cCity;
    }
    public void setcCity(String cCity) {
        this.cCity = cCity;
    }
    public void setcName(String cName) {
        this.cName = cName;
    }
    public int addDepartment(String dName, int dCapacity, Faculty dFaculty) {
        for(Department department: cDepts) {
            if(department.getdName().equals(dName)){
                return -1;
            }
        }
        Department newDept = new Department(dName, dCapacity, dFaculty);
        newDept.setdName(dName);
        newDept.setdCapacity(dCapacity);
        newDept.setdFaculty(dFaculty);
        cDepts.add(newDept);
        return cDepts.size();
    }
    public int addStudent(String deptName, Student newStudent) {
        for(Department department: cDepts) {
            if(department.getdName().equals(deptName)){
                department.getdStudents().add(newStudent);
                return department.getdStudents().size();
            }
        }
        return -1;
    }
    public boolean upgradeFaculty(String deptName, Faculty faculty) {
        for(Department department: cDepts) {
            if(department.getdName().equals(deptName)) {
                department.setdFaculty(faculty);
                return true;
            }
        }
        return false;
    }
    public int getStudentCountFromState(String state) {
        int count = 0;
        for(Department department: cDepts) {
            for(Student student: department.getdStudents()) {
                if(student.getState().equals(state)) {
                    count++;
                }
            }
        }
        return count;
    }
}

public class CS_15 {
    public static void main(String[] args) {
        ArrayList<Department> departments = new ArrayList<Department>();
ArrayList<Student> students = new ArrayList<Student>();
students.add(new Student("Rocky", 'M', "Maharashtra", 1001, "IT"));
departments.add(new Department("IT", 30, new Faculty("Nayan", 'M', "Gujarat", "M.tech",12.8)));
departments.get(0).setdStudents(students);
College college = new College("GCET", "V.V.Nagar", departments);
System.out.println("The students size in IT is " + college.addStudent("IT", new Student("Abhi", 'M', "Gujarat", 1002, "IT")));
System.out.println("Students from Gujarat :" + college.getStudentCountFromState("Gujarat"));
     }
}

OUTPUT
The students size in IT is 2
Students from Gujarat :1


Post a Comment

0 Comments