Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class LookSc {
  4. public static void main(String [] args) throws FileNotFoundException{
  5. Scanner sc = new Scanner (System.in);
  6. String lookupString = constructLookUpStringFromFile("/Users/puvitpracharktam/IdeaProjects/pondspective/src/score.csv");
  7. boolean toQuit = false;
  8. do{
  9. char choice = showMainMenu();
  10. switch choice{
  11. case 'L':
  12. commenceLookUpProcedure(lookupString);
  13. break;
  14. case 'Q':
  15. toQuit = true;
  16. break;
  17. default:
  18. System.out.println("Invalid choice. Quitting.");
  19. toQuit = true;
  20. }
  21. }while(!toQuit);
  22. }
  23.  
  24. public static String constructLookUpStringFromFile(String f) throws FileNotFoundException{{
  25. Scanner sc = new Scanner(new File(f));
  26. sc.useDelimiter(",|\\n");
  27. return sc.next();
  28. }
  29. public static void commenceLookUpProcedure(String table){
  30. Scanner sc = new Scanner(System.in);
  31. System.out.print("Enter Student ID : ");
  32. String id = sc.next();
  33. String data = table.substring(table.indexOf("\n"));
  34. if (data.indexOf(id)>=0)
  35. showScore(table, id);
  36. else
  37. System.out.println("Student ID \'"+id+"\' not found in data.");
  38. }
  39.  
  40.  
  41.  
  42. }
  43. public static char showMainMenu(Scanner sc)) {
  44. System.out.println("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐");
  45. System.out.println("Main Menu");
  46. System.out.println("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐");
  47. System.out.println("L) Look up score");
  48. System.out.println("Q) Quit");
  49. System.out.println("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐");
  50. System.out.print(">> ");
  51. char n = sc.next().charAt(0);
  52. return n;
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement