Create the following two methods in java. You will need to have SearchCourse as
ID: 3718123 • Letter: C
Question
Create the following two methods in java. You will need to have SearchCourse as part of your code for Drop Course. Courses are in the form of "ABC123" with no space inbetween
Public/Private Method Name Description Parameters and Data Type Return Value and Data Type Searches through the Course existing courses in name: String. the array for a particular course name. Displays one of two messages: Name of course and number of credits if found OR message stating that the course was not found. Public searchCourse InExplanation / Answer
Assuming an array of course (Courses) exists as a member of the class to which these two methods
belong:
int searchCourse(String name){
for (int i = 0; i< Courses.length; i++){
if (Courses[i].getName().equals(name)){
System.out.println(Courses[i].getName() + " " + Integer.toString(Courses[i].getCredits()));
return i;
}
}
return -1;
}
void dropCourse(String name){
int a = searchCourse(name);
if (a != -1 ){
for (int i = a+1; i < Courses.length; i++) {
Courses[i].setName( Courses[i+1].getName());
Courses[i].setCredits( Courses[i+1].getCredits());
}
totalNumCourses--;
totalNumCredits = totalNumCredits - Courses[a].getCredits();
}
else {
cout << "Course can not be dropped as it is not in the schedule ";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.