Java: I\'m trying to get data the user selects from a menu to be saved into a co
ID: 3718480 • Letter: J
Question
Java: I'm trying to get data the user selects from a menu to be saved into a course section to be tested with a try catch block to verify the user hasn't enrolled in the same thing twice. Attached you'll see the pseudo code I'm working with. I've also attached an ouput for how the menu appears. I just can't figure out how to pull the data out of the menu array and assign it to the proper variable to initiate the try catch block. All help is apprecaited.
Data:
. Get information from console to instantiate your student 2. Create an array and call the getsections from your singleton to load it . DataStore dataStore DataStore.getlnstance(); .Section[] courseMenu dataStore.getSections); 3. Use a loop to show your menu: while truef for loop to display menu (this is courseMenu array or whatever you named it) ask user for input of which to enroll in if choose quit, brealk iary student addCourse (courseMenu[choice); catch Duplicate sys out Duplicate Exception getMessage() catch TooMany sys out TooMany Exception getMessage() 4. After your loop is over, print the student schedule a. Sys out student toString()Explanation / Answer
you need to save the students added course in a cache and before adding any course need to check whether that course is already present in that pojo. If yes, do not add it and move to next iteration. Also for too many check for size of the cache which is holding the number of course which student current has added in previous loops, if it exceeds your threshold, throw a message that it cannot be added anymore.
So a pseudocode would be :
while(true)
{
for loop to display menu (this is course array or whatever you named id)
ask user for input of which course to enroll in
if course quit,break
create an arrayList to hold course lets say courseList
If(list empty) -- this will your first iteration
{
student.addCourse(courseMenu(choice));
}
else if(list.count > your defined threshold of max course that a user can enroll for )
{
break loop and throw message saying "Max number of course already enrolled";
}
else if(list.contains(choice))
{
skip the loop and goback to next iteration
}
else if(list.contains(choice))
{
Student.Addcourse();
}
//end of for loop.
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.