Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner reader = new Scanner(System.in);
- System.out.println("Welcome to the Exam Histogram program by Henry Yates.");
- System.out.println("Please enter 0-100 for the marks and enter -1 to complete data entry");
- int total = 0, count = 0;
- double average = 0.0;
- int marks = 0;
- int BotMarks = 0;
- int LowMarks = 0;
- int MedMarks = 0;
- int HighMarks = 0;
- int Highest = 0;
- int Lowest = 1000;
- int MarksEntered = 0;
- while (marks != -1) {
- try {
- marks = reader.nextInt();
- } catch (InputMismatchException e) {
- marks = 1000;
- continue;
- }
- while (marks < -1 || marks > 100) {
- if (marks == -1) {
- total++;
- count=count-1;
- } else {
- System.out.println("Invalid input please enter 0-100");
- marks = reader.nextInt();
- }
- }
- total = total + marks;
- count++;
- //total++;
- if (marks > Highest) {
- Highest = marks;
- }
- if (marks < Lowest && marks >= 0) {
- Lowest = marks;
- }
- if (marks != -1) {
- MarksEntered++;
- }
- if (marks <= 100 && marks >= 70) {
- HighMarks++;
- } else if (marks <= 69 && marks >= 40) {
- MedMarks++;
- } else if (marks <= 39 && marks >= 30) {
- LowMarks++;
- } else if (marks >= 29 || marks == 0 || marks >= 1) {
- BotMarks++;
- }
- } // end of main while loop
- System.out.print("70-100: ");
- for (int a = 0; a < HighMarks; a++) {
- System.out.print("*");
- }
- System.out.println("");
- System.out.print("40-69 : ");
- for (int a = 0; a < MedMarks; a++) {
- System.out.print("*");
- }
- System.out.println("");
- System.out.print("30-39 : ");
- for (int a = 0; a < LowMarks; a++) {
- System.out.print("*");
- }
- System.out.println(" ");
- System.out.print("0-29 : ");
- for (int a = 0; a < BotMarks; a++) {
- System.out.print("*");
- }
- System.out.println("");
- int StudentsPass = 0;
- count=count-1;
- total++;
- average = (total / count);
- StudentsPass = MedMarks + HighMarks;
- System.out.println("The amount of students who passed are " + StudentsPass);
- System.out.println("The Lowest Mark is: " + Lowest);
- System.out.println("The Highest Mark is: " + Highest);
- System.out.println("The Average Mark is: " + average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement