======================================REGISTRAR CLASS /* This class provides a a
ID: 3527884 • Letter: #
Question
======================================REGISTRAR CLASS /* This class provides a a menu for the user */ import java.io.*; import java.util.*; public class Registrar { public static void main(String args[]){ int usr_ch, regcode, max_stu, stuidnum; String course_name, studname; Scanner c1 = new Course(System.in); //HERE------------------------------------------------------------------>>>>>>> BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); do { System.out.println("Enter your selection:"); System.out.println("1. Create course, 2. Add student, 3. Remove student, 4. Exit"); usr_ch = Integer.parseInt(br.readLine()); switch(usr_ch) { case 1: System.out.println("What is the course name?"); course_name = br.readLine(); System.out.println("What is the registration code?"); regcode = Integer.parseInt(br.readLine()); System.out.println("What is the max students?"); max_stu = Integer.parseInt(br.readLine()); Course c = new Course(course_name, regcode, max_stu); break; case 2: System.out.println("What is the student name?"); studname = br.readLine(); System.out.println("What is the student id?"); stuidnum = Integer.parseInt(br.readLine());; c1.add_student(stuidnum); //HERE------------------------------------------------>>>>>>> break; case 3: System.out.println("Enter a student id?"); stuidnum = Integer.parseInt(br.readLine()); c1.remove_student(stuidnum); //HERE------------------------------------------------>>>>>>> break; } } while(usr_ch!=4); } } ============================================EXCEPTION CLASS /* Exception handling in case incorrent information is entered */ public class MyException extends Exception { void add_student(int stuidnum) { try{ if((reg_stud.size) == student_max) { throw new MyException(); } else reg_stud.add(stuidnum); } catch(Exception e) { System.out.println("Course has maximum students"); } } void rem_student(stuidnum) { try{ if(reg_student.contains(stuidnum)) reg_stud.remove(new Integer(stuidnum)); else throw new MyException(); }catch(Exception e) {System.out.println("NO STUDENT FOUND WITH THE GIVEN id");} } } ===========PERSON CLASS /*This class captures the commonality and uses it as a base class for Student class and Instructor class. */ public class Person { String studname, instrucnam; int facid, stuidnum; } ===========STUDENT CLASS /* Student class that stores data fields for a student - student name - student id number - number of credits - total grade points earned */ public class Student extends Person { String studname; int stuidnum; int class_credits, grade_pts; //This constructor initializes the name and id fields Student(String studname,int stuidnum) { this.studname = studname; this.stuidnum = stuidnum; } //Method to return the student name field String get_name() { return studname; } //Method to return the student id field int get_stuidnum() { return stuidnum; } //Method determines if two students objects are equal boolean two_equal(int stuidnum) { if((this.stuidnum) == stuidnum) return true; else return false; } //Sets the total number of credits void set_credits(int credit) { class_credits = credit; } //Gets the total number of credits int get_credits() { return class_credits; } //Sets the total number of grade points earned void set_gptotals(int gpoints) { grade_pts = gpoints; } //Sets the total number of grade points earned int get_tgpt() { return grade_pts; } //Method returns the GPA float get_gpa() { return ((grade_pts)/(class_credits)); } } ================================INSTRUCTOR CLASS /*Instructor class that stores the data fields for an instructor - name - faculty id number - department */ public class Instructor extends Person { String instrucnam; int facid; String department; //Name and id fields are initialized Instructor(String instrucnam, int facid) { this.instrucnam = instrucnam; this.facid = facid; } //Set department void set_department(String department) { this.department = department; } //Get department String get_department() { return department; } } ==============================COURSE CLASS /*Course class that stores the data for a course - name of a course - course registration code - max number of 35 students - instructor - number of students - students registered in the course(an array) */ //import java.io.InputStream; import java.util.*; public class Course { String course_name, instructor_name; int course_reg; int student_max, student_in_class; //private Student[] students = new Student[35]; ArrayList reg_stud = new ArrayList(); Course(String course_name,int course_reg,int student_max) { this.course_name = course_name; this.course_reg = course_reg; this.student_max = student_max; } void set_instructor(String instructor_name) { this.instructor_name = instructor_name; } boolean search_student(int stuidnum) { if(reg_stud.contains(stuidnum)) return true; else return false; } }Explanation / Answer
1) Scanner c1 = new Scanner(System.in); 2) remove one semicolon (;) after br.readLine()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.