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]
3 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]3 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
Directions: pick the right letter for each number.
Ede4ka [16]

1. Upgrading RAM increases run speed.

2. Upgrading Hard Drive increases memory.

3. Adding more ROM to it..?

8 0
3 years ago
Read 2 more answers
If I use google incognito mode or a throwaway google account can my search history be tracked by Microsoft parental controls?
3241004551 [841]

nu it would not but if they call microsoft to check it then yez the history would show up for them but dont try to make it notice able so they dont have to call

6 0
3 years ago
A laptop computer communicates with a router wirelessly, by means of radio signals. the router is connected by cable directly to
Hoochie [10]
The answer would be 2500 Bits
4 0
3 years ago
what's the best mouse for fast clicking ? I play a lot of fps and a lot of pvp games I need a mouse that I can click fast with a
kondaur [170]
Alenware hp dell logtech, and i know others
7 0
3 years ago
What's a big question or problem in the tech field you'd like to solve and why?
aleksandrvk [35]

A big question or problem in the tech field that i would like to solve is Data security.

<h3>What is Data security ?</h3>

Data security  can be regarded as process of protecting data from unauthorized user as well as protection from  data corruption .

I will like to solve this problem because as advances in technology, the data of individual or organization is not been total secured and this is posing so much loss to individuals.

Data security are;

  • data encryption
  • hashing
  • tokenization

Learn more about Data security at;

brainly.com/question/17493537

5 0
2 years ago
Other questions:
  • Your new home has a vacuum system. what kind of computer is controlling it?
    5·1 answer
  • Okay so, not really a question but whatever it’s been bothering me.
    9·2 answers
  • What systemctl command configures a unit to start the next time the computer boots?
    10·1 answer
  • What are some of the potential sources of risk in a systems analysis and design project? How does the project manager cope with
    6·1 answer
  • Hackers who gain control over several computers can organize them into a client-server network known as a(n) __________ . This n
    7·1 answer
  • Define Class in C++. Briefly discuss.
    9·1 answer
  • Jim wants to buy a car, but he’ll probably only need it for a couple of years. He has a short commute to work, so he won’t be pu
    10·1 answer
  • ____________ is a script or a tool that obtains privileges of a root
    8·1 answer
  • In two to three sentences, define "home row" and explain why it is important.
    6·2 answers
  • Koi jinda hei kya hello​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!