Question

In: Computer Science

Having Questions with my Java program. We consider a school is the user of this application....

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(){
}
}

Solutions

Expert Solution

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);
   }
  


Related Solutions

This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
(JAVA) We will write a program to check the spelling of the word entered by user,...
(JAVA) We will write a program to check the spelling of the word entered by user, using data from a dictionary, which is text file. The program will ask user to enter a word for spell check, and then check in the text file (dictionary.txt) if the word exists. (The dictionary.txt file is provided) If the word exists in text file, the output will be “Word is correctly spelled”. If the word doesn’t exist in the text file, program will...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT