用HashMap模拟一个网上购物车。要求:从键盘输入5本书的名称、单价、购买数量,将这些信息存入一个HashMap,然后将该HashMap作为参数调用方法getSum(HashMapbooks),该方法用于计算书的总价并返回。提示:键盘输入可以使用Scanner类。代码:importjava.util.HashMap;importjava.util.Scanner;classBook{publicStringname;publicdoubleprice;publicintnum;}/****@authorAdministrator**/publicclassShoping{publicstaticdoublegetSum(HashMapbooks){doublesum=0;for(inti=0;ibooks.size();i++){Bookb=(Book)books.get(i);sum+=b.price*b.num;}returnsum;}publicstaticvoidmain(String[]args){HashMapm=newHashMap();System.out.println(请输入5本书的名称、单价、购买数量);for(inti=0;i5;i++){Bookb=newBook();Scannera=newScanner(System.in);b.name=a.nextLine();b.price=a.nextDouble();b.num=a.nextInt();m.put(i,b);}doublesum=getSum(m);System.out.println(sum=+sum);}}执行结果: