Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Question: Instructions: The goal of this project is to create a Food Diary. This diary should contain breakfast, lunch, dinner and Snacks that you

Java Question:

Instructions:

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(' ');

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(' ');

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

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

Students also viewed these Databases questions

Question

2 The role of economic theory in economics.

Answered: 1 week ago