In: Computer Science
Having Questions with my Java program.
We consider a school is the user of this application. A courseApp personnel can use the application do complete the following tasks,
1. Add courses. The courseApp can create courses, i.e., a user can add more than one courses for the courseApp in the application.
2. Add students. The courseApp can enroll students, i.e., a user can add a list of students for the courseApp in the application.
3. Register classes. A user can act as a student (e.g., select a student) and enroll in a list of courses not exceeding 18 credit hours in total.
4. Add instructors. The courseApp can hire instructors, i.e., a user can add instructors in the application.
5. Assign instructors to courses. A course can have one to three instructors who teach or co-teach the course. A user can assign instructors to a course.
6. Display students. The application can display the student list. 7. Display course information. The application can display the course information including minimally course name, credit hours, instructors, and the enrollment of the course.
This is my code for now and I don't know how to add instructors into the program:
===========
CourseApp.java
import java.util.Scanner;
import java.util.ArrayList;
public class CourseApp{
public static void main(String[] args){
//vars
ArrayList<Student> studentList = new ArrayList();
ArrayList<Instructor> instructorList = new ArrayList();
ArrayList<Course> courseList = new arrayList();
System.out.println("Add courses");
addCourses(courseList);
System.out.println("Add students");
addStudents(studentList);
System.out.println("Add instructors");
addInstructors(instructorList);
System.out.println("register for courses");
registerClasses(courseList,studentList);
System.out.println("\nShowing all student data");
for(Student s : student) {
System.out.println(s);
System.out.println("====================");
}
System.out.println("Showing all course details:");
for(Courses c : subjects) {
System.out.println(c);
System.out.println("====================");
}
}
//methods
//adds a course to the courseList
void addCourse(Scanner sc){ //you can change this parameter if
you'd like
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of course: ");
int num = sc.nextInt();
sc.nextLine();
System.out.println("Enter course name and credit hours:");
for(int i=0; i<num;i++) {
String line = sc.nextLine();
String[] data = line.split(" ");
String name = data[0];
double hours = Double.parseDouble(data[1]);
classC.add(new Courses(name, hours));
}
}
//adds a student to the total student roster (studentList)
void addStudent(Scanner sc){ //you can change this paramter if
you'd like, as well
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of student: ");
int num = sc.nextInt();sc.nextLine();
System.out.println("Enter name and id:");
for(int i=0; i<num;i++){
String line = sc.nextLine();
String[] data = line.split(" ");
String name = data[0].trim();
int id = Integer.parseInt(data[1]);
classS.add(new Student(name,id));
}
}
//adds an instructor to the total instructors roster
(instructorList)
void addInstructor(Scanner sc){ //you can change this paramter if
you'd like, as well
}
//adds a student in the student roster to a course
void registerStudentToCourse(Student student, Course course){
Scanner sc = new Scanner(System.in);
double hrs = 0.0;
ArrayList<Courses> temp = new ArrayList<>();
System.out.println("Enter the student's name: ");
String name = sc.nextLine().trim();
Student p = findStudent( s,name);
if(p!=null) {
System.out.println("Enter number of courses you want to add
student: ");
int count = sc.nextInt();
sc.nextLine();
System.out.println("Enter course names: ");
ArrayList<Courses> t = studentOptedCourses(c,count);
p.setRegCourses(t);
}
else {
System.out.println("No student named"+name);
}
}
//attempts to set an instructor in the instructor roster to a
course
void setInstructorToCourse(Instructor instructor, Course
course){
}
//prints out the names and ID numbers of all the students in the
student roster
void listAllStudent(){
for(Student s : student) {
if(s.getStudentName().equals(name)) {
return s;
}
}
return null;
}
//prints out the names of all of the hired instructors in the
instructor roster
void listAllInstructors(){
}
//prints out the course name, its credit hours, the names of the
students
//enrolled in the input course, and the names of the instructors
enrolled
//in the input course.
String getCourseInfo(Course course){
for(Courses c: classC) {
if(c.getCourseName().equals(cname)) {
return c;
}
}
return null;
}
}
=================
Course.java
import java.util.ArrayList;
public class Course{
//vars
String name;
int creditHours;
ArrayList<Student> studentList = new ArrayList();
//The size of the Instructor array is set to three because there
can only be a max of 3 instructors per course
Instructor[] instructor = new Instructor[3];
Courses(String name, double hrs) {
this.courseName = name;
this.creditHours = hrs;
}
Courses(String name, double hrs, ArrayList<String> teachers)
{ //what if more than one prof
this(name, hrs);
instructors = new ArrayList<>(teachers);
}
//constructor
public Course(String inputName, int creditHours){
}
//methods
//returns the name of the course
public String getName(){
}
//returns the value of addCreditHours
public int getCreditHours(){
}
//returns a list of students in this form (not set in stone): Adam
Sandler, Jacob Righdon, Stephen Greene, and Jacob Nate.
//I wasn't too sure about how I would do this so, if you want to
change it, feel free to do so
public String getStudents(){
}
//same as the getStudents class. Feel free to change this
public String getInstructors(){
}
//adds a student to studentList. Should this also add a student's
ID to another linked list in this class, in the same index
location?
void addStudent(Student student){
}
//adds an instructor to the instructor array. Returns true if there
is space for a new instructor, and returns false if not.
boolean addInstructor(Instructor instructor){
}
//the overridden equals method
public boolean equals(Object object){
}
//the overriden hashCode method
public int hashCode(){
}
}
==============
Student.java
public class Student{
//vars
String name;
String studentID;
//totalCreditHours is set to 0 because it can only be added to as
of now
int totalCreditHours = 0;
//constructor
public Student(String inputName, int studentID){
}
//methods
//returns the value of the name variable
public String getName(){
}
//returns the value of the studentID variable
public int getStudentID(){
}
//returns the value of the totalCreditHours variable
public int getTotalCreditHours(){
}
//if totalCreditHours will not be greater than 18 if the
inputCreditHours was added to totalCreditHours,
//then return true and add inputCreditHours to totalCreditHours.
Otherwise, do not add to totalCreditHours, and return false.
public boolean addCreditHours(int inputCreditHours){
}
//the overridden equals method
public boolean equals(Object object){
}
//the overriden hashCode method
public int hashCode(){
}
}
===============
Instructor.java
public class Instructor{
//vars
String name;
//constructor
public Instructor(String name){
}
//methods
//returns the value of name
public String getName(){
}
//the overridden equals method
public boolean equals(Object object){
}
//the overriden hashCode method
public int hashCode(){
}
}
Hi There,
Taking input from user does not always mean from STDIN you can creat appropriate APIs to give the user more flexibility
i think this is more design problem, you should create 3 diffenent class Student, Course and Instructor, that should have all the methods defined in the below CourseApp
By creating instance of this class you can have any number of
permutation possible, i implemented few which was asked in this
problem but you can always create more. please feel free to contact
again if you have any doubts
Thanks
//CourseApp.java
import java.util.Scanner;
import java.util.ArrayList;
public class CourseApp{
public ArrayList<Course> coursesList;
public ArrayList<Instructor>
InstructorList;
public Arraylist<Student> studentList;
//Constructor
public CourseApp(ArrayList<Course> coursesList,
ArrayList<Instructor> InstructorList,
Arraylist<Student> studentList){
this.InstructorList =
InstructorList;
this.studentList =
studentList;
this.coursesList =
coursesList;
}
//Constructor
public CourseApp(){
this.InstructorList = new
ArrayList();
this.studentList = new
ArrayList();
this.coursesList = new
ArrayList();
}
//user can add courses
public void addCourse(Course c){
this.courseList.add(c);
}
public void addCourse(ArrayList<Course>
courses){
for (Course c: courses){
this.courseList.add(c);
}
}
//user can add students
public void addStudent(Student s){
this.studentList.add(s);
}
public void addStudent(ArrayList<Student>
students){
for (Student s: students){
this.studentList.add(s);
}
}
//user can add Instructor
public void addInstructor(Instructor i){
this.InstructorList.add(i);
}
public void addInstructor(ArrayList<Instructor>
instructors){
for (Instructor i:
instructors){
this.InstructorList.add(i);
}
}
public void assignInstructor(Course c, Instrctor
i){
//add this method to the Courses
class
c.addInstructor(i)
}
public void displayStudentList(){
for (Student s:
this.studentList){
//add toString
Method to the Student Class
System.out.println(s.toString());
}
}
public void dispayCourseInfo(Course c){
//add toString Method to the
Courses Class
System.out.println(c.toString());
}
public void RegisterClass(Student s, Course c){
//we can create this entry in both
studnt and course classes
//implement both these method in
the respective class
s.addCourse(c);
c.addStudent(s);
}