This program is a command-line based utility for creating students and courses (presumably for a school), adding students to courses, and displaying information about students and courses. It is designed in order to give you an opportunity to:
- Utilize all you have learned so far about writing program statements.
- Introduce you to programs consisting of multiple classes
- Introduce you to the idea of understanding and adding to code written by others
- Give you practice in writing and using methods in your own code
The whole program will consist of four classes:
- DriverClass: This is the primary class for this program, because it holds the main method. Much of this code uses techniques we have not covered yet.
- MethodHolder: It contains the primary methods used in DriverClass. The methods are static, so you do not create an actual object in order to use them.
- Student: This class represents the idea of a "student", so a particular Student object represents a specific student. A student has a name, a major, number of credits taken so far, an age, money spent on tuition so far, and whether or not student has senior status (student already has 90+ credit hours).
- Course: This class represents the idea of a "course", so a particular Course object represents a specific course. A course has a title, a department, number of credits (semester hours), maximum number of students, cost of course, and whether or not it is "intensive" (consists of 4+ semester hours).
The ONLY .java file in which you will have to write code is MethodHolder - though you need to at least understand how the Student and Course classes work. (Hint: If you find yourself thinking you need to change/add code in any place other than where I've told you to do so, that's a good sign you need to let me or someone know what obstacles you are running up against.) Notice the following three lines:
private static final double COST_PER_CREDIT = 345.59;
private static final int SENIOR_MIN_CREDITS = 90;
private static final int INTENSITY_THRESHOLD = 4;
These are constant variables that hold the cost per credit, the minimum number of credits a student must have to qualify as a senior, and the minimum number of credits a course must have to count as intense. You will write code for the following four methods:
- protected static Student generateStudent(): Write code to prompt user for input, accept said input, and assign it to the following four variables, respectively:
In addition, you will need to write a double expression and a boolean expression, in the last line, in order to calculate how much the student has spend so far on tuition and whether or not the student is a senior. Replace the 0.0 with a double expression that evaluates to how much the student has spent on tuition (the student's number of credits times the cost per credit). Replace the false with a boolean expression that is true if and only if the student is a senior (has 90 or more credits).
- protected static Course generateCourse(): Same as the previous, for the following four variables, respectively:
- title
- department
- credits
- maxStudents
In addition, you will need to write a double expression and a boolean expression, in the last line, in order to calculate how much the course costs and whether or not the course is intensive. Replace the 0.0 with a double expression that evaluates to how much the course costs (the course credits times the cost per credit). Replace the false with a boolean expression that is true if and only if the course is intensive (counts for 4 or more credits).
- protected static void printStudentInfo(Student s): For the Student object referred to by s, print the following pieces of information:
- Name
- Major
- Credits
- Age
- Money spent so far
- Whether the student is a senior
- Courses student is currently taking
The Student class already has an instance method that will print the student's courses for you, though it does not go inside a println like the others. The first piece of information, the name, is already done for you. Look at how this is done, and then look for similar methods in Student.java that will do the other parts for you. Your job is to figure out the pattern.
- protected static void printCourseInfo(Course c): For the Course object referred to by c, print the following pieces of information:
- Title
- Department
- Credits
- Enrollment (not maximum students!)
- Cost of course
- Whether the course is intensive
- Students currently enrolled in this course
The Course class already has an instance method that will print the course's students for you, though it does not go inside a println like the others. The first piece of information, the title, is already done for you. Look at how this is done, and then look for similar methods in Course.java that will do the other parts for you. Your job is to figure out the pattern.
Click here for a live demonstration of the program in action.