Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class ControleAlimentacao {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Digite o número de dias do mês: ");
int numeroDiasMes = scanner.nextInt();
int[] quantidadeCafeDiaria = new int[numeroDiasMes];
int[] quantidadeAlmocoDiaria = new int[numeroDiasMes];
for (int dia = 1; dia <= numeroDiasMes; dia++) {
System.out.print("Digite a quantidade de café para o dia " + dia + ": ");
quantidadeCafeDiaria[dia - 1] = scanner.nextInt();
System.out.print("Digite a quantidade de almoço para o dia " + dia + ": ");
quantidadeAlmocoDiaria[dia - 1] = scanner.nextInt();
}
System.out.print("Digite o valor unitário do café: ");
double valorUnitarioCafe = scanner.nextDouble();
System.out.print("Digite o valor unitário do almoço: ");
double valorUnitarioAlmoco = scanner.nextDouble();
double totalCafe = calcularTotal(quantidadeCafeDiaria, valorUnitarioCafe);
double totalAlmoco = calcularTotal(quantidadeAlmocoDiaria, valorUnitarioAlmoco);
double totalGeral = totalCafe + totalAlmoco;
// Salva o relatório em um arquivo de texto
try (PrintWriter writer = new PrintWriter(new FileWriter("relatorio_alimentacao.txt"))) {
writer.println("Relatório de Alimentação");
writer.println("------------------------");
writer.println("Número de dias do mês: " + numeroDiasMes);
for (int dia = 1; dia <= numeroDiasMes; dia++) {
writer.println("Dia " + dia + ":");
writer.println("Quantidade de café: " + quantidadeCafeDiaria[dia - 1]);
writer.println("Quantidade de almoço: " + quantidadeAlmocoDiaria[dia - 1]);
}
writer.println("Valor unitário do café: " + valorUnitarioCafe);
writer.println("Valor unitário do almoço: " + valorUnitarioAlmoco);
writer.println("Total gasto com café: " + totalCafe);
writer.println("Total gasto com almoço: " + totalAlmoco);
writer.println("Total geral: " + totalGeral);
System.out.println("Relatório salvo com sucesso no arquivo relatorio_alimentacao.txt!");
} catch (IOException e) {
System.out.println("Erro ao salvar o relatório: " + e.getMessage());
}
scanner.close();
}
private static double calcularTotal(int[] quantidadeDiaria, double valorUnitario) {
double total = 0;
for (int quantidade : quantidadeDiaria) {
total += quantidade * valorUnitario;
}
return total;
}
}
Agora, o código solicitará a quantidade de café e almoço para cada dia do mês, conforme solicitado. Ele armazenará essas informações em arrays separados e calculará o total gasto com café, o total gasto com almoço e o total geral. O relatório detalhado será salvo no arquivo de texto "relatorio_alimentacao.txt".
Espero que isso atenda às suas necessidades! Se você tiver mais perguntas, fique à vontade para perguntar.
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team