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. Here is what I have so far When I write my variables f and t to excel they are in the same cell how can I make it so they are in separate columns
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class App {
public static void main(String[] args) {
BufferedWriter bw = null;
FileWriter fw = null;
FileOutputStream FileName = new FileOutputStream( "MyFooDiary.csv");
System.out.println("Welcome to your food diary");
System.out.println("What is the name of your Food?");
Scanner x = new Scanner(System.in);
String f = x.nextLine();
System.out.println("Was this breakfast, lunch, dinner, or a snack");
Scanner y = new Scanner(System.in);
String t = y.nextLine();
try {
File file = new File(FileName);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
// true = append file
fw = new FileWriter(file.getAbsoluteFile(), true);
bw = new BufferedWriter(fw);
bw.write("Date, Food Time, Food Name, Calories, Carbohydrates,
Sugars, Fiber, Protein, Total Fat ");
bw.write(t);
bw.write(f);;
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} }