SHARE
TWEET

Untitled

a guest Sep 17th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.Map;
  3. import java.util.HashMap;
  4. import java.util.Set;
  5.  
  6. /**
  7.  * A program to add, remove, modify or print
  8.  * student names and grades.
  9. */
  10. public class Gradebook
  11. {
  12.     public static void main(String[] args)
  13.     {
  14.         Scanner in = new Scanner(System.in);
  15.  
  16.         Map<String,String>yes = new HashMap<>();
  17.  
  18.         boolean done = false;
  19.         while(!done)
  20.         {
  21.             System.out.println("A)dd R)emove M)odify P)rint Q)uit");
  22.             String input = in.next().toUpperCase();
  23.             if (input.equals("Q"))
  24.             {
  25.                 done = true;
  26.             } else if (input.equals("A"))
  27.             {
  28.                 String name = in.next();
  29.                 String grade = in.next();
  30.                 yes.put(name,grade);
  31.  
  32.             } else if (input.equals("R"))
  33.             {
  34.                 String name = in.next();
  35.                 yes.remove(name);
  36.             } else if (input.equals("M"))
  37.             {
  38.                 String name = in.next();
  39.                 String grade = in.next();
  40.                 yes.replace(name,grade);
  41.             } else if (input.equalsIgnoreCase("P"))
  42.             {
  43.                 Set<String>keys = yes.keySet();
  44.                 for(String key:keys){
  45.                     System.out.println(key+": "+yes.get(key));
  46.                 }
  47.  
  48.             } else
  49.             {
  50.                 done = true;
  51.             }
  52.         }
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top