$29
Design a class named Course. The class contains:
a. Four private data fields [10 points]
◦ name (String) : The name of a course
◦ credit (int) : The credit hours of a course
◦ grade (String) : The grade of the students that a course can be open to, including “freshman”, “sophomore”, “junior”, “senior”.
◦ teacher(String) : The teacher of a course
b. Design two constructors: [10 points]
1. A constructor with one parameter name.
2. A constructor with four parameters including name, credit, grade and teacher.
c. Design the getter and setter method for each private field of course. [10 points]
d. Design a toString() method, which can return a String value of the course name. [10 points]
e. Design a public method named getCourseLevel() to return “major course” when the course grade is “junior” and “senior”, return “common course” when the course grade is “freshman” and “sophomore” and return “not valid query” otherwise. [10 points]
f. Design a public static method named getQualificationForCourse() with grade as the parameter. This method returns “You are not qualified for the course” when it is a major course with the input “freshman” and “sophomore”, or when it is a common course with the input “junior” and “senior”; it also returns “You are qualified for the course” when it is a major course with the input “junior” and “senior”, or when it is a common course with the input “freshman” and “sophomore”; it returns “not valid query” otherwise. [10 points]
g. Design a public method named isWithLab() to return “true” when the credit hour is 3, return “false” otherwise. [10 points]
Design a class named CourseTest. In this class, you should design a main method and also
h. keep asking the user to create a course until he/she quits. [10 points]
i. next, keep asking the user to obtain certain course information based on the index of the course in its data structure. In particular, given the course, you should be able to tell whether it is a major or common course, whether it comes with labs, and whether you are able to enroll in the
course based on your grade. Moreover, you should be able to tell all the courses given a credit hour and a teacher’s name.[10 points]
j. at last, keep asking the user to obtain course information after removing certain course until he/she quits. [10 points]
One example overall program flow is as follows.
First, you should repeatedly ask user “Would you like to create some courses: yes or no ?”: if “yes”, you should prompt “Please input the course name: ” and so forth. In the following, we set three courses including {java programming, 3, freshman, tom ko}, {frontier seminar, 1, junior, yepang liu}, and {object oriented programming, junior, yuqun zhang}; if “no”, this process is terminated.
Would you like to create some courses: yes or no ?
yes
Please input the course name:
java programming
Please input the course credit:
3
Please input the course grade:
freshman
Please input the course teacher:
tom ko
Would you like to create some courses: yes or no ?
yes
Please input the course name:
frontier seminar
Please input the course credit:
1
Please input the course grade:
junior
Please input the course teacher:
yepang liu
Would you like to create some courses: yes or no ?
yes
Please input the course name:
object oriented programming
Please input the course credit:
3
Please input the course grade:
junior
Please input the course teacher:
yuqun zhang
Would you like to create some courses: yes or no ?
no
Second, you should keep asking user “Would you like to obtain course information: yes or no?”: if “yes”, you should prompt the total number of the current courses, such as “There are 3 courses in the system, please pick No.” and wait for user to input the index of the courses he/she just input before, such as “1” in the following text. Correspondingly, you should prompt the information of the “No.1 course”. In our case, the course level is major course, it does not come with lab since its credit hours are 1. If you are a junior student, you are qualified for the course. In addition, you can also input a course credit, say “3”, to find out all the courses with 3 credit hours. In our case, they are “java programming” and “object oriented programming”. You can also input a teacher’s name, say “tom ko”, to find out all the course that are taught by Professor. Tom Ko. In our case, they are “java programming”. Then this process is terminated by throwing the question “Would you like to obtain course information: yes or no?” again. If “no”, the entire process is terminated.
Would you like to obtain course information: yes or no ?
yes
There are 3 courses in the system, please pick No.1
The course level is: major course
Is this course with lab? false
Please enter your grade:
junior
The result for your qualification to enroll in the course is: You are qualified for the course
Input a course credit:
3
The courses with 3 credits are [java programming, object oriented programming]
Input a teacher's name:
tom ko
The courses taught by tom ko are [java programming] Would you like to obtain course information: yes or no ? no
Third, you should ask “Would you like to obtain course information after removing certain courses: yes or no?”: if “yes”, you should prompt “Please pick the index of the course you want to remove”. If the user responds with “0” in our case, you should prompt “The remaining courses are [frontier seminar, object oriented programming]”. Then this process is terminated by throwing another “Would you like to obtain course information after removing certain courses: yes or no?”: if “no”, the entire program is terminated.
Would you like to obtain course information after removing certain courses: yes
or no ?
Please pick the index of the course you want to remove:
0
The remaining courses are [frontier seminar, object oriented programming] Would you like to obtain course information after removing certain courses: yes or no ?
yes
Please pick the index of the course you want to remove:
0
The remaining courses are [object oriented programming]
Would you like to obtain course information after removing certain courses: yes or no ?
no
What to submit
1. Please submit two “.java” files including “Course.java” and “CourseTest.java” , and make sure that those “.java” files have no package
information included.
a. Course.java: It is for you to create and design.
b. CourseTest.java: It is for you to create and design.
2. The prompts, including the words and their sequential patterns, should be exactly the same as our example.
3. It is your own jobs to take care of the corner cases. Some corner cases are listed as follows.
a. bound check, e.g., you cannot always remove the created courses.
b. Input validation, e.g., what if the input course grade is not one of “freshman”, “sophomore”, “junior”, and “senior”.
c. In fact, “java programming” is taught by three professors together. Think about how you would deal with the query about this fact.
d. The system you design should be case-‐insensitive, e.g., "zhang" and "Zhang", "Yes" and "yes" are perceived as the same in your system.
e. ...
We will have test cases for those corner cases when grading you.
4. No Chinese characters are allowed to appear in your code.
5. Please submit your assignment on the SAKAI site of your lab section. Marks will be deducted if you submit later than the deadline. If you submit your assignment within 24 hours after the deadline (grace period), your score will be half of the score you could get if the submission was made before the deadline. Assignments submitted after the grace period will not be graded (meaning you will get a zero for the assignment).
4