Results 1 to 5 of 5
  1. #1
    FcnChuck is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default New programmer - Course mgmt system

    This is my first class with Java and it is kicking my ass. I am attempting to make a simple course mgmt system that i can add students to certain courses using a string array. I am totally stuck. My if statement for number == 3 is not correct and when i check the array size, im getting a not found error. Any help would be great.

    oh and using NetBeans

    Java Code:
    public static void main(String[] args) throws IOException {
    // TODO code application logic here
    
    int courseNum = 0;
    String courseTitle;
    int courseMaxSize;
    boolean found = false;
    Course course;
    int studentUID;
    String studentName;
    double studentGPA;
    String newStudent;
    
    
    do {
    
    ArrayList<Course> courseArr = new ArrayList<Course>();
    courseArr.add(null);
    
    Scanner console = new Scanner(System.in);
    System.out.println("Please select from the following options:");
    System.out.println("1. Add a course");
    System.out.println("2. Add a student to a course");
    System.out.println("3. View available courses");
    System.out.println("4. Exit from system");
    int number = console.nextInt();
    
    
    
    if (number == 1) {
    System.out.println("Please enter Course Number");
    courseNum = console.nextInt();
    System.out.println("Please enter course Title");
    courseTitle = console.nextLine();
    System.out.println("Please enter the max size of the course");
    courseMaxSize = console.nextInt();
    
    String Courses = console.nextLine();
    
    } if (number == 2) {
    if (courseArr.size() == 0) {
    System.out.println("There are no courses in the system");
    }
    break;
    }
    
    System.out.println("Please enter the course you wish to search for");
    console.next();
    
    course = null;
    for (int i = 0; i < courseArr.size(); i++) {
    
    if (course.getCourseNum() == courseNum) {
    
    found = true;
    }
    }
    System.out.println("Please enter the student UID #");
    studentUID = console.nextInt();
    System.out.println("Please enter the Students name");
    studentName = console.next();
    System.out.println("Please enter the students GPA");
    studentGPA = console.nextInt();
    
    newStudent = console.nextLine();
    System.out.println("Student added successfully. The course "+ courseNum
    + "now has " + courseMaxSize + " students");
    
    if(course.addStudent() == courseMaxSize){
    System.out.println("Sorry the course is full, cannot add student");
    }
    if(course.addStudent() != course.getCourseNum()){
    System.out.println("Sorry, that course was not found. Try again.");
    }
    
    } if (number == 3) {
    
    if (courseArr.size() == 0){
    System.out.println("There are no courses to list");
    }
    
    
    
    }while (number != 4);
    
    }
    
    }
    Last edited by FcnChuck; 07-12-2013 at 05:44 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: New programmer - Course mgmt system

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default Re: New programmer - Course mgmt system

    a formatting nightmare.. format you the code through netbeans.

    you have a misplaced bracket
    Java Code:
    } if (number == 3) { // before the if you close the loop, delete the curly bracket before the if
    should be like this:
    Java Code:
    if (number == 3) {
    	 
    	if (courseArr.size() == 0){
    	System.out.println("There are no courses to list");
    	}
     }
    After you do that, you should declare the number variable outside the loop, otherwise in the while it won't be recognized.

  4. #4
    FcnChuck is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default Re: New programmer - Course mgmt system

    Thanks Super

    When i have attempted to declare number as an int outside the loop, i get an error on line 26 for my console input. The if statement for number == 3 works, but then im back to confusion on the console.nextint.

    Do i just need to remove the int on line 26?

    Is there another way to write line 26 as well?

  5. #5
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default Re: New programmer - Course mgmt system

    yes, remove the int if you declared outside int number;
    It's fine, just number = get the integer. What do you mean another way? Another way to get input?

Similar Threads

  1. Help making a Menu system for Student List System
    By jason3460 in forum New To Java
    Replies: 0
    Last Post: 12-09-2012, 01:39 PM
  2. Replies: 14
    Last Post: 08-07-2011, 09:25 AM
  3. system.out.printf versus system.out.format
    By bigsonny in forum New To Java
    Replies: 10
    Last Post: 06-21-2011, 10:40 PM
  4. Replies: 8
    Last Post: 06-21-2011, 02:21 PM
  5. Replies: 3
    Last Post: 02-07-2010, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •