任何人都可以幫助我嗎? 我正在完成這項任務,我幾乎完成了我的代碼,除了我不知道如何通過輸入姓名來搜索客戶列表。 !如何使用掃描儀在java中搜索客戶列表:
- 獲取客戶列表從文件
- 客戶包含姓,名和電子郵件地址
- 排序名單按姓氏
- 在列表中找到一個給定的名稱
列表項
import java.util.*; import java.io.*; public class computer { public static void main(String args[]){ Scanner console = new Scanner(System.in); //create a file named myFile.txt createFile object1 = new createFile(); object1.openFile(); object1.addRecords(); object1.closeFile(); //This code reads the File and outputs it on the screen System.out.println("-----------------------------------------------------------------------"); System.out.println("This is the list of customers being read from a file called myFile.txt "); System.out.println("-----------------------------------------------------------------------"); readFile r = new readFile(); r.openFile(); r.readfile(); r.closeFile(); LinkedList<customers> list = new LinkedList<customers>(); try { Scanner file = new Scanner(new File("myFile.txt")); while(file.hasNext()) { String name = file.next(); String lname = file.next(); String email = file.next(); list.add(new customers(name,lname, email)); } } catch (Exception e) { // TODO: handle exception } Collections.sort(list,new Mycustomers()); System.out.println("This is the list of customers sorted by their last names: "); System.out.println("--------------------------------------------------------------"); System.out.println(); for(customers cu:list){ System.out.println(cu); }
您需要搜索哪些客戶?他們是否相同從文件讀取,或者用戶指定要搜索哪些客戶?你被困住的問題有兩個部分。一個是獲取名稱來搜索。這部分可以使用'掃描儀'。另一個實際上是執行搜索。這不應該使用'掃描儀'。 – 2014-09-26 18:04:35