Question: import java.io.BufferedWriter; import java.io.FileWriter; import java.text.DecimalFormat; import java.util.Date; import java.util.Scanner; public class ExpenseAccount { public static void main(String[] args) throws Exception { // TODO Auto-generated

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.text.DecimalFormat;

import java.util.Date;

import java.util.Scanner;

public class ExpenseAccount {

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

// TODO Auto-generated method stub

System.out.println("NAME 2023");

System.out.println("Welcome to the ExpenseAccount program! Run this program to accumulate the expenses for a given activity, like");

System.out.println("the business trip to L.A. Then run the program again to accumulate the expenses for the business trip to New York.");

System.out.println("The expenses for each trip/activity are kept in a separate text disk file that you will name.");

System.out.println("Each expense item is entered on a separate line. e.g. $12.47 for Tuesday lunch");

System.out.println("A leading $ sign is optional, then expense amount, then ' for ' (no quotes) and then a brief description.");

System.out.println("An expense amount must contain a decimal point followed by two decimal digits.");

System.out.println("Each entered expense is added to the accumulating total expenses amount.");

System.out.println("Enter EXIT to end the program and to show the total expenses and to write the log file on the disk.");

System.out.println("");

Scanner scanner = new Scanner(System.in);

DecimalFormat df = new DecimalFormat(("0.00"));

double totalExpenses = 0;

double expenseAmount = 0;

String expenseAmountAsString = null;

String expenseDescription = null;

String expenseEntryLine = null;

String fileName;

while(true) // let user specify a unique file name for this activity's expenses

{

System.out.println("To begin, enter the name of the disk text file (no blanks, periods or slashes) to hold the expenses for this activity. (e.g. TripToLA2023)");

fileName = scanner.nextLine().trim(); // wait for user entry

if (fileName.equalsIgnoreCase("EXIT")) return;

if ((fileName.length() != 0) && !fileName.contains(".") && !fileName.contains(" ") && !fileName.contains("\\") && !fileName.contains(" /"))

break;

}

FileWriter fw = new FileWriter(fileName + ".txt");

BufferedWriter bw = new BufferedWriter(fw);

bw.write("Expenses for " + fileName + " recorded " + new Date());

bw.newLine(); // need to do this after EVERY line written to log file!

while(true) // "do forever" // main program loop

{

System.out.println("");

System.out.println("Enter an expense line or EXIT.");

expenseEntryLine = scanner.nextLine().trim(); // remove blanks

if (expenseEntryLine.equalsIgnoreCase("EXIT")) break; // exit loop

int forOffset = expenseEntryLine.indexOf(" for ");

JAVA PROGRAM: EXPENSEACCOUNT

I'm having issues with the log files not containing any information collected by user. The file is created, but when it's opened, there's no information on it.

PLEASE HELP SOLVE THIS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!