Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. /**
  6. * The DisplayDocuments class is responsible for displaying tests and surveys
  7. * to the console screen for selecting and viewing.
  8. * @author Tom Rottinger
  9. *
  10. */
  11. public class DisplayDocuments {
  12.  
  13. /**
  14. * displaySurveys does exactly what its name entails - it provides the
  15. * user with a list of surveys that are able to be displayed and, upon
  16. * user selection, displays the survey.
  17. * @throws IOException - in case of any bad input.
  18. */
  19. public static void displaySurveys() throws IOException
  20. {
  21. /** The selected survey, displayed at the end of the method. */
  22. Survey selectedSurvey;
  23.  
  24. /** The reader used to get user input on which survey to display. */
  25. BufferedReader displayReader;
  26.  
  27. /** The number indicating which survey the user selected. */
  28. int userSurveyChoice;
  29.  
  30. /** User input, parsed into a number for selecting a survey. */
  31. String displayReaderEntry;
  32.  
  33. displayReader = new BufferedReader(new InputStreamReader(System.in));
  34.  
  35. System.out.println("Which survey would you like to display?");
  36.  
  37. /** Display all surveys in memory. */
  38. for (int i = 1; i <= SurveyTestSystem.surveyList.size(); i++)
  39. {
  40. System.out.println(i + ".) " + SurveyTestSystem.surveyList.get(i-1).documentName);
  41. }
  42.  
  43. /** Until a valid input is chosen, always wait for a valid input... */
  44. while (true)
  45. {
  46. displayReaderEntry = displayReader.readLine();
  47.  
  48. try
  49. {
  50. userSurveyChoice = Integer.parseInt(displayReaderEntry);
  51. if (userSurveyChoice < 1 || userSurveyChoice > SurveyTestSystem.surveyList.size())
  52. {
  53. System.out.println("Please select a number from the list above.");
  54. }
  55. else break;
  56. }
  57. catch (Exception e)
  58. {
  59. }
  60. }
  61.  
  62. /** Finally, display the selected survey. */
  63. selectedSurvey = SurveyTestSystem.surveyList.get(userSurveyChoice - 1);
  64. selectedSurvey.display();
  65. }
  66.  
  67. public static void displayTests()
  68. {
  69. System.out.println("Feature coming soon!");
  70. }
  71.  
  72. }
Add Comment
Please, Sign In to add comment