1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Korolek [52]
2 years ago
7

A store owner keeps a record of daily transactions in a text file. Each line contains three items: The invoice number, the cash

amount, and the letter P if the amount was paid or R if the amount was received. Items on each line are separated by spaces. Wri te a program that prompts the store owner for the amount of cash at the beginning of the day and for the amount of cash at the end of the day, as well as the name of the ledger text file. Your program should calculate if the actual amount of cash at the en d of the day equals the expected value. If an error is found while reading the text file, the user should be allowed to choose another file
Computers and Technology
1 answer:
Alex17521 [72]2 years ago
5 0

Answer:

Answer explained below

Explanation:

Java Program:

package ledger;

import java.util.*;

import java.io.*;

public class Ledger {

   //Main method

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

     

       String fileName;

     

       try

       {

           //Reading file name

           fileName = getFileName();

                 

           //Processing file

           processFile(fileName);

       }

       catch(Exception ex)

       {

           //Reading file name

           fileName = getFileName();

                 

           //Processing file

           processFile(fileName);

       }

     

   }

 

   //Reading file name

   public static String getFileName()

   {

       String fileName;

     

       Scanner sc = new Scanner(System.in);

     

       //Prompting user for file name

       System.out.print("\n\n Enter ledger text file name: ");

     

       //Reading and storing file name

       fileName = sc.nextLine();

     

       return fileName;

   }

 

   //Method that process the file

   public static void processFile(String fileName) throws FileNotFoundException

   {

       //Scanner class object for reading file

       Scanner reader = new Scanner(new File(fileName));

     

       double startingBalance, endingBalance, amount, balance;

       String transactionType, invoiceNum;

     

       //Scanner class object

       Scanner sc = new Scanner(System.in);

     

       //Reading starting balance

       System.out.print("\n Enter Starting Balance: ");

       startingBalance = sc.nextDouble();

     

       //Reading ending balance

       System.out.print("\n Enter Ending Balance: ");

       endingBalance = sc.nextDouble();

     

       //Initiall balance is starting balance

       balance = startingBalance;

     

       //Reading data

       while(reader.hasNext())

       {

           //Reading invoice number

           invoiceNum = reader.next();

         

           //Reading amount

           amount = reader.nextDouble();

         

           //Reading transaction type

           transactionType = reader.next();

         

           //For Paid transactions

           if(transactionType.equalsIgnoreCase("P"))

           {

               balance = balance - amount;

           }

           //For Received transactions

           else

           {

               balance = balance + amount;

           }

       }

     

       System.out.println("\n\n Ledger Balance: " + balance);

     

       //Closing file

       reader.close();

     

       //Comparing ending balance

       if(balance == endingBalance)

       {

           System.out.println("\n Actual amount matches with the expected value.... \n");

       }

       else

       {

           System.out.println("\n Sorry!!! Actual amount doesn't match with the expected value.... \n");

       }

   }

}

You might be interested in
Web-based application software is software that ________.
d1i1m1o1n [39]
Web-based application - this is a special kind of applications that operate in the global Internet via HTTP. The user interacts with the program, usually carried out through the browser.
8 0
3 years ago
On a wireless network use _____ to ensure that only authorized client computers are able to access the wireless network.
grigory [225]

Answer:

That

your answer

MAC address filtering

5 0
2 years ago
Consider the following class interfaces:
o-na [289]

Answer:

class teacher and student I didn't actually read it but I think it is class student

6 0
3 years ago
I need some questions and answers in spreadsheet​
yarga [219]

Answer:

you need to show what you need help with

Explanation:

5 0
2 years ago
2) State True or False. 1. Abacus is an electronic device. 2. ROM is read and writes memory of computer. 3. Header and footer ap
mr_godi [17]

Answer:

1 false

2 false

3 false

4  true

5 false

Explanation:

7 0
2 years ago
Read 2 more answers
Other questions:
  • A password checking system that disallows user passwords that are proper names or words that are normally included in a dictiona
    15·1 answer
  • You have found statistics on the Internet that you would like to use in your speech.
    6·1 answer
  • Which payment type is best if you are trying to sick to a budget?
    15·1 answer
  • A ____ is text and graphics that print at the bottom of every page.
    12·1 answer
  • True or false?
    5·1 answer
  • When should recursion be avoided?
    9·1 answer
  • For this assignment, select one of the organizations with a prominent IT department from the Topic 1 assignment. Once identified
    11·1 answer
  • Need help ASAP <br><br> Thankss + BRAINLIST only for correct answers
    10·1 answer
  • Can able to Computer decide its input by itself? How ?​
    15·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!