subject

The goal of this project is to create a Food Diary. This diary should contain breakfast, lunch, dinner and Snacks that you consume during the day. The user should be able to enter their food items and save it as a csv file. The user should be able to keep appending to the file.

This is what I have so far but I'm not sure where to close my scanner:

import java. io. File;

import java. io. FileNotFoundException;

import java. io. PrintWriter;

import java. util. Scanner;

public class App {

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

PrintWriter pw = new PrintWriter(new File("test. csv"));

StringBuilder sb = new StringBuilder();

sb. append("Date");

sb. append(',');

sb. append("FoodTime");

sb. append(',');

sb. append("FoodItem");

sb. append(',');

sb. append("Calories");

sb. append('\n');

int exit;

do {

Scanner sc = new Scanner(System. in);

System. out. println("Date : ");

String Date = sc. next();

System. out. println("Meal Time: ");

String FoodTime = sc. next();

System. out. println("Food Item : ");

String FoodItem = sc. next();

System. out. println("Calories : ");

String Calories = sc. next();

sb. append(Date);

sb. append(',');

sb. append(FoodTime);

sb. append(',');

sb. append(FoodItem);

sb. append(',');

sb. append(Calories);

sb. append('\n');

pw. write(sb. toString());

System. out. println("Please enter 0 to exit, 1 to continue : ");

exit = sc. nextInt();

} while (exit != 0);

System. out. println("done!");

}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:20
The kurt vonnegut commencement speech, the neiman-marcus chocolate chip cookie recipe, and the get-well emails to the dying boy are examples of select one: a. social engineering b. hoax emails c. email viruses d. worms
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
Annie is creating a corporate report for a company’s annual meeting. in the report, she wants to add the signature of various department heads. which device can annie use to capture signatures to include in the report? a. printer b. monitor c. e-reader d. digitizing tablet
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Pl i need the answer now ! which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
You know the right answer?
The goal of this project is to create a Food Diary. This diary should contain breakfast, lunch, dinn...
Questions
question
Mathematics, 24.07.2021 16:00
question
Mathematics, 24.07.2021 16:00
question
Social Studies, 24.07.2021 16:00
question
Social Studies, 24.07.2021 16:00
question
Chemistry, 24.07.2021 16:00
question
Biology, 24.07.2021 16:00
question
English, 24.07.2021 16:00
Questions on the website: 13722359