1
good night!
I need that even if it reaches the condition total_min < 720
He keeps going through the lines. The 720 are the total minutes before lunch, when reached should separates the activities to be performed after lunch.
- I need to make a system that reads a TXT(intput.txt file).
- This file has several lines.
- Each line an activity with run 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 as it should be the output.txt file
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:
static int i = 0;
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 nomePc = System.getProperty("user.name");
String path = "\\input.txt";
String outputDir = "\\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 < 720) {
total_min += 60;
antes_almoco.add(linha);
}
if (trinta_min == true && total_min < 720) {
total_min += 30;
antes_almoco.add(linha);
}
if (quarentaCinco_min == true && total_min < 720) {
total_min += 45;
antes_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();
}
Now the null test on
if
became unnecessary kkk.– Piovezan
Thanks @Piovezan! Removed and worked. Can help me with the rest of the code?
– Ronison Matos
Your question is not clear. It looks like this: "Read my code and help me with logic". Be more specific in what you want. Detail better.
– Piovezan
I need that even if it reaches the condition
total_min < 720
He keeps going through the lines. The 720 are the total of minutes before lunch, when reached should separates the activities that are to be performed after lunch. I’m sorry, I’m a beginner and I couldn’t think of another way to do it :(– Ronison Matos
No problem. Edit the question by putting this detail into it.
– Piovezan