Created
February 17, 2014 01:51
-
-
Save AndresRodz/9043339 to your computer and use it in GitHub Desktop.
Andres Rodriguez A01193126, Hector Carpizo A01193092
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Andres Rodriguez A01193126, Hector Carpizo A01193092 | |
| import java.util.Scanner; | |
| public class StudentsGrades { | |
| public static void main(String [] args) { | |
| Scanner input = new Scanner(System.in); | |
| String[] arraynames = Names(); | |
| int[] arraygrades = Grades(arraynames); | |
| for(int i = 0; i < arraynames.length; i++){ | |
| if((arraynames[i]).charAt(0) == '*'){ | |
| System.out.println("\nNumber of students in the class: " + i); | |
| break; | |
| } | |
| } | |
| // Print names and grades | |
| for (int y = 0; y < arraynames.length; y++) { | |
| if ((arraynames[y]).charAt(0) == '*') { | |
| break; | |
| } | |
| System.out.println(arraynames[y] + " " + arraygrades[y]); | |
| } | |
| // Print the highest grade | |
| int highest = HighScore(arraygrades); | |
| System.out.println("\nHighest grade: " + highest); | |
| //Print the student(s) with the highest grade | |
| System.out.println("\nThe student(s) with this score were: "); | |
| for (int z = 0; z < arraygrades.length; z++) { | |
| if (arraygrades[z] == highest) { | |
| System.out.print(arraynames[z] + ", "); | |
| } | |
| } | |
| } | |
| // Method for asking the names | |
| public static String[] Names() { | |
| Scanner input = new Scanner(System.in); | |
| String[] names = new String[30]; | |
| for (int x = 0; x < names.length; x++) { | |
| names[x] = input.nextLine(); | |
| if ((names[x]).charAt(0) == '*') { | |
| break; | |
| } | |
| } | |
| return names; | |
| } | |
| // Method for asking the grades | |
| public static int[] Grades(String [] arraynames) { | |
| Scanner input = new Scanner(System.in); | |
| int[] grades = new int[30]; | |
| for (int y = 0; y < grades.length; y++) { | |
| if ((arraynames[y]).charAt(0) == '*') { | |
| break; | |
| } | |
| grades[y] = input.nextInt(); | |
| } | |
| return grades; | |
| } | |
| // Method for finding the highest grade | |
| public static int HighScore(int[] arraygrades) { | |
| int max = arraygrades[0]; | |
| for (int i = 0; i < arraygrades.length; i++) { | |
| if (max < arraygrades[i]) { | |
| max = arraygrades[i]; | |
| } | |
| } | |
| return max; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment