Last active
April 18, 2018 12:03
-
-
Save heiybb/618b866cf2330447326951efe6ab69cc to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Scanner; | |
public class Student { | |
private String name; | |
private float mark; | |
public static void main(String[] args) { | |
Scanner stInput = new Scanner(System.in); | |
System.out.print("Enter number of students:\n"); | |
int num = stInput.nextInt(); | |
stInput.nextLine(); | |
Student[] stGp = new Student[num]; | |
// info input | |
for (int i = 0; i < num; i++) { | |
System.out.print("Enter name and mark:\n"); | |
stGp[i] = new Student(); | |
stGp[i].name = stInput.nextLine(); | |
stGp[i].mark = stInput.nextInt(); | |
stInput.nextLine(); | |
} | |
// average mark | |
float sum = 0; | |
for (Student aSt : stGp) { | |
sum = sum + aSt.mark; | |
} | |
float average = sum / num; | |
System.out.print("The average mark is " + average + "\n"); | |
// get the highest mark and name | |
float highest = stGp[0].mark; | |
String highestName = ""; | |
for (Student aSt : stGp) { | |
if (aSt.mark > highest) { | |
highest = aSt.mark; | |
highestName = aSt.name; | |
} | |
} | |
System.out.print("The highest mark and student is " + highestName + " " + highest + "\n"); | |
// list who above average | |
System.out.print("Students whose mark scoring above average:\n"); | |
for (Student aSt : stGp) { | |
if (aSt.mark >= average) { | |
System.out.print(aSt.name + "\n"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment