Student information system

  • I have made a small project and I am just wondering if I could add more functionality to the project e.g more classed etc. Is a better way of displaying my results and what error handling I could do?



    I was also wondering what would be the best way to add Inheritance to the this project.I was thinking a EveningCourse class or PostGrad, UnderGrad class. What would be the best way to go about it?



    The user enters student name, age, year and student number.



    package david;

    public class Student
    {

    private String name;
    private int age;
    private int year;
    private String studentNum;



    public Student(String name, int age, int year, String studentNum)
    {

    this.name = name;
    this.age = age;
    this.year = year;
    this.studentNum = studentNum;
    }

    // Setters and getters (Name, Age, Year and Student Number)

    public String getName() // name
    {
    return name;
    }

    public void setName(String name)
    {
    this.name = name;
    }

    public int getAge() // age
    {
    return age;
    }

    public void setAge(int age)
    {
    this.age = age;
    }

    public int getYear() // year
    {
    return year;
    }

    public void setYear(int year)
    {
    this.year = year;
    }

    public String getstudentNum() // studentNum
    {
    return studentNum;
    }

    public void setstudentNum(String studentNum)
    {
    this.studentNum = studentNum;
    }

    }

    package david;

    // David Needham - G00263842.
    // Student information program.

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;

    public class TestStudents
    {

    public static void main(String[] args) throws IOException
    {

    System.out.println("============" + "=================");
    System.out.println("Students " + "Personal Details");
    System.out.println("============" + "=================");

    String name;
    int age;
    int year;
    String studentNum;

    List<Student> studentsList = new ArrayList<Student>();

    for (int i = 0; i < 2; i++)
    {

    int studentNumber = (i + 1);

    System.out.println("");
    System.out.println("Please enter " + "data for student " + studentNumber);

    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);

    System.out.println("Enter Student "+ studentNumber + " Name:");
    name = in.readLine();

    System.out.println("Enter Student " + studentNumber + " Age (Integer):");
    age = Integer.valueOf(in.readLine());

    System.out.println("Enter Student " + studentNumber + " Year (Integer):");
    year = Integer.valueOf(in.readLine());

    System.out.println("Enter Student " + studentNumber + " Student Number:");
    studentNum = in.readLine();

    Student student = new Student(name, age, year, studentNum);

    studentsList.add(student); // add student
    }

    for (int j = 0; j < studentsList.size(); j++)
    {

    Student st = studentsList.get(j);

    System.out.println("Student : " + (j + 1));
    System.out.println("Name: " + st.getName() + " - Age: " + st.getAge() + " - Year: " + st.getYear() + " - Student Number: " + st.getstudentNum());
    }

    }
    }

    You could have used a single function for the `name`, `age`, `year` and `studentnum`.

  • DFord

    DFord Correct answer

    8 years ago

    Yes, you can add more functionality to your project. You can take this in many different directirons such as adding courses that students and register for.



    As for a error handling, you could add a check in your set functions of the Student class to check for formatting or content and return a boolean value based on if they pass the validation or not. For example, since studentnum is a string, you can check to make sure that the format of letters and numbers if correct, if there is a certain format.



    You could also use a try-catch block around the code where you read in the values from the user. Or validate that the user enter an acceptable value for each entry such as checking that when the user is asked to enter the age, check to make sure that they did indeed enter a number.


    Thanks very much for this feedback, now I know where to start!

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used