Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE FOLLOW DIRECTIONS DO NOT DO ANY ARRAY OR ARRAYLIST I DONT KNOW ALL THESE

ID: 3802094 • Letter: P

Question

PLEASE FOLLOW DIRECTIONS DO NOT DO ANY ARRAY OR ARRAYLIST I DONT KNOW ALL THESE COMPLEX THINGS IN PROGRAMMING

************** MAKE SURE TO FOLOW My SKELETON TO SEE HOW IT NEED TO BE DONE PLEASE ************

-------------------- https://codeshare.io/5vArKl -------------------------

in JAVA JAVA PLEASE JAVA********************* PLEASE READ ******************** please follow instructions and do as asked in JAVA JAVA JAVA JAVA

Assignment Description:

For this assignment, you will write a program that keeps track of your expenses, taking the information from a text file and displaying it back to you. A skeleton of the program is provided to you, which will also contain code relevant to taking data from your text data.

This purpose of this assignment is for you to understand both methods and loops fully; you will also learn how to access data from files and how to manipulate this data in various ways to display the required output. At the end, you will be given a .class file which you can run from the terminal to see the expected output and compare to your own program. We will explain how you can run the .class file this later.

Please read through all of the instructions first, before starting.

When starting the program, the user is given the following choices:

Make a log

View all logs for my previous expenses

View all logs for deposits

View all logs for a month

View Customized logs for a month

View all logs for a day

View Customized logs for a day

View all logs for a previous expenses

View all logs for a previous deposits

View all logs till date

Quit

Each option in this menu will have its own method. If the method is not already provided in the skeleton code, you will need to make it yourself. After the user chooses one option, other than to Quit, the menu will be displayed and the user will get to pick another option. This should continue looping until the user chooses to quit.

Each menu option is described below:

Option A:

For this method, the user will be able to create a log. First, ask the user if he or she would like to log (A) a deposit, or (B) an expense. Based on that choice, they will next be asked to enter a category for that expense/deposit. For example, if one chose option ‘B’, they could then type in ‘food’ as the expense category.

Next, ask for the amount for that expense or deposit. If it was an expense, this amount will be subtracted from the current balance. If it was a deposit, it will be added.

Once the user enters everything, this information must be added to the text file. The program should also automatically determine the current date, as well as the current balance, and save all of this to the text file.

Note that to get and update the current balance, you will need to obtain the last item in the text file. This will probably be taken in as a String, so you must also parse it to convert to an integer. For example:

int number = Integer.ParseInt(someString);

Again, once we have all five variables (date, type, category, amount, and balance), they will be added into the text file in that order and separated by spaces. Finally, display back to the user that a log has been successfully added.

Option B:
The program will read the given text file and print every log where the user has recorded an expense. Make sure to print all the information:

Date

Type (Expense or Deposit)

Category (such as Food, etc…)

Amount

Balance

Option C:

The program will read the given text file and print the logs where the user has recorded a deposit. Make sure to display all the same information as described above in Option B.

Option D:

The program will first ask the user to enter the month he or she would like to look up. Next, read in the given text file and print all the logs where the month recorded is the same as that of the user’s input.

Option E:

This option is like Option D, but more specific. Again, ask the user to enter the month they would like to look up. Next, also ask them to select either “Expenses” or “Deposits.” Finally, ask the user for the deposit or expense category (food, salary, etc.). Once you have all this information, read the given text file and print all the logs that contain only the information that the user has set.

Option F:

Ask the user to enter a specific month and day he or she would like to look up. Next, read in the given text file and print all the logs where that month and day correspond to that which the user inputted.

Option G:

Like option F, ask the user to enter a specific month and day. Then, ask them to also enter whether it was an expense or deposit, as well as the category. Once you have all this information, read the given text file and print all the logs that contain only the information that the user has set.

Option H:

The program will ask the user what type of expense they would like to look up. Provide a menu listing the possible types of expenses they may choose from (such as food, entertainment, etc.). Once the user makes a choice, read the text file and print all the logs based on the inputted type.

Option I:

The program will ask the user what type of deposit they would like to look up. Provide a menu listing the possible types of deposits they may choose from (such as food, entertainment, etc.). Once the user makes a choice, read the text file and print all the logs based on the inputted type.

Option J:

This option will be to print all the logs from the text file.

