Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am having trouble with my code output. I have attached my codes in parts as well as the incorrect output. Any sort of

Hi,

I am having trouble with my code output.

I have attached my codes in parts as well as the incorrect output.

Any sort of help will be appreciated.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
public clas private Subject subject; private String group; private int number; private String day; private int start; private int duration; private String room; private int capacity; private int enrolled = 0; public Activity(Subject subject, String group, int number, String day, int start, int duration, String room, int capacity) this. subject = subject; this. group = group; this. number = number; this . day = day; this. start= start; this . duration = duration; this. room = room; this. capacity = capacity; public Subject getSubject ( ) return subject; public String getGroup( ) return group public int getNumber ( ) return number; / /NEW public boolean isFull( ) if (enrolled==capacity) return true; else return false; /NEW public int getCapacity( ) return capacity; /NEW public int getEnrolled( ) return enrolled; / /NEW public boolean hasCapacity ( ) if (enrolled activities = new LinkedList( ); public Student (String number, String name) this . number = number; this . name =name; public boolean hasNumber (String number) return number . equals (this. number) ; public String getNumber( ) return number; public void addEnrolledActivityToList(Activity activity) activities. add (activity); public void viewEnrolledActivity ( ) for (Activity activity: activities) System. out . printIn(activity) ; public void removeEnrolledActivity(Activity activity) activities. remove (activity); public Activity has(mp1 (Subject subject) Activity toReturn = null; for (Activity activity: activities) if (activity. getSubject() == subject && activity. getGroup() . equals ("(mp1") ) toReturn = activity; return toReturn; / /NEW public Activity hasSubjectGroup (Subject subject, String group) Activity hasSubGroup = null; for (Activity activity: activities) if (activity. getSubject() == subject && activity. getGroup() . equals (group) ) hasSubGroup = activity; } return hasSubGroup; } aOverride public String toString ( ) return number + " " + name ; public void removeEnrolled ( ) for(Activity activity: activities) } activity. withdrawStudent ( ) ;[import java. util. *; public class Subject private int number; private String name; private LinkedList activities = new LinkedList( ) ; public Subject (int number, String name) //initialise the fields this . number = number; this . name = name public void addActivity (String group, int number, String day, int start, int duration, String room, int capacity) activities. add (new Activity (this, group, number, day, start, duration, room, capacity) ) ; public void printActivity (Subject subject) for (Activity activity: activities) if (activity. getSubject ()== subject) System. out . print in (activity); public Activity enrolInActivity (String group, int activityNumber) Activity enrolledActivity = null; for (Activity activity: activities) if(activity. getGroup () . equals (group) && activity. getNumber() == activityNumber) if (activity. hasCapacity ( ) ) activity . enrolStudent() ; enrolledActivity = activity; } / /System. out . printin("Enrolled in Subject"); else System. out . print In("No available seats"); return enrolledActivity; public Activity autoEnrolInActivity (String group, int activityNumber) Activity enrolledActivity = null; for (Activity activity: activities) if(activity. getGroup ( ) . equals ("Cmp1") && activity. getNumber( ) == activityNumber) if (activity . hasCapacity ( ) ) activity . enrolStudent ( ) ; enrolledActivity = activity; / /System. out . printIn("Enrolled in Subject"); return enrolledActivity; return null; public boolean checkActivity (String group, int activityNumber) for (Activity activity: activities) if (activity. getGroup () . equals (group) && activity. getNumber () == activityNumber) return true; return false ; / /NEW //checks if activity is full or not public Activity autoEnrol (String group) for (Activity activity: activities) if (autoEnrolInActivity (group, activity . getNumber( ) )== null) / /System. out . printin("No available seats") ; //return null;else return activity; } return null; / / NEW public boolean checkSubjectActivity(int subjectNumber, String group) for (Activity activity: activities) if (number == subjectNumber && activity . getGroup ( ) . equals (group) ) return true; return false; public void withdrawStudentFromActivity(Activity activity) activity . withdrawStudent ( ) ; aOverride public String toString() return number + " " + name; public String getName ( ) return name; public int getNumber( ) return number; public String printSelectedActivity( ) for (Activity activity: activities) return activity . toString(); return null;public void showStudentOptions (Student student) char choice; while( (choice = StudentReadChoice( ) ) != 'x' ) switch (choice) case 'v': studentViewEnrolledActivities (student) ; break; case 'e': studentEnrolInActivity (student) ; break; case 'w': withdrawFromActivity (student); break; default: studentOptionsHelp( ) ; break; private char StudentReadChoice() System. out. print ("Choice (v/e/w/x) : ") ; return In. nextChar ( ); private void studentOptionsHelp( ) System. out . print In("Student menu options" ) ; System. out . printIn("v = view my activities"); System. out . print In("e = enrol in an activity"); System, out . print In("w = withdraw from an activity"); System. out . printIn("x = exit"); public void studentViewEnrolledActivities (Student student) student. viewEnrolledActivity ( ) ; public void studentEnrolInActivity (Student student) int subjectNumber=0; Activity enrolledActivity, tempActivity = null; String tempInput; System. out . printIn("Select a subject"); for (Subject subject: subjects) System. out. printIn (subject); subjectNumber = readSubjectNumber ( ) ; Subject subject = subject (subjectNumber) ; if ( checkSubject ( subjectNumber) ) { / / check subject System, out . print In("Select an activity"); if (subject !=null) { subject. printActivity(subject) ; System. out. print ("Activity code (group:activity) : "); String choiceInput =In. nextLine( ) ; tempInput = choiceInput. split(":"); String group = tempInput [0] ; if ( tempInput. length == 2) int activityNumber = Integer . parseInt ( tempInput [1] ) ; if ( checkActivity (subject, group, activityNumber )== false) System. out. printIn("No such activity"); else if (group. equals ("Lec1") ) enrolledActivity = subject. enrolInActivity (group, activityNumber) ; if(enrolledActivity!=null) w student. addEnrolledActivityToList(enrolledActivity) ; else tempActivity = student, hasCmpl (subject) ; if (tempActivity != null) student. removeEnrolledActivity( tempActivity) ; subject.withdrawStudentFromActivity(tempActivity) ; enrolledActivity = subject. enrolInActivity(group, activityNumber) ;tempActivity = student , has(mp1(subject) ; if (tempActivity != null) student. removeEnrolledActivity(tempActivity) ; subject. withdrawStudentFromActivity(tempActivity) ; enrolledActivity = subject. enrolInActivity(group, activityNumber) ; if (enrolledActivity!=null) } student. addEnrolledActivityToList(enrolledActivity); } else enrolledActivity = subject. enrolInActivity (group, activityNumber) ; if (enrolledActivity!=null) student . addEnrolledActivityToList (enrolledActivity) ; } else if(tempInput. length == 1) Subject subSubject = subject (subjectNumber) ; Activity activity = subSubject. autoEnrol(tempInput [0] ) ; if (activity!=null) student . addEnrolledActivityToList (activity) ; else System. out. printIn ("No available seats"); } else System, out. printIn ("No such subject"); private int readSubjectNumber ( ) System. out. print ("Subject number: ") ; int number = In. nextInt( ) ; } return number; / /NEW public void withdrawFromActivity (Student student) String tempInput; System. out. print ("Activity code (subject:group) : ") ; String choiceInput =In. nextLine( ) ; tempInput = choiceInput. split(":"); String group = tempInput [1] ; int subjectNumber = Integer . parseInt ( tempInput [0] ) ; Subject subject = subject (subjectNumber) ; Activity subjectEnrolled = null; if ( checkSubject (subjectNumber) ) if ( checkSubjectActivity (subject, subjectNumber , group)= false) System, out. printIn("Not enrolled in activity"); } else subjectEnrolled = student. hasSubjectGroup (subject, group) ; { if (subjectEnrolled != null) student. removeEnrolledActivity (subjectEnrolled) ; subject. withdrawStudentFromActivity (subjectEnrolled) ; } else //System. out . printIn ("subject not enrolled yet") ; System. out. print In("Not enrolled in activity");import java. util.*; public class University private LinkedList subjects = new LinkedList( ) ; private LinkedList students = new LinkedList( ) ; public University( ) Subject sub1 = new Subject (48024, "Applications Programming") ; Subject sub2 = new Subject (31284, "Web Services Development" ) ; addActivities (sub1) ; addActivities (sub2) ; subjects. add (sub1) ; subjects . add ( sub2) ; public void addActivities (Subject subject) if (subject . getName( ) . equals ("Applications Programming") ) subject . addActivity ("Lec1", 1, "Wed" , 18, 1, "CB11. 00. 405" , 200) ; subject . addActivity ("Cmp1", 1, "Wed", 19,2, "CB11. B1. 403", 2) ; subject. addActivity("Cmp1", 2, "Wed", 19,2, "C "CB11. B1. 401", 2) ; } subject. addActivity("Cmp1", 3, "Wed", 19,2, "CB11. B1. 402",2) ; else subject . addActivity ("Lec1", 1, "Tue", 16, 1, "CB02. 03. 002", 160) ; subject. addActivity("Cmp1", 1," subject. addActivity ("Cmp1", 2," ",1, "Tue" , 9,2, "CB11. B1. 102",30); ", 2, "Tue" , 9,2, "CB11. B1. 103", 30) ; subject. addActivity ("Cmp1",3, "Tue", 14, 2, "CB11. B1. 102", 30); subject. addActivity("Cmp1", 4, "Tue", 14, 2, "CB11. B1. 103",30); public static void main (String args) new University ( ) . use ( ) ; public void use( ) char choice; while((choice = readChoice( ) ) != 'x' ) switch (choice) case 'a': addStudent ( ) ; break; case 'r' : removeStudent ( ) ; break; case 'v': viewAllStudents ( ); break; case 'l': login( ); break; default: help(); break; private char readChoice( ) { System. out. print ("Choice (a/r/v/1/x) : "); return In. nextChar ( ); private void help( ) { System. out. print In ("University menu options") ; System. out. print ln("a = add a student") ; System. out. println("r = remove a student"); System. out. printIn("v = view all students") ; System. out . print ln("l = login"); System. out. printIn("x = exit") ; public void addStudent ( ) String number = readNumber ( ) ; if (checkNumber (number) ) } System. out. print In("Student number already exists"); else String name = readName ( ) ; students. add ( new Student ( number, name) ) ;public void removestudent( ) String number = readNumber ( ) ; for (int i =0; i it = students. iterator(); it. hasNext(); ) if (it. next ( ) . hasNumber (number) ) it. remove ( ) ; }* / System. out . print In("No such student") ; public void viewAllStudents ( ) for (Student student : students) // removeStudent ( ) ; System. out . print In ( student) ; public void login() String number = readNumber ( ) ; Student student = student (number) ; if (student!= null) showStudentOptions (student) ; else System. out. print in("No such student") ; private String readNumber ( ) System. out . print ("Number: ") ; String number = In. nextLine( ) ; return number; private String readName ( ) System. out. print ("Name: ") ; return In. nextLine ( ) ; private boolean checkNumber (String number) for (Student student: students) if (student. hasNumber(number) ) } return true; return false; private Student student (String number) for (Student student: students) { if (student. hasNumber (number) ) return student; return null; }System. out . printIn("Not enrolled in activity"); } // System. out. print In("Not enrolled subject") ; private boolean checkSubject (int number) for (Subject subject: subjects) if ( subject. getNumber ( )== number) return true; } return false; private Subject subject (int number) for (Subject subject: subjects) if (subject. getNumber ( )== number) } return subject; return null; private boolean checkActivity (Subject subject, String group, int number) if ( subject. checkActivity (group, number) ) return true; } else return false; private boolean checkSubjectActivity (Subject subject, int subjectNumber, String group) if ( subject. checkSubjectActivity(subjectNumber, group) ) return true; else return false; / /NEW //checks if activity is full or not { /*private boolean checkFullStatus (Subject subject, String group, int enrolled, int capacity) if (subject. checkFullStatus (group, enrolled, capacity) ) { return true; } else { return false; 3 * /

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Who has the right to strike?

Answered: 1 week ago

Question

\f

Answered: 1 week ago