Question
So this is the prompt: Open AcctNumsIn.txt and look over the contents. Then open ValidateCheckDigits.java and write a program to read in each account number
So this is the prompt:
Open AcctNumsIn.txt and look over the contents.
Then open ValidateCheckDigits.java and write a program to read in each account number from AcctNumsIn.txt and display whether it is valid.
An account number is valid only if the last digit is equal to the sum of the first five digits divided by 10. For example, the number 223355 is valid because the sum of the first five digits is 15, the remainder when 15 is divided by 10 is 5, and the last digit is 5. Write only valid account numbers to an output file, each on its own line, to a file named AcctNumsOut.txt.
This is my code:
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class ValidateCheckDigits { public static void main(String[] args) { Scanner filescanner=null; PrintWriter filewritter=null; String inputFileName="AcctNumsIn.txt"; String outputFileName="AcctNumsOut.txt"; try { filescanner=new Scanner(new File(inputFileName)); filewritter=new PrintWriter(new File(outputFileName)); while(filescanner.hasNextLine()) { int account=Integer.parseInt(filescanner.nextLine()); if(isValidAccount(account)) filewritter.println(account); } } catch (FileNotFoundException e) { System.out.println("Exception opening File."); } filescanner.close(); } private static boolean isValidAccont(int account) { int lastDigit=account%10; int temp=account/10; int sum=0; while(temp!=0) { sum+=temp%10; temp=temp/10; } if(sum%10==lastDigit) return true; else return false; } }
I'm getting an error on line 20: if(isvalidAccount(account)). It says cannot find file, meaning it was unable to find something it was looking for. How do I rectify this?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started