任何人都可以帮助我吗? 我正在完成这项任务,我几乎完成了我的代码,除了我不知道如何通过输入姓名来搜索客户列表。 !如何使用扫描仪在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