importjava.util.Scanner;classPeople{//定义一个People类,Stringname;//姓名Stringtel;//Stringgoods;//存储物品doublegoodsPrice;//物品价格publicPeople(Stringname,Stringtel,Str...
import java.util.Scanner;
class People{ //定义一个People类,
String name;//姓名
String tel;//
String goods;//存储物品
double goodsPrice;//物品价格
public People(String name, String tel, String goods, double goodsPrice) {//构造方法
this.name = name;
this.tel = tel;
this.goods = goods;
this.goodsPrice = goodsPrice;
}
public String toString() {//toString方法, 用于输出
return "姓名:"+name+"\t电话:"+tel+"\t存储的物品:"+goods+"\t物品的单价:"+goodsPrice;
}
}
public class Demo3 { // 测试类
public static void main(String[] args) {
int peoNums = 10;//定义人数
People[] ps = new People[peoNums];
Scanner input = new Scanner(System.in);
for (int i = 0; i < ps.length; i++) {
System.out.println("-----输入第"+(i+1)+"号信息");
System.out.print("请输入姓名:");
String name = input.nextLine();
System.out.print("请输入tel:");
String tel = input.nextLine();
System.out.print("请输入存储物品:");
String goods = input.nextLine();
System.out.print("请输入物品价格:");
double goodsPrice = Double.parseDouble(input.nextLine());
ps[i] = new People(name, tel, goods, goodsPrice);
System.out.println(ps[i]);//输出信息
}
}
}
怎么将扫描仪记录的数据保存在文件里面。
并且可以随时查到保存的东西。例如你保存的人名是小明,你搜索小明可以把他的电话,货品以及价格同时找到。需要一个这样的程序。
展开