Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package adrianmom;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- /**
- *
- * @author Archer
- */
- public class AdrianMom {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Map<String, Double> students = new HashMap<>();
- boolean running = true;
- Scanner scan = new Scanner(System.in);
- while(running){
- String name;
- double grade;
- System.out.print("Please enter student name: ");
- name = scan.nextLine();
- System.out.print("Please enter student grade: ");
- grade = scan.nextDouble();
- students.put(name, grade);
- System.out.print("Add more students? 1 for yes, any other number for no: ");
- int proceed;
- proceed = scan.nextInt();
- if(!(proceed == 1)){
- running = false;
- }
- scan.nextLine();
- }
- /**
- * Calculates the average class test grade
- */
- double gradeTotal = 0;
- double highestGrade = Double.MIN_VALUE;
- for (Double grade : students.values()) {
- gradeTotal += grade;
- if(grade > highestGrade)
- highestGrade = grade;
- }
- double classAverage = gradeTotal/students.size();
- ArrayList<String> studentsBelowAvg = new ArrayList<>();
- ArrayList<String> studentsHighestTest = new ArrayList<>();
- /**
- * Runs through hash map entries, finding the students
- * with the highest test grade and below average test grades
- */
- for (Map.Entry entry : students.entrySet()) {
- String key = (String)entry.getKey();
- Double value = (Double)entry.getValue();
- if(value < classAverage)
- studentsBelowAvg.add(key);
- if(value == highestGrade)
- studentsHighestTest.add(key);
- }
- /**
- * Prints out student data extracted from the arrayLists
- */
- System.out.println("Class Average: " + classAverage + "%");
- System.out.println("Students with below average test grades:");
- for(String studentName : studentsBelowAvg){
- System.out.println(studentName);
- }
- System.out.println("Next time study for the test!");
- System.out.println("");
- System.out.println("Students with the highest test grade:");
- for(String studentName : studentsHighestTest){
- System.out.println(studentName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement