Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Student {
  4. private String name;
  5. private float mark;
  6.  
  7. public static void main(String[] args) {
  8. Scanner stInput = new Scanner(System.in);
  9. System.out.print("Enter number of students:\n");
  10. int num = stInput.nextInt();
  11. stInput.nextLine();
  12. Student[] stGp = new Student[num];
  13.  
  14. // info input
  15. for (int i = 0; i < num; i++) {
  16. System.out.print("Enter name and mark:\n");
  17. stGp[i] = new Student();
  18. stGp[i].name = stInput.nextLine();
  19. stGp[i].mark = stInput.nextInt();
  20. stInput.nextLine();
  21. }
  22.  
  23. // average mark
  24. float sum = 0;
  25. for (Student aSt : stGp) {
  26. sum = sum + aSt.mark;
  27. }
  28. float average = sum / num;
  29. System.out.print("The average mark is " + average + "\n");
  30.  
  31. // get the highest mark and name
  32. float highest = stGp[0].mark;
  33. String highestName = "";
  34. for (Student aSt : stGp) {
  35. if (aSt.mark > highest) {
  36. highest = aSt.mark;
  37. highestName = aSt.name;
  38. }
  39. }
  40. System.out.print("The highest mark and student is " + highestName + " " + highest + "\n");
  41.  
  42. // list who above average
  43. System.out.print("Students whose mark scoring above average:\n");
  44. for (Student aSt : stGp) {
  45. if (aSt.mark >= average) {
  46. System.out.print(aSt.name + "\n");
  47. }
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment