Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Date;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- public class Testtt {
- public static void main(String[] args) {
- ArrayList<String> ArraynewStudent = new ArrayList<String>();
- Scanner input = new Scanner(System.in);
- boolean endprogram = false;
- while (!endprogram) {
- System.out.println("Choice you student status : ");
- System.out.println("Press 1 for new student ");
- System.out.println("Press 2 for existing student: ");
- System.out
- .println("Press 3 to upload document, certificate or picture: ");
- System.out.println("Press 4 to exit program: ");
- System.out.println("Press 5 to write student to file: ");
- int studentChoice = input.nextInt();
- switch (studentChoice) {
- case 1:
- NewStudent(ArraynewStudent);
- break;
- case 2:
- ActualStudent();
- break;
- case 3:
- StudentsAndCertificate();
- break;
- case 4:
- endprogram = true;
- break;
- case 5:
- writeStudent("textDataBase\\NewStudent.txt", ArraynewStudent);
- break;
- case 6:
- readFile();
- break;
- }
- }
- }
- public static void NewStudent(ArrayList<String> ArrayNewStudent) {
- Scanner input = new Scanner(System.in);
- //
- Date studentDate = new Date();
- System.out.print("Enter your names : ");
- String studentNames = input.nextLine();
- System.out.print("Enter your EGN number : ");
- String studentEGN = input.nextLine();
- System.out.print("Enter your ID number : ");
- String studentId = input.nextLine();
- ArrayNewStudent.add(studentNames);
- ArrayNewStudent.add(studentId);
- ArrayNewStudent.add(studentEGN);
- ArrayNewStudent.add(studentDate.toString());
- for (String newStudent : ArrayNewStudent) {
- System.out.println(newStudent);
- }
- System.out.println();
- }
- public static void ImportCertificate() {
- // качване на сертификат
- }
- public static void ImportPicture() {
- // Добавяне .jpeg
- }
- public static void ActualStudent() {
- // добавяне :
- String[] actualStudent = { "Names : Petar Plamenov Kamenov",
- "Student ID : 90024242403", "University Number : 09091044 :" };
- String[] StudentPayment = { " " };
- SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
- Date date = new Date();
- String StudentEndEducation = "12-09-2016";
- Date End = null;
- try {
- End = format.parse(StudentEndEducation);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- boolean IsEnded = date.after(End);
- if (IsEnded) {
- System.out.println("Student is not Active: ");
- } else {
- System.out.println("Student is Active: ");
- }
- for (String actStudent : actualStudent) {
- System.out.println(actStudent);
- }
- }
- public static void StudentsAndExams() {
- // опция за признаване на изпит поради издържани майстоски класове
- }
- public static void StudentsAndCertificate() {
- // прехвърляне в метода StudentsAndExams(); и признаване на изпитите
- }
- public static void readFile() {
- // Link the File variable to a file on the computer
- File file = new File("NewStudent.txt");
- // Next line may throw an exception!
- Scanner fileReader = new Scanner("textDataBase\\NewStudent.txt");
- int lineNumber = 0;
- // Read file
- while (fileReader.hasNextLine()) {
- lineNumber++;
- System.out.printf("Line %d: %s%n", lineNumber,
- fileReader.nextLine());
- }
- fileReader.close();
- }
- public static void writeStudent(String fileName,
- ArrayList<String> ArrayOfStudents) {
- try {
- PrintWriter writer = new PrintWriter(new BufferedWriter(
- new FileWriter(fileName, true)));
- String[] simpleStrArray = new String[ArrayOfStudents.size()];
- simpleStrArray = ArrayOfStudents.toArray(simpleStrArray);
- for (int i = 0; i < ArrayOfStudents.size(); i++) {
- writer.println(simpleStrArray[i]);
- }
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement