Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: College Course-Array

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default College Course-Array

    Hi all,
    Im new to the forum. I really need some help on this program i am doing. Im currently trying to teach myself java so i have some knowledge for my upcoming college class. My current program deals with arrays. It is suppose to prompt the user, a college professor, to enter 10 student IDs, and then a grade for a certain course, which it asks for the course grade only 5 times. I finally got this to compile after a lot of time spent on it. My issue is that it completely skips the entering student ID's and goes straight to entering the grade and im not sure why. This probably isnt the only problem but its the current problem i am having. Here is my code:
    import java.io.*;
      public class InputGrades {
      private int idGrade;
      public CollegeCourse[] courses = new CollegeCourse[5];
      public InputGrades(int gradeID)
      {
            idGrade = gradeID;
            courses[0] = new CollegeCourse('A', "CIS 210", 3);
            courses[1] = new CollegeCourse('B', "CIS 211", 2);
            courses[2] = new CollegeCourse('C', "CIS 212", 2);
            courses[3] = new CollegeCourse('D', "CIS 213", 3);
            courses[4] = new CollegeCourse('F', "CIS 214", 1);
       }
    public static void main(String[] args) throws IOException
    {
     
           InputGrades inputgrades = new InputGrades(1);
     
              char value;
              boolean match = false;
                 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
     
                 for (int s = 1; s <= 10; s++) 
                 {
                   System.out.println("Enter ID for student#: " + s);
                 }
              for (int n = 1; n <= 5; n++) 
                 {
                   System.out.print("\tEnter grade for course ID#" + n + ": " 
                        + inputgrades.courses[x].getCourseID());
                   value = stdin.readLine().charAt(0);
              if ((value == 'A') || (value == 'B') || (value == 'C')
                    || (value == 'D') || (value == 'F')) 
                     {
                       match = false;
                 } 
                     else 
                     {
                 System.out.println("Please re-enter the grade");
                 match = true;
                 --n;
                 }
                }
     
         }
     }
    I really appreciate any help with this.

    Thanks,
    Sam


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: College Course-Array

    Try running your code as if you were the computer. Hint: look at your loop structure. You'll need a nested loop wrather than two consecutive loops. You're also forgetting to ask the user to actually input the student ID.

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: College Course-Array

    Ok, i did nest the For loops. and am working on the other user input part. When compiling it also tells me that the 'x' line System.out.print("\tEnter grade for course ID#" + n + ": " + inputgrades.courses[x].getCourseID());
    is an unfound variable. I seen someone else use that in their code with out declaring it as a varible and thats where i got it from but dont understand it and why for me it needs to be declared as a varible. Am still working on the enterring student part and will post that update tomorrow hopefully.

    Thanks,
    Sam

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: College Course-Array

    In Java if you don't declare it, it doesn't exist. Likely they did declare it somewhere and you just didn't see it, or their code is wrong, too.

Similar Threads

  1. College Assignment please help
    By The Lost Plot in forum Collections and Generics
    Replies: 7
    Last Post: March 13th, 2012, 09:27 AM
  2. New to Programming, Starting college for computer engineering
    By TheBLC84 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2010, 04:06 AM
  3. [SOLVED] Create new Array from old Array
    By satory in forum Collections and Generics
    Replies: 1
    Last Post: February 24th, 2010, 11:44 AM
  4. Object array to int array?
    By rsala004 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2009, 04:09 AM
  5. Storing an array into an array
    By vluong in forum Collections and Generics
    Replies: 4
    Last Post: September 22nd, 2009, 02:14 PM