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
A circuit has a resistance of 300 ohm and a current of 0.024 A. What is the voltage in the circuit?
fomenos
**Formula

If u want to calculate voltage:
Current x Resistance

so the answer is D

Current:
Voltage ÷ Resistance

Resistance:
Voltage ÷ Current
7 0
3 years ago
Which part of the cryosphere comes directly from the atmosphere?
marin [14]
The answer to this question is C.
4 0
3 years ago
Read 2 more answers
Routines will depend on the ______________________ and is found in every program you write.
kari74 [83]

Answer:

Open an application (Word, PowerPoint, etc.) and create a new file like you normally would. ...

Click File.

Click Save as.

Select Box as the location where you'd like to save your file. If you have a particular folder that you'd like to save it to, select it.

Name your file.

Click Save.

Explanation:

3 0
3 years ago
How can you use the cash envelop system and the 50-30-20 rule at the same time
Amanda [17]

Answer:

hi

Explanation:

6 0
3 years ago
Can someone join my pad let? If so here it is https://pad let.com/skeefex21/fyhcso9xasndl4xh
mario62 [17]

Answer:

Sure

Explanation:

5 0
3 years ago
Other questions:
  • 1.
    7·1 answer
  • Victor has been murdered, and Art, Bob, and Carl are suspects. Art says he did not do it. He says that Bob was the victim's frie
    14·1 answer
  • 3. You arrive at an intersection with traffic lights that are not working because of a power outage. What do you do?
    9·1 answer
  • Bonnie gets very nervous before taking tests. What can she do to help her anxiety while she takes her tests?
    15·2 answers
  • Which internet resource can you use to publicly describe an adventure trip you recently made?
    6·2 answers
  • Are goals that<br> have concrete criteria for measuring<br> progress toward their attainment.
    5·1 answer
  • In classical conditioning, _____ means that the CS and US are presented closely together, whereas _____ means that the CS is a g
    6·1 answer
  • Which of these is an example of rebranding ?
    6·2 answers
  • What is the current DoD repository for sharing security authorization packages and risk assessment data with Authorizing officia
    9·1 answer
  • What rpm command can be used to list the full paths for files within the bash package?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!