Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.io.*;
  2. public class Question {
  3. public static void main(String[] args) throws IOException {
  4. String name = null;
  5. float mark, total, average, totalAverage = 0;
  6. int totalNumberOfPeople = 0;
  7. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  8. System.out.println ("This program will calculate the average of five marks for each person.n");
  9.  
  10. do {
  11. total = 0;
  12. System.out.print("Please enter student name <or enter 'end' to exit> : ");
  13.  
  14. try {
  15. name = br.readLine();
  16. }
  17. catch (IOException e) {
  18. e.printStackTrace();
  19. }
  20.  
  21. if(!name.equalsIgnoreCase("end")) {
  22. totalNumberOfPeople++;
  23. System.out.println("nPlease enter 5 marks for " + name + ".");
  24.  
  25.  
  26. for(int i=1; i <= 5; i++) {
  27. System.out.print("Enter mark #" + i + " of 5: ");
  28. try {
  29. mark = Float.parseFloat(br.readLine());
  30. }
  31. catch(NumberFormatException nfe) {
  32. mark = 0;
  33. }
  34. catch (IOException e) {
  35. mark = 0;
  36. }
  37. total = total + mark;
  38. }
  39.  
  40.  
  41. average = (float)total / 5;
  42. System.out.println("nThe average of the 5 marks entered is " + average);
  43. totalAverage = totalAverage + average;
  44. System.out.println("============================================================");
  45. }
  46. }
  47.  
  48. while(!name.equalsIgnoreCase("end"));
  49.  
  50. System.out.println("============================================================");
  51. System.out.println("Total number of people = " + totalNumberOfPeople);
  52. System.out.println("The overall average for all the people entered = " + totalAverage / totalNumberOfPeople );
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement