repl.it
@vedprad1/

File Management System

Java

No description

fork
loading
Files
  • Main.java
  • File.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    File[] fileDatabase = new File[0];
    File[] temp;
    int reply = 1;
    int terminate;
    int i;
    int j;
    int view;
    int remove;
    String fileName;
    String fileContent;
    String addToFile;
    System.out.println("Hello! Welcome to your file management system.");
    while (reply != 5) {
      System.out.println("Press a number:\n1: Create a new file.\n2: View a file.\n3: Add to a file.\n4: Delete a file.\n5: Exit this program.");
      reply = scan.nextInt();
      if (reply == 1) {
        temp = new File[fileDatabase.length + 1];
        for (i = 0; i < fileDatabase.length; i++){
        temp[i] = fileDatabase[i];
        }
        fileDatabase = temp;
        System.out.println("What would you like to name this file?");
        scan.nextLine();
        fileName = scan.nextLine();
        System.out.println("Write your file. You can edit it later.");
        fileContent = scan.nextLine();
        fileDatabase[fileDatabase.length - 1] = new File(fileName, fileContent);
        fileDatabase[fileDatabase.length - 1].content = fileContent;
      }
      else if (reply == 2) {
        for (i = 0; i < fileDatabase.length; i++) {
          j = i + 1;
          System.out.print(j + ": " + fileDatabase[i].name);
          System.out.println();
        }
        System.out.println("Press the number of the file you want to view.");
        view = scan.nextInt();
        view--;
        System.out.println(fileDatabase[view].content);
      }
      else if (reply == 3) {
        for (i = 0; i < fileDatabase.length; i++) {
          j = i + 1;
          System.out.print(j + ": " + fileDatabase[i].name);
          System.out.println();
        }
        System.out.println("Press the number of the file you want to edit.");
        view = scan.nextInt();
        view--;
        System.out.println(fileDatabase[view].content);
        scan.nextLine();
        addToFile = scan.nextLine();
        fileDatabase[view].content = fileDatabase[view].content 
        + " " + addToFile;
      }
      else if (reply == 4) {
        for (i = 0; i < fileDatabase.length; i++) {
          j = i + 1;
          System.out.print(j + ": " + fileDatabase[i].name);
          System.out.println();
        }
        System.out.println("Press the number of the file you want to delete.");
        remove = scan.nextInt();
        remove--;
        temp = new File[fileDatabase.length - 1];
        for (i = 0; i < remove; i++) {
          temp[i] = fileDatabase[i];
        }
        for (i = remove; i < temp.length; i++) {
          temp[i] = fileDatabase[i+1];
        }
        fileDatabase = temp;
      }
      else {
        System.out.println("Are you sure you want to terminate this program? You will lose all history. Press 1 to terminate, or 2 to continue.");
        terminate = scan.nextInt();
        if (terminate == 2) {
          reply = 1;
        }
        else {
          System.out.println("Repl.it stopping...");
          System.out.println("Repl.it stopped.");
        }
      }
    }
  }
}
?