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 10 of 10

Thread: Having trouble making calls.

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Having trouble making calls.

    I am working on a program that takes a user input file name, and pulls specific information from that file (ie number of students, names, and scores). I am having some difficulty wrapping my mind around calls to other methods. I realize that my code will most likely be fraught with errors but that is why I am here. My most pressing issue is this: I want to call private static Student[] getStudents(int n) and have it populate my array that I have attempted to set up.


    import java.util.Scanner;
     
    public class Lab6
    {
        public static void main(String[] args)
        {
            // Fill in the body according to the following comments
        	Scanner in = new Scanner(System.in);
        	// Input file name
        	String filename = getFileName(in);
        	// Input number of students
        	int n = FileIOHelper.getNumberOfStudents(filename);
        	// Input all student records and create Student array and
        	// integer array for total scores
        	Student [] students;
        	students[n] getStudents(n);
        	int [] totalScores = new int [n];
        	int j = 0;
        	while (j < n)
        	{
        		totalScores[j] = (std.getScore(1) + std.getScore(2) + std.getScore(3));
        		j++;
        	}
        	// Compute total scores and find students with lowest and
        	// highest total score
     
        	// Compute average total score
     
        	// Output results
        }
     
        // Given a Scanner in, this method prompts the user to enter
        // a file name, inputs it, and returns it.
        private static String getFileName(Scanner in)
        {
            // Fill in the body
        	System.out.print("Enter input file name: ");
        	String filename = in.nextLine();
        	return filename;
            // Do not declare the Scanner variable in this method.
            // You must use the value this method receives in the
            // argument (in).
       }
     
        // Given the number of students records n to input, this
        // method creates an array of Student of the appropriate size,
        // reads n student records using the FileIOHelper, and stores
        // them in the array, and finally returns the Student array.
        private static Student[] getStudents(int n)
        {
            // Fill in the body
     
        	int pos = 0;
        	Student[] students;
        	while (pos < n)
        	{
        		students[pos] = FileIOHelper.getNextStudent();
        		pos = ++pos;
        	}
        	return students;
        }
     
        // Given an array of Student records, an array with the total scores,
        // the indices in the arrays of the students with the highest and
        // lowest total scores, and the average total score for the class,
        // this method outputs a table of all the students appropriately
        // formatted, plus the total number of students, the average score
        // of the class, and the name and total score of the students with
        // the highest and lowest total score.
        private static void outputResults(
                Student[] students, int[] totalScores,
                int maxIndex, int minIndex, int average
            )
        {
            // Fill in the body
        }
     
        // Given a Student record, the total score for the student,
        // and the average total score for all the students, this method
        // outputs one line in the result table appropriately formatted.
        private static void outputStudent(Student s, int total, int avg)
        {
            // Fill in the body
        	System.out.println(Student(filename) + std.getScore(1) + std.getScore(2) + std.getScore(3) + (std.getScore(1) + std.getScore(2) + std.getScore(3)));
     
        }
     
        // Given the number of students, this method outputs a message
        // stating what the total number of students in the class is.
        private static void outputNumberOfStudents(int n)
        {
            // Fill in the body
        	System.out.println("Number of students: " + n);
        }
     
        // Given the average total score of all students, this method
        // outputs a message stating what the average total score of
        // the class is.
        private static void outputAverage(int average)
        {
            // Fill in the body
        }
     
        // Given the Student with highest total score and the student's
        // total score, this method outputs a message stating the name
        // of the student and the highest score.
        private static void outputMaxStudent(
                Student student,
                int score
            )
        {
            // Fill in the body
        }
     
        // Given the Student with lowest total score and the student's
        // total score, this method outputs a message stating the name
        // of the student and the lowest score.
        private static void outputMinStudent(
                Student student,
                int score
            )
        {
            // Fill in the body
        }
    }

    Any help is greatly appreciated and my apologies in advance if I missed any required etiquette.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Having trouble making calls.

    What does your code do now? If you are getting errors, please copy and paste the full text here.

    Do you have any specific questions?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble making calls.

    you not yet describe [n] value

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble making calls.

    Quote Originally Posted by Norm View Post
    I want to call private static Student[] getStudents(int n) and have it populate my array that I have attempted to set up.
    I realize I did not phrase this in the form of a question.

    How do I call private static Student[] getStudents(int n) and have it populate my array that I have attempted to set up?

    I am unable to compile due to other errors in my code.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Having trouble making calls.

    How do I call private static Student[] getStudents(int n)
    Call it like this: Student[] stdArray = getStudents(<an int here>);
    have it populate my array
    In getStudents(), create an array, use a loop to create some Student objects and put in the array and return that array.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    ntracing777 (May 31st, 2012)

  7. #6
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble making calls.

    where the section?

  8. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Having trouble making calls.

    Why did erdy_rezki get banned? What'd he do? I don't recall him getting so much as a warning from a mod or admin.

    Did he just get banned yesterday as he was listed as last visiting yesterday?

    Just checking to see if it was by mistake.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Having trouble making calls.

    Take a look at his posts and see if there is any substance to them.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Having trouble making calls.

    Sometimes yes. Sometimes he posted a bunch of code. Others he posted only a one liner.

  11. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Having trouble making calls.

    Quote Originally Posted by javapenguin View Post
    Why did erdy_rezki get banned? What'd he do? I don't recall him getting so much as a warning from a mod or admin.

    Did he just get banned yesterday as he was listed as last visiting yesterday?

    Just checking to see if it was by mistake.
    No, it was not a mistake. And yes, he received warnings regarding his non-informative and confusing one line posts.

    Please don't hijack someone else's post. There are other categories in which you can bring this up.

Similar Threads

  1. Java recursive calls
    By ksahakian21 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 1st, 2012, 01:50 PM
  2. How to make calls to methods
    By ksahakian21 in forum Java Theory & Questions
    Replies: 4
    Last Post: April 6th, 2012, 10:57 PM
  3. BlueJ trouble or program trouble (Combining Arraylists)
    By star12345645 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2012, 12:15 PM
  4. Identifying invalid calls
    By joshft91 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 26th, 2011, 05:38 PM
  5. Any way to map method calls?
    By Swiftslide in forum Collections and Generics
    Replies: 1
    Last Post: September 21st, 2009, 04:37 AM