Based on all this information, complete the code based on the skeleton provided.

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;

/**
*
* @author pankaj
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;  
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Scanner;
import java.time.format.DateTimeFormatter;

public class JavaApplication2 {

  
   public static void readDeposit()
   { try {
        FileReader input = new FileReader("./log.txt");
              BufferedReader bufRead = new BufferedReader(input);
              String myLine = null;
              String[] array1;
              while ( (myLine = bufRead.readLine()) != null)
           {  
                // String[] array1 = myLine.split(":");
  
                  array1 = myLine.split(" ");                                
                 for(int i=0;i<array1.length;i++)
                 {
                     if(array[1]=="NULL")
                        System.out.println(myLine) ;
                 }  
           }
            
            
   }catch (IOException ex) {

               ex.printStackTrace();

           }
   }
    public static void viewLog()
    {
        BufferedReader br = null;
       FileReader fr = null;

       try {

           fr = new FileReader("./log.txt");
           br = new BufferedReader(fr);

           String sCurrentLine;

           br = new BufferedReader(new FileReader("./log.txt"));

           while ((sCurrentLine = br.readLine()) != null) {
               System.out.println(sCurrentLine);
           }

       } catch (IOException e) {

           e.printStackTrace();

       } finally {

           try {

               if (br != null)
                   br.close();

               if (fr != null)
                   fr.close();

           } catch (IOException ex) {

               ex.printStackTrace();

           }

       }
    }
  
  
    public static void makeLog() {
       try {
              DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
              LocalDate localDate = LocalDate.now();
              String date=dtf.format(localDate);
          
          File file = new File("./log.txt");
              String content = "Date Type Category Amount Balance";
            
          if (file.createNewFile()){
            System.out.println("Log file is created!");
             
          }else{
            System.out.println("Log file already exists.");
          }
            
             FileWriter writer = new FileWriter("./log.txt", true);
            BufferedWriter bufferedWriter = new BufferedWriter(writer);

          
        

            bufferedWriter.close();
          
              Scanner userInput = new Scanner(System.in);
              char choice;
              String category="",data="";
              int amount=0;
              System.out.println("Enter A for deposit and B for expense");
              choice =userInput.next().charAt(0);
            
              FileReader input = new FileReader("./log.txt");
              BufferedReader bufRead = new BufferedReader(input);
              String myLine = null;
              int balance;
              String b="";
              String[] array1;
              while ( (myLine = bufRead.readLine()) != null)
           {  
                // String[] array1 = myLine.split(":");
  
                  array1 = myLine.split(" ");                                
      
           }
              b=array1[4];
            
              if(b.isEmpty())
                 balance=0;
              else
                  balance=Integer.parseInt(b);
            
              if(choice=='A')
              {             
                
                  System.out.println("Enter the deposit amount");
                  amount=userInput.nextInt();
                  balance=balance+amount;
                  data=date+" "+"NULL"+" "+"deposit"+" "+String.valueOf(amount)+" "+String.valueOf(balance);
              }  
              else
              {
                  System.out.println("Enter the expense category: ");
                  category=userInput.next();
                  System.out.println("Enter the expense amount");
                  amount=userInput.nextInt();
                  balance=balance-amount;
                  data=date+" "+category+" "+"expense"+" "+String.valueOf(amount)+" "+String.valueOf(balance);
                
              }
              bufferedWriter.write(data);
              bufferedWriter.newLine();
       } catch (IOException e) {
          e.printStackTrace();
   }
   }
  
    public static void main(String[] args) {
   Scanner userInput = new Scanner(System.in);
   int choice;
   int currentBalance;

do
{
//display our menu
System.out.println("*** Expenses***");
System.out.println("1. Make a log ");
System.out.println("2. View all logs for my previous expenses ");
System.out.println("3. View all logs for deposits ");
System.out.println("4. View all logs for a month ");
System.out.println("5. Exit");
System.out.println("**********************");
System.out.println("Please enter your choice:");


choice = userInput.nextInt();


switch(choice)
{
case 1:
        makeLog();
        break;
case 2:
        viewLog();
        break;
case 3:
        readDeposit();
        break;
case 4:
System.out.println("You have chose exit!");
break;
default:
System.out.println("You entered an invalid choice");
}
}while(true);


    }
} // end class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote