Doubts in logic to generate the output file according to the example I need that even if he reaches the total_min <720 condition he continues to travel the lines. 720 is the total number of minutes before lunch, when reached, it should separate the activities that should be performed after lunch (lunch must be inserted manually).
- I need to make a system that reads a TXT file (intput.txt).
- This file has several lines.
- Each line an activity with execution time (30min, 45min, 60min)
- Activities should start at 9 am.
- Half day (12:00) lunch break
- Generate a TXT with organized activities (output.txt)
intput.txt
Correr 60min
Estudar 30min
Ler 45min
Escrever 60min
Caminhar 45min
Jogar 30min
Example how the output.txt file should look
09:00 Correr 60min
10:00 Estudar 30min
10:30 Ler 45min
11:15 Caminhar 45min
12:00 Almoço 60min
13:00 Jogar
(...)
My code:
public static void main(String[] args) throws IOException {
// TODO code application logic here
ArrayList<String> antes_almoco = new ArrayList<String>();
ArrayList<String> depois_almoco = new ArrayList<String>();
int total_min = 540;
int horas = total_min / 60;
int minutos = total_min % 60;
String trinta = "30min";
String quarentaCinco = "45min";
String sessenta = "60min";
boolean trinta_min = false;
boolean quarentaCinco_min = false;
boolean sessenta_min = false;
String path = "C:\\input.txt";
String outputDir = "C:\\output.txt";
FileReader arq = new FileReader(path);
BufferedReader lerArq = new BufferedReader(arq);
String linha;
//Output
File file2 = new File(outputDir);
FileWriter arq_output = new FileWriter(file2, true);
PrintWriter gravarArq = new PrintWriter(arq_output);
if (!file2.exists()) {
file2.createNewFile();
}
while ((linha = lerArq.readLine()) != null) {
trinta_min = linha.toLowerCase().contains(trinta.toLowerCase());
quarentaCinco_min = linha.toLowerCase().contains(quarentaCinco.toLowerCase());
sessenta_min = linha.toLowerCase().contains(sessenta.toLowerCase());
if (sessenta_min == true) {
total_min += 60;
if (total_min < 720) {
antes_almoco.add(linha);
} else if (total_min > 720) {
depois_almoco.add(linha);
}
}
if (trinta_min == true && total_min < 720) {
total_min += 30;
if (total_min < 720) {
antes_almoco.add(linha);
} else if (total_min > 720) {
depois_almoco.add(linha);
}
}
if (quarentaCinco_min == true && total_min < 720) {
total_min += 45;
if (total_min < 720) {
antes_almoco.add(linha);
} else if (total_min > 720) {
depois_almoco.add(linha);
}
}
if (total_min == 720) {
total_min += 60;
antes_almoco.add("12:00 Almoço");
}
}
for (String cont : antes_almoco) {
System.out.println(cont);
gravarArq.printf("%d:%02d %s \n", horas, minutos, cont);
}
for (String cont : depois_almoco) {
//System.out.println(cont);
gravarArq.printf("%d:%02d %s \n", horas, minutos, cont);
}
lerArq.close();
gravarArq.close();
arq.close();
}
lunch must be inserted manually
I hate the vision of being machine (force) fed.) \$\endgroup\$ – greybeard May 16 '20 at 5:31720 is the total number of minutes
&start at 9 am. Half day (12:00) lunch break
is that working surprisingly short minutes, or looong hours?) \$\endgroup\$ – greybeard May 16 '20 at 5:36lunch inserted manually
norhoras
orminutos
computed/updated: I don't see how this can possibly work: off topic at CodeReview@SE. \$\endgroup\$ – greybeard May 16 '20 at 5:46