• Status: Open
  • Priority: Low
  • Security: Public
  • Views: 38
  • Last Modified:

Sending information from one method to another

Here's what I'm trying to do and I'll explain it as best as I can.

1. input a number that represents the total number of students (Done)
2. take that number, send it to the "enterGrade" method (NOT DONE)

In my code below the "enterGrade" portion i'm stuck at is represented by <<<<<<<<<<<<<<<<<<<<<<<

Any suggestions and help are appreciated.






public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            //enter student amount
            System.out.println("Enter number of students: ");
            int student = input.nextInt();
            //check if more than 25 students
            if (student > 25) {
                  System.out.println("Cannot have more than 25 students, try again.");
                  System.exit(0);
                  
                  
            }
                //Send number of students to enter grade method <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            int grade = enterGrade(int[] student);
      }
                  
      public static void enterGrade(int[] student) {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter student's grades");
            int grades = 0;
            while( grades < student.length) {
                  student[grades] = input.nextInt();
                  grades++;
                  
                  
            }
            studentName();
      }
            
      public static void studentName() {
            
      }
0
Grant Richards
Asked:
Grant Richards
1 Comment
 
awking00Commented:
The first problem is in your main method. Student is an int (i.e. a single number <= 25) and you're trying to pass it as an int array to be populated with grades. You need to create the int array object first (e.g. int[] students = new int[student]), then pass it to the enterGrade method. There is no need to enter the object type, just pass the object itself. You will however need to define the type being passed in to the  enterGrade method when you create it. Hope it helps get you started.
0

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now