Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trouble with nested if statement class roster program

$
0
0
i have this program running almost perfectly but my instructor wants me to add a warning if i try to delete an entire course that does not exist. i think the solution lies in a nested if statement in the area between the two "test" comments. does any one have an idea of how i can achieve this?
//java2
//11-5
//by taddei
//test course class  
   import java.util.ArrayList;
   import java.util.Date;
   import javax.swing.JOptionPane; 
 
   public class TestCourse {   
      public static void main(String [] args) {
      
         String chs = JOptionPane.showInputDialog(null, 
            "Enter Course Name", "Create Course", JOptionPane.INFORMATION_MESSAGE);
         Course course = new Course(chs);
      
         boolean menu = true;
         while(menu) {
         
            String choice = JOptionPane.showInputDialog(null,
               course.getDate() + "\n"  
               + course.getCourseName() + " Enrollment for Fall 2013\n"
               + "\n1.  Add Student"
               + "\n2.  Drop Student"
               + "\n3.  Drop Class"
               + "\n4.  Currently Enrolled"
               + "\n5.  Exit\n\n", "Selection Menu", JOptionPane.INFORMATION_MESSAGE);         
         
            if(choice.equals("1")) {
            
               String student = JOptionPane.showInputDialog(null, 
                  "Enter Student Name for " 
                  + course.getCourseName() + " Enrollment", "Add Student", JOptionPane.INFORMATION_MESSAGE);
               course.addStudent(student);
               String students = "";
               ArrayList<String> studentList = course.getStudents();
               for(int i = 0; i < studentList.size(); i++)
                  students += studentList.get(i)+"\n";
               JOptionPane.showMessageDialog(null, 
                  "Currently Enrolled in  " 
                  + course.getCourseName() 
                  + "\n\n" + students, "Class Roster", JOptionPane.INFORMATION_MESSAGE);
            }
            
            else if(choice.equals("2")) {
            
               String student = JOptionPane.showInputDialog(null, 
                  "Enter Student Name ", "Drop Student", JOptionPane.INFORMATION_MESSAGE);
               course.dropStudent(student);
               String students = "";
               ArrayList<String> studentList = course.getStudents();
               for(int i = 0; i < studentList.size(); i++)
                  students += studentList.get(i)+"\n";
               JOptionPane.showMessageDialog(null, 
                  "Currently Enrolled in " 
                  + course.getCourseName() 
                  + "\n\n" + students, "Class Roster", JOptionPane.INFORMATION_MESSAGE);
            }
            
            else if(choice.equals("3")) {
            
               String students = "";
               course.clear();
               JOptionPane.showMessageDialog(null, 
                   course.getCourseName() + " Has Been Deleted! "
                  + "\n\n" + students, "Delete Course", JOptionPane.INFORMATION_MESSAGE);
				/////////////test////////////
				{		
				if(!course.remove(course)) 
            JOptionPane.showMessageDialog(null, 
               "Course Does Not Exist!", "No Course Warning", JOptionPane.INFORMATION_MESSAGE);		
				}
				////////////test//////////////		
						
            }
            
            else if(choice.equals("4")) {
            
               String students = "";
               ArrayList<String> studentList = course.getStudents();
               for(int i = 0; i < studentList.size(); i++)
                  students += studentList.get(i)+"\n";
               JOptionPane.showMessageDialog(null, 
                  "Currently Enrolled in " 
                  + course.getCourseName() 
                  + "\n\n" + students, "Class Roster", JOptionPane.INFORMATION_MESSAGE);
            }
            
            else if(choice.equals("5")) {
               JOptionPane.showMessageDialog(null, 
                  course.getDate() + "\n\n" 
                  + "Exiting Enrollment for " 
                  + course.getCourseName(), "EXIT", JOptionPane.INFORMATION_MESSAGE);
               menu = false;
            }
            
            else {
            
               JOptionPane.showMessageDialog(null, 
                  "INVALID SELECTION! \n\n Please Enter 1-5 ", "INVALID SELECTION WARNING", JOptionPane.INFORMATION_MESSAGE);
            }
         }  	
      }
   }





my current errors are:
estCourse.java:68: error: cannot find symbol
				if(!course.remove(course)) 
				          ^
  symbol:   method remove(Course)
  location: variable course of type Course
1 error

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>