Java Help: A store owner keeps a recored of daily cash transactions in a text fi
ID: 3697985 • Letter: J
Question
Java Help:
A store owner keeps a recored of daily cash 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 it was received. Items are separated by space. Write a program that will prompt the store owner for the amount of cash at the begining and end of the day, and the name of the file. Your program should check whether the actual amount of cash at the end of the day equals the expected value.
Plus write a test program .
Explanation / Answer
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
public class test99 {
public static void main(String[] args)
{
BufferedReader br;
int st,end,st1;
Scanner scan = new Scanner(System.in);
System.out.print("What is the amount at the start of the day:");
st = scan.nextInt();
st1=st;
System.out.print("What is the amount at the end of the day:");
end = scan.nextInt();
String s;
int temp;
try {
Path path = Paths.get("C:\Users\Rajeev\Desktop\chegg\Codes\transactions.txt");
Scanner sn = new Scanner(path);
while (sn.hasNext()) {
s = sn.next();
temp = sn.nextInt();
s= sn.next();
if(s.equals("P"))
{
st1 -= temp;
}
else
{
st1 += temp;
}
}
}
catch(Exception e)
{
}
if(st1==end)
System.out.println("The actual amount equals the amount of expected value");
else
System.out.println("The actual amount is different from the expected value");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.