Hi this has me stumped I'm trying to search my file for a selected number and then display that number with the rest of the line, the problem is that my program seems to return the first line of contents when I search for it, but not second or third lines when I type in to search for them
public static String searchProject(String searchTerm, String filepath) {
String findString = "";
boolean found = false;
String projectNumber = "";
String projectName = "";
String typeProject = "";
String address = "";
String erf = "";
String fee = "";
String paid = "";
String deadline = "";
String finalised = "";
String architectName = "";
String architectTel = "";
String architectEmail = "";
String architectAddress = "";
String contractorName = "";
String contractorTel = "";
String contractorEmail = "";
String contractorAddress = "";
String customerName = "";
String customerTel = "";
String customerEmail = "";
String customerAddress = "";
try {
Scanner userInput = new Scanner(System.in);
userInput = new Scanner(new File(filepath));
userInput.useDelimiter("[,\n]");
while (userInput.hasNext() && !found) {
projectNumber = userInput.next();
projectName = userInput.next();
typeProject = userInput.next();
address = userInput.next();
erf = userInput.next();
fee = userInput.next();
paid = userInput.next();
deadline = userInput.next();
finalised = userInput.next();
architectName = userInput.next();
architectTel = userInput.next();
architectEmail = userInput.next();
architectAddress = userInput.next();
contractorName = userInput.next();
contractorTel = userInput.next();
contractorEmail = userInput.next();
contractorAddress = userInput.next();
customerName = userInput.next();
customerTel = userInput.next();
customerEmail = userInput.next();
customerAddress = userInput.next();
if (projectNumber.equals(searchTerm)) {
findString = "\nProject Number: " + projectNumber + "\nProject Name: " + projectName + "\nType Project: " + typeProject + "\nAddress: "
+ address + "\nERF number: " + erf + "\nTotal fee: R" + fee + "\nPaid to date: R" + paid + "\nProject Deadline: "
+ deadline + "\nIs the project finalised: " + finalised + "\nArchitect Name: " + architectName + "\nArchitect Telephone: " + architectTel + "\nArchitect Email: "
+ architectEmail + "\nArchitect Address: " + architectAddress + "\nContractor Name: " + contractorName + "\nContractor Telephone: " + contractorTel + "\nContractor Email: "
+ contractorEmail + "\nContractor Address: " + contractorAddress + "\nCustomer Name: " + customerName + "\nCustomer Telephone: " + customerTel + "\nCustomer Email: "
+ customerEmail + "\nCustomer Address: " + customerAddress;
System.out.println(findString);
}
}
} catch (Exception e) {
}
return findString;
}
my txt file contents
1,House mack,house,123 mack road,155,100000,40000,2022-09-14,no,Bill,123456,bill@gmail.com,12 Bill road,Jack,456789,jack@gmail.com,23 Jack road,John,789632,john@gmail.com,34 John road,
2,House John,house,123 John road,183,160000,50000,2022-09-10,yes,Bill,123456,bill@gmail.com,12 Bill road,Jack,456789,jack@gmail.com,23 Jack road,John,789632,john@gmail.com,34 John road,
3,House bill,house,123 bill road,193,160000,50000,2022-09-10,yes,Bill,123456,bill@gmail.com,12 Bill road,Jack,456789,jack@gmail.com,23 Jack road,John,789632,john@gmail.com,34 John road,
the output I am looking for
Please enter the project number to find the task: 1
Project Number: 1
Project Name: House mack
Type Project: house
Address: 123 mack road
ERF number: 155
Total fee: R100000
Paid to date: R40000
Project Deadline: 2022-09-14
Is the project finalised: no
Architect Name: Bill
Architect Telephone: 123456
Architect Email: bill@gmail.com
Architect Address: 12 Bill road
Contractor Name: Jack
Contractor Telephone: 456789
Contractor Email: jack@gmail.com
Contractor Address: 23 Jack road
Customer Name: John
Customer Telephone: 789632
Customer Email: john@gmail.com
Customer Address: 34 John road
when I type in 2 or 3 to find the project my program displays nothing where is the problem and how can I fix it?