Advertisement
Guest User

Main

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. /*
  2. Pontus Eklund
  3. poek1067
  4. */
  5.  
  6. import java.util.*;
  7.  
  8. public class Main {
  9.  
  10. private Scanner myScanner = new Scanner(System.in);
  11.  
  12. public static void main(String[] args) {
  13. new Main().run();
  14. }
  15.  
  16. private void run() {
  17. Event eventA = new Event("Marathon", 1);
  18. Participant participantA = new Participant("John", "Smith", "Ireland");
  19. Participant participantB = new Participant("John", "Johnson", "UK");
  20. Team team = new Team(participantA.getTeam());
  21. Team.teams.add(team);
  22. Event.events.add(eventA);
  23. Participant.participantList.add(participantA);
  24. Participant.participantList.add(participantB);
  25.  
  26. boolean bool = true;
  27.  
  28. while (bool) {
  29. System.out.println("Welcome! Please enter your command:");
  30.  
  31. String answer = myScanner.nextLine();
  32.  
  33. switch (answer) {
  34.  
  35. case "add event":
  36. Event.addEvent(myScanner);
  37. break;
  38.  
  39. case "add participant":
  40. Participant.addParticipant(myScanner);
  41. break;
  42.  
  43. case "remove participant":
  44. Participant.removeParticipant(myScanner);
  45. break;
  46.  
  47. case "add result":
  48. Result.addResult(myScanner);
  49. break;
  50.  
  51. case "participant":
  52. Participant.participant(myScanner);
  53. break;
  54.  
  55. case "exit":
  56. System.out.println("Terminating program");
  57. bool = false;
  58. break;
  59.  
  60. default:
  61. if (answer.substring(0,7).equals("message")) {
  62. message(answer);
  63. break;
  64. }
  65. else if (Event.isEvent(answer)) {
  66. Event.eventStanding(answer);
  67. break;
  68. }
  69. else{
  70. System.out.println("Error. Please enter a correct command.");
  71. break;
  72. }
  73. }
  74. }
  75. }
  76.  
  77. private void message(String answer) {
  78. String message = answer.substring(7).toUpperCase();
  79. int height = 5;
  80. int width = 60;
  81. int k = 0;
  82. char [][] matrix = new char[height][width];
  83. for (int i = 0; i < matrix.length; i++) {
  84. for (int j = 0; j < matrix[i].length; j++) {
  85. if (i == 0 || i == matrix.length - 1 || j == matrix[i].length - 1 || j == 0) {
  86. matrix[i][j] = '#';
  87. } else if (j == 1 || j == matrix[i].length - 2) {
  88. matrix[i][j] = ' ';
  89. } else if (i == Math.floor(matrix.length / 2) && j <= message.length() + 1) {
  90. matrix[i][j] = message.charAt(k);
  91. k++;
  92. } else {
  93. matrix[i][j] = ' ';
  94. }
  95. }
  96. }
  97.  
  98. String temp;
  99. for (int i = 0; i < matrix.length; i++) {
  100. temp = new String(matrix[i]);
  101. System.out.println(temp);
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement