Charge Account Validation In the Chap07 folder of the Studen
Solution
package ch07;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Ch07 {
public static void main(String[] args) {
String arr[]=new String[50]; //array to store the numbers read from file
String c_line; //for getting current line
try (BufferedReader br = new BufferedReader(new FileReader(\"C:\\\\Users\\\\ttechnocraft\\\\Documents\\\\ChargeAccounts.txt\"))) //please provide your own path
{
int i=0;
while ((c_line= br.readLine())!= null) {
arr[i]=c_line;
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
Scanner scn = new Scanner(System.in);
System.out.println(\"Enter the charge account number to be searched:\");
String charge_acc_no = scn.next();
int counter=0;
for(int i=0;i<18;i++){
if(charge_acc_no.equals(arr[i]))
{
System.out.println(\"The charge account number you have entered is valid\");
counter=1;
break;
}
}
if(counter==0)
System.out.println(\"Invalid number..!!! The number is not present in the array or the file\");
}
}
