repl.it
@egehanasal/

Weekly Calendar

Java

A weekly calendar which will be written to a file.

fork
loading
Files
  • Main.java
  • .metadata
  • .tooling
  • eskiDosya.txt
  • Main.class
  • yeniDosya.txt
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.PrintStream;
import java.io.File;

public class Main {

    public static void main(String[] args) throws FileNotFoundException {

        Scanner console = new Scanner(System.in);
        calendar(console);
        console.close();
    }

    public static boolean calendar(Scanner scanner) throws FileNotFoundException{

        String name;
        String password;
        String toDo = "";
        int numberOfActivities;
        int hour = 0;
        String day;
        int secondComponent = 0;

        File file1 = new File("yeniDosya.txt");
        File file2 = new File("eskiDosya.txt");
        PrintStream printer = new PrintStream(file1);
        PrintStream printer2 = new PrintStream(file2);


        String[][] frame = new String[17][8];
        String[] days = {"", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"};

        System.out.println("Enter your name: ");
        name = scanner.nextLine();
        System.out.println("Enter your password: ");
        password = scanner.nextLine();
        if(!name.equalsIgnoreCase("egehan") || !password.equals("12345")){
            System.out.println("You entered wrong name or password");
            return false;
        }

        System.out.println("How many days?");
        int n = Integer.parseInt(scanner.nextLine());
        while(n > 2){
            System.out.println("You can add your activities on only 2 days at the same time.");
            n = Integer.parseInt(scanner.nextLine());
        }
        for(int i = 0; i < n; i++) {
            System.out.println("To which day do you want to add your job? ");
            day = scanner.nextLine();
            for (int k = 0; k < 7; k++) {
                if (day.equalsIgnoreCase(days[k + 1])) {
                    secondComponent = k + 1;
                }
            }
            System.out.print("How many activities you want to add on " + day.toLowerCase() + ":");
            numberOfActivities = Integer.parseInt(scanner.nextLine());
            for (int f = 0; f < numberOfActivities; f++) {
                System.out.println("Enter what you want to do on " + day.toLowerCase() + ":");
                toDo = scanner.nextLine();
                System.out.println("Enter what time do you want to do: ");
                hour = Integer.parseInt(scanner.nextLine());
                frame[hour - 7][secondComponent] = toDo;
            }
        }

        frame[0][0] = "   ";

        for (int j = 1; j < 17; j++) {
            if(j == 1){
                frame[j+1][0] = "";
            }
            else{
                frame[j][0] = Integer.toString(j + 7);
            }
        }
        for (int i = 0; i < 7; i++) {
            frame[0][i + 1] = days[i + 1];
        }

        for (int i = 0; i < 17; i++) {
            for (int j = 0; j < 8; j++) {
                if (frame[i][j] == null) {
                    frame[i][j] = " ";
                }
                if(i > 0 && j == 1){
                    if (i < 3) {
                        addSpace(2 , file1 , printer);
                    } else {
                        addSpace(1 , file1 , printer);
                    }
                }
                else if (i > 0 && j == 2) {
                    if (i < 3) {
                        addSpace(5 , file1 , printer);
                    } else {
                        addSpace(5 , file1 , printer);
                    }
                }
                else if( i > 0 && j == 3){
                    if (i < 3) {
                        addSpace(6 , file1 , printer);
                    } else {
                        addSpace(6 , file1 , printer);
                    }
                }
                else if(i > 0 && j == 4){
                    if (i < 3) {
                        addSpace(8 , file1 , printer);
                    } else {
                        addSpace(8 , file1 , printer);
                    }
                }
                else if(i > 0 && j == 5){
                    if(frame[i][1] != "") {
                        if (i < 3) {
                            addSpace(8 - (frame[i][1].length()), file1, printer);
                        }
                        else {
                            addSpace(8 - (frame[i][1].length()), file1, printer);
                        }
                    }
                    else if(frame[i][2] != ""){
                        if (i < 3) {
                            addSpace(5, file1, printer);
                        }
                        else {
                            addSpace(0, file1, printer);
                        }
                    }
                    else{
                        if (i < 3) {
                            addSpace(7, file1, printer);
                        }
                        else {
                            addSpace(7, file1, printer);
                        }
                    }
                }
                else if(i > 0 && j == 6){
                    if (i < 3) {
                        addSpace(5 , file1 , printer);
                    } else {
                        addSpace(5 , file1 , printer);
                    }
                }
                else if(i > 0 && j == 7){
                    if (i < 3) {
                        addSpace(7 , file1 , printer);
                    } else {
                        addSpace(7 , file1 , printer);
                    }
                }
                System.out.print(frame[i][j] + "                ");
                printer.print(frame[i][j] + "                ");
            }
            System.out.println();
            printer.println();
        }
        printer2.println(file2);
        return true;
    }

    public static void addSpace(int max , File file , PrintStream printer) throws FileNotFoundException{ ;
        for(int m = 0; m < max; m++){
            System.out.print(" ");
            printer.print(" ");
        }
    }
}
Fetching token
?