title: Issue dropping credits from course in Java dropCourse Method
body: <p>What I have is a two snippets of code. The question I have in particular is about my dropCourse method within the student driver. Everything in my code seems to work fine except when I drop a course it does not drop the courses credits. For example, if I drop a course named "Computer101" which had four credits, it will remove "Computer101" From the schedule, but will not remove the "4" credits when I choose option 5 to print the total credits. So if we have a full schedule of:</p>
  
  <p>Computer101 in position 0 worth 4 credits</p>
  
  <p>Physics105 in position 1 worth 4 credits</p>
  
  <p>Art101 in position 2 worth 4 credits</p>
  
  <p>Chem101 in position 3 worth 4 credits</p>
  
  <p>And I decide to drop Computer101 from the schedule, all other classes will move up in their position in the array as they are supposed to, when printing the schedule that class will no longer show up and when it is searched for it will not be found, but the amount of credits it was worth will still be there. I feel like the solution is right in front of me, but I am so burned out I am not seeing it. I would really appreciate any help and I hope I was clear with what I am asking.</p>
  
  <p>Here is where my dropCourse method will be found:</p>
  
  <pre><code>public class Student
  {
     //Instance Data
     String studentName;
     String studentID;
     String streetAddress;
     String city;
     String state;
     String zipCode;
     String major;
     final int MAX_CREDITS = 18;
     int courseNumber = 0;  //start out with no courses
     int  totalCredits;
     final int SIZE = 6;
     String [ ] schedule = new String [SIZE];
  
     //Create Constructor:
     //Initializes the student data at instantiation time.
     //-------------------------------------------------------
     //  Sets up the student's information.
     //-------------------------------------------------------
     public Student (String name, String id, String address, String cityName, String stateName, String zip, String area )
     {
       studentName = name;
       studentID = id;
       streetAddress = address;
       city = cityName;
       state = stateName;
       zipCode = zip;
       major = area;
     }//end Student Constructor
  
     //Method to Return student information as string:
     //-------------------------------------------------------
     //  Returns the student information as a formatted string.
     //-------------------------------------------------------
     public String toString()
     {
       String studentInfo;
  
       studentInfo = "Name:\t\t\t" + studentName + "\n" + "ID:\t\t\t" + studentID + "\n" + "Address:\t\t" + streetAddress
             + "\n" + "City:\t\t\t" + city + "\n" + "State:\t\t\t" + state + "\n" + "Zip Code:\t\t" + zipCode
             + "\n" + "Major:\t\t\t" + major + "\n";
  
       return studentInfo;
     }// end toString
     //Method to determine if maximum allowed credits have been exceeded
     //-------------------------------------------------------
     //  Returns true if total credits does not exceed 18.
     //-------------------------------------------------------
     private boolean checkCredits(int numCredits)
     {
        if (numCredits + totalCredits &lt;= MAX_CREDITS)  //make sure max credits not exceeded
        {
           return true;  //return a true if still less than 18 credits
        }
        else
        {
           return false;  //return a false if 18 credit limit is exceeded
        }//end numCredits
     }//checkCredits
  
     //Method to add a course to the student’s schedule
     //-------------------------------------------------------
     //  Adds a course to the array if total credits does not exceed 18.
     //-------------------------------------------------------
     public void addCourse(String course, int numCredits)
     {
        if (courseNumber &lt;  SIZE )  //make sure array is not full. 
        {
           if (checkCredits(numCredits) == true) //if we’re under 18 credits
           {
              //add course
              schedule [courseNumber] = course + ":\t\t" + numCredits + "\tCredits\n";
              //increment number of credits
              totalCredits = totalCredits + numCredits;
              //increment number of courses
              courseNumber = courseNumber + 1;
              System.out.println("The course has been added!");
           }
           else  //oops – can’t do more than 18 credits
           {
              System.out.println("You have exceeded the maximum allowed credits.");
           }//end checkCredits
        }
        else  //oops – can’t do more than 6 courses
        {
           System.out.println("You have exceeded 6 courses.");
        }//end courseNumber
  
     }//addCourse
     public void displaySchedule( )
     {
        for (int index = 0; index &lt; courseNumber; index++)
           {
              System.out.println("Course #" + (index + 1) + " " + schedule[index] + "\n");
           }//end for
     }//end display schedule
  
     public int searchCourse(String courseName)
     {    
        String course;
        boolean flag = false;
        int index = 0;
        while(index &lt; courseNumber &amp;&amp; flag == false) 
        {
           String extract = schedule[index].substring(0,6);
           if (extract.contains(courseName) == true)
           {
              flag = true;
           } 
           else 
           {
              index++;
           }
        }
        if (flag == false)
        {  
           return -1;
        } 
        else
        {   
           return index++;   
        }
     }
     public void dropCourse(String courseName)
     {
        int found;
        found = searchCourse(courseName);
        int index = 0;
        if (found == -1)
        {
           System.out.println("Course not in schedule");
        }
        else
        {
           if (found == 5)
           {
              courseNumber = courseNumber -1;    
           }
           else
           {
              for (index = found; index &lt; courseNumber; index ++)
              {
                 schedule[index] = schedule[index + 1];
              }
              courseNumber = courseNumber -1;
              System.out.println("The course has been dropped!");
           }
        }
     }
     public int totalCredits()
     {
        System.out.println("The total credits are " + totalCredits);
        return totalCredits;
     }   
  }//end class Student
  </code></pre>
  
  
  
  <p>This is where my menu that works with the above code is:</p>
  
  <pre><code>//This is a Driver program to test the external Class named Student
  import java.util.Scanner;
  public class TheMenu //BEGIN Class Definition
  {
   //****************  Main Method*************************
      static Scanner scan = new Scanner(System.in);
      public static void main (String[] args)
      {
        //Data Definitions:
  
        //Instance Data
        String name;
        String id;
        String street;
        String city;
        String state;
        String zip;
        String major;
        String courseName;
        int courseCredits;
        int menu = 0;
  
        //Initialize first Student
        name = "Florence Welch";//look her up
        id = "7777";
        street = "777 Heaven Street";
        city = "Witchville";
        state = "NY";
        zip = "12345";
        major = "Arts";
        //instantiate the Student object
        Student student1 = new Student(name, id, street, city, state, zip, major);
        while (menu &lt; 6)//begin while for menu options
        {
           System.out.println("1. Add a course ");
           System.out.println("2. Search for a course");
           System.out.println("3. Drop a course");
           System.out.println("4. Print out a student's schedule");
           System.out.println("5. Print out total credits");
           System.out.println("6. Exit");
           System.out.println("Enter an option: ");
           menu = scan.nextInt();
  
           if (menu == 1)//option to add course
           {
              System.out.println("Please enter the name of the course: ");
              courseName = scan.next();
              System.out.println("How many credits is the course? ");
              courseCredits = scan.nextInt();
              student1.addCourse(courseName, courseCredits);//uses method to store course information in array
           }  
  
              else if (menu == 2)//option to search for course
              {
                 int x;
                 System.out.println("Please enter the name of the course: ");
                 courseName = scan.next();
                 student1.searchCourse(courseName);
                 x = student1.searchCourse(courseName);
  
                 if (x == -1)//course is not found if value returns -1
                 {
                    System.out.println("Course not found");
                 }
                 else
                 { 
                    System.out.println("Course found in position " + student1.searchCourse(courseName));//shows user the position of course
                 }
              }
           else if (menu == 3)//will drop course from users schedule
           {
              System.out.println("Please enter the course you wish to drop: ");
              courseName = scan.next();
              student1.dropCourse(courseName);
           }
           else if (menu == 4)//displays the users schedule
           {
              System.out.println(name + "'s Schedule:\n\n");
              student1.displaySchedule();
           }
           else if (menu == 5)//will display users credits for semester
           {
              student1.totalCredits();
           }
           else
           {
              System.out.println("Enjoy your semester!");//option 6 will exit program
           }
        }
     }
  }
  </code></pre>