Advertisement
PetyoKamenov

Untitled

Jul 22nd, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.Date;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11.  
  12. public class Testtt {
  13. public static void main(String[] args) {
  14. ArrayList<String> ArraynewStudent = new ArrayList<String>();
  15. Scanner input = new Scanner(System.in);
  16. boolean endprogram = false;
  17. while (!endprogram) {
  18. System.out.println("Choice you student status : ");
  19. System.out.println("Press 1 for new student ");
  20. System.out.println("Press 2 for existing student: ");
  21. System.out
  22. .println("Press 3 to upload document, certificate or picture: ");
  23. System.out.println("Press 4 to exit program: ");
  24. System.out.println("Press 5 to write student to file: ");
  25. int studentChoice = input.nextInt();
  26. switch (studentChoice) {
  27.  
  28. case 1:
  29. NewStudent(ArraynewStudent);
  30. break;
  31. case 2:
  32. ActualStudent();
  33. break;
  34. case 3:
  35. StudentsAndCertificate();
  36. break;
  37. case 4:
  38. endprogram = true;
  39. break;
  40. case 5:
  41. writeStudent("textDataBase\\NewStudent.txt", ArraynewStudent);
  42. break;
  43. case 6:
  44. readFile();
  45. break;
  46. }
  47. }
  48. }
  49.  
  50. public static void NewStudent(ArrayList<String> ArrayNewStudent) {
  51. Scanner input = new Scanner(System.in);
  52. //
  53. Date studentDate = new Date();
  54. System.out.print("Enter your names : ");
  55. String studentNames = input.nextLine();
  56. System.out.print("Enter your EGN number : ");
  57. String studentEGN = input.nextLine();
  58. System.out.print("Enter your ID number : ");
  59. String studentId = input.nextLine();
  60. ArrayNewStudent.add(studentNames);
  61. ArrayNewStudent.add(studentId);
  62. ArrayNewStudent.add(studentEGN);
  63. ArrayNewStudent.add(studentDate.toString());
  64. for (String newStudent : ArrayNewStudent) {
  65. System.out.println(newStudent);
  66. }
  67. System.out.println();
  68. }
  69.  
  70. public static void ImportCertificate() {
  71. // качване на сертификат
  72. }
  73.  
  74. public static void ImportPicture() {
  75. // Добавяне .jpeg
  76. }
  77.  
  78. public static void ActualStudent() {
  79. // добавяне :
  80. String[] actualStudent = { "Names : Petar Plamenov Kamenov",
  81. "Student ID : 90024242403", "University Number : 09091044 :" };
  82. String[] StudentPayment = { " " };
  83. SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
  84. Date date = new Date();
  85. String StudentEndEducation = "12-09-2016";
  86. Date End = null;
  87. try {
  88. End = format.parse(StudentEndEducation);
  89.  
  90. } catch (ParseException e) {
  91. e.printStackTrace();
  92. }
  93. boolean IsEnded = date.after(End);
  94. if (IsEnded) {
  95. System.out.println("Student is not Active: ");
  96. } else {
  97. System.out.println("Student is Active: ");
  98. }
  99. for (String actStudent : actualStudent) {
  100. System.out.println(actStudent);
  101. }
  102. }
  103.  
  104. public static void StudentsAndExams() {
  105. // опция за признаване на изпит поради издържани майстоски класове
  106. }
  107.  
  108. public static void StudentsAndCertificate() {
  109. // прехвърляне в метода StudentsAndExams(); и признаване на изпитите
  110. }
  111.  
  112. public static void readFile() {
  113. // Link the File variable to a file on the computer
  114. File file = new File("NewStudent.txt");
  115.  
  116. // Next line may throw an exception!
  117. Scanner fileReader = new Scanner("textDataBase\\NewStudent.txt");
  118.  
  119. int lineNumber = 0;
  120.  
  121. // Read file
  122. while (fileReader.hasNextLine()) {
  123. lineNumber++;
  124. System.out.printf("Line %d: %s%n", lineNumber,
  125. fileReader.nextLine());
  126. }
  127.  
  128. fileReader.close();
  129. }
  130.  
  131. public static void writeStudent(String fileName,
  132. ArrayList<String> ArrayOfStudents) {
  133. try {
  134. PrintWriter writer = new PrintWriter(new BufferedWriter(
  135. new FileWriter(fileName, true)));
  136. String[] simpleStrArray = new String[ArrayOfStudents.size()];
  137. simpleStrArray = ArrayOfStudents.toArray(simpleStrArray);
  138. for (int i = 0; i < ArrayOfStudents.size(); i++) {
  139. writer.println(simpleStrArray[i]);
  140. }
  141. writer.close();
  142. } catch (IOException e) {
  143. e.printStackTrace();
  144. }
  145.  
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement