Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Question {
- public static void main(String[] args) throws IOException {
- String name = null;
- float mark, total, average, totalAverage = 0;
- int totalNumberOfPeople = 0;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- System.out.println ("This program will calculate the average of five marks for each person.n");
- do {
- total = 0;
- System.out.print("Please enter student name <or enter 'end' to exit> : ");
- try {
- name = br.readLine();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- if(!name.equalsIgnoreCase("end")) {
- totalNumberOfPeople++;
- System.out.println("nPlease enter 5 marks for " + name + ".");
- for(int i=1; i <= 5; i++) {
- System.out.print("Enter mark #" + i + " of 5: ");
- try {
- mark = Float.parseFloat(br.readLine());
- }
- catch(NumberFormatException nfe) {
- mark = 0;
- }
- catch (IOException e) {
- mark = 0;
- }
- total = total + mark;
- }
- average = (float)total / 5;
- System.out.println("nThe average of the 5 marks entered is " + average);
- totalAverage = totalAverage + average;
- System.out.println("============================================================");
- }
- }
- while(!name.equalsIgnoreCase("end"));
- System.out.println("============================================================");
- System.out.println("Total number of people = " + totalNumberOfPeople);
- System.out.println("The overall average for all the people entered = " + totalAverage / totalNumberOfPeople );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement