Answer:
Step-by-step explanation:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class FinancialInfoSearch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter ID to search: ");
String searchID = scanner.nextLine();
scanner.close();
try (BufferedReader br = new BufferedReader(new FileReader("financial_info.txt"))) {
String line;
while ((line = br.readLine()) != null) {
String[] data = line.split(":");
if (data[0].equals(searchID)) {
System.out.println("Rate for " + searchID + ": " + data[1]);
return;
}
}
System.out.println("ID not found.");
} catch (IOException e) {
System.err.println("Error reading file: " + e.getMessage());
}
}
}
In this code, the user is prompted to enter the ID to search for. The BufferedReader class is used to read the lines of the file. For each line, the split method is used to split the line into an array of strings using the colon character as a delimiter. The first element of the array is compared to the search ID, and if they match, the rate is outputted. If the end of the file is reached and no match is found, a message is outputted saying that the ID was not found.
thank you