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.
Code Java:
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.
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?
Re: Having trouble making calls.
you not yet describe [n] value
Re: Having trouble making calls.
Quote:
Originally Posted by
Norm
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.
Re: Having trouble making calls.
Quote:
How do I call private static Student[] getStudents(int n)
Call it like this: Student[] stdArray = getStudents(<an int here>);
Quote:
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.
Re: Having trouble making calls.
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.
Re: Having trouble making calls.
Take a look at his posts and see if there is any substance to them.
Re: Having trouble making calls.
Sometimes yes. Sometimes he posted a bunch of code. Others he posted only a one liner.
Re: Having trouble making calls.
Quote:
Originally Posted by
javapenguin
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.