Computers and Technology

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!");

}

}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:40, broang23
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
image
Computers and Technology, 23.06.2019 12:40, Emilyvite6251
According to the video what are some tasks petroleum engineers perform check all that apply
Answers: 2
image
Computers and Technology, 24.06.2019 12:10, breezer20042
What is it called during the editing process when the processor ensures that a character holding a coffee mug from one angle is holding the same mug in the same way when the shot switches to another camera at another angle? cinematography continuity technology prop use
Answers: 1
image
Computers and Technology, 24.06.2019 21:30, Xghoued2056
Aobject is used for displaying the results of a question based on stored data. a. query b. report c. table d. form
Answers: 2
Do you know the correct answer?
The goal of this project is to create a Food Diary. This diary should contain breakfast, lunch, dinn...

Questions in other subjects:

Konu
History, 05.05.2020 12:56