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
"As a ____ database management system, Access is particularly powerful because you can enter data once and then retrieve informa
Galina-37 [17]

Answer:

d.Relational

Explanation:

With the help of Access users can successfully manage valuable information by saving it easily for future reporting it , and analysis.In access users can have access to organized data in their database with minimal effort.

You can enter the data and you can select which data you want and use queries for that accordingly for example:- joins,select statements etc.

7 0
3 years ago
Channel logging tokens can be set to all but:________. a. Relaxed b. Strict c. Both versions d. None
Rudik [331]

Answer:

c. Both versions

Explanation:

The Windows Remote management has hardening levels that could be set to Relaxed, Strict, or None based on the channel binding token associated with a request. This feature could be automatically found in the system or manually configured to a user's choice.

Relaxed settings mean rejection of channel binding token that are not valid and the acceptance of requests with no channel binding tokens, but which may be susceptible to attacks. Strict settings entail an automatic rejection of invalid channel binding tokens. None settings entail the acceptance of all requests with no protection against credential-forwarding attacks.

4 0
2 years ago
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program where the
SCORPION-xisa [38]

a aj ji hfjizbhig jiad jv hD jug vhi SDhvb hbnsdubghi

a biabihb hsjgbidbihdgbhibsrhkgbhibshibvghibsdgjo

asbihdg hibsihbghibdshibghbshbg9bhisdbghivbhbhir

aa sbuogjanjfjnbsujoenngobuewwwwwwwwwwwwwwwwwwwwwwww0o

8 0
2 years ago
When you use the tilde operator (~ in a url for the attribute of a server control, it represents the _____ directory of the webs
Verizon [17]
The tilde operator represents the root directory of the website.
4 0
3 years ago
The term drive app is used to describe applications stored on a computer true or false
Volgvan
Hello <span>Areyano7475
</span>

Question: T<span>he term drive app is used to describe applications stored on a computer true or false


Answer: False


Hope this helps
-Chris</span>
7 0
3 years ago
Read 2 more answers
Other questions:
  • What is the formula for calculating the average of cells<br> C2 through C30?
    15·1 answer
  • A ____ database supports data distributed across several different sites.
    7·1 answer
  • Haley is helping to choose members for a customer satisfaction team. Which
    6·1 answer
  • Compared to a virtual image, a real image
    15·2 answers
  • Secondary hard drive whats its purpose
    5·1 answer
  • Explain two ways by which the calendar meets or fails to meet the criteria of showing the correct data
    7·1 answer
  • Write a statement to add the key Tesla with value USA to car_makers. Modify the car maker of Fiat to Italy. Sample output for th
    13·1 answer
  • Writing a function that implements a loop to collect a set amount of data. The function should use the serial object, the record
    9·1 answer
  • - A blacksmith is shoeing a miser's horse. The blacksmith charges ten dollars for his work. The miser refuses to pay. "Very well
    6·1 answer
  • What are the disadvantages of vector images when compared to bitmap images?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!