So here are my directions for this program:
Write a program that allows the user to enter students names followed by their test scores and outputs the following information(assume that the maximum nmber of students in the class is 50; if the number of students is less than 50, to indicate the end of input data, after entering the last students data, on a line by itself, hold the ctrl key/press z and then press the Enter key):
a) Class average
b) Names of all the students whose test scores are below the class average, with an appropriate message( youre below class average)
c) Highest test score and the names of all the students having the highest score.
Use methods.
Now I wrote the program but i cant figure out how to end the input by pressing ctrl key/press z and then press the Enter key... Can some one show me how this is done?
Here is my code
import java.util.Scanner; public class ClassAverage { public static void main(String args[]) { String names[] = new String[50]; int scores[] = new int[50]; int entries = 0; Scanner in = new Scanner(System.in); //System.out.println("Enter number of entries"); //int entry = in.nextInt(); System.out.println("Enter the names followed by scores of students: "); for(int i = 0; i < 50; i++) { names[i] = in.next(); scores[i] = in.nextInt(); entries++; } Average avg = new Average(); double average = avg.CalcAvg(scores,entries); System.out.println("The class average is: " + average); avg.belowAvg(scores,average,names,entries); avg.highestScore(scores,names, entries); } } class Average { Average() { System.out.println("The averages: "); } double CalcAvg(int scores[], int entries) { double avg; int total = 0; for(int i = 0; i < entries; i++) { total += scores[i]; } avg = total/entries; return avg; } void belowAvg(int scores[],double average,String names[], int entries) { for(int i = 0; i < entries; i++) { if(scores[i] < average) System.out.println(names[i] + "You're below class average"); } } void highestScore(int scores[],String names[], int entries) { int max = scores[1]; for(int i = 0; i < entries; i++) { if(scores[i]>=max) max=scores[i]; } System.out.println("The maximum score is: " + max); System.out.println("The highest score acheivers list: "); for(int i = 0; i < entries; i++) { if(scores[i] == max) System.out.println(names[i]); } } }