Charge Account Validation In the Chap07 folder of the Studen

Charge Account Validation In the Chap07 folder of the Student Sample Programs, you will find a file named ChargeAccounts.txt. The file contains a list of a company\'s valid charge account numbers. There are a total of 18 charge account numbers in the file, and each one is a 7-digit number, such as 5658845. Create an application that reads the contents of the file into an array or a List. The application should then let the user enter a charge account number. The program should determine whether the number is valid by searching for it in the array or List that contains the valid charge account numbers. If the number is in the array or List. the program should display a message indicating the number is valid. If the number is not in the array or List. the program should display a message indicating the number is invalid.

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\");
  
  
  
}
  
}

 Charge Account Validation In the Chap07 folder of the Student Sample Programs, you will find a file named ChargeAccounts.txt. The file contains a list of a com

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site