package Test;
import java.util.ArrayList;
import java.util.Scanner;
public class T1 {
public static void main(String[] args) {
shangpin s1 = new shangpin("电脑", 1, 8000);
shangpin s2 = new shangpin("键盘", 15, 500);
shangpin s3 = new shangpin("鼠标", 14, 250);
ArrayList<shangpin> arr = new ArrayList();
arr.add(s1);
arr.add(s2);
arr.add(s3);
show(arr, null);
Scanner sc = new Scanner(System.in);
String ss = sc.nextLine();
show(arr, ss);
}
public static void show(ArrayList<shangpin> arr, String ss) {
int sum = 0;
System.out.println("您选购的商品为");
for (int i = 0; i <arr.size(); i++) {
shangpin s=arr.get(i);
if (s.getName().equals(ss)) {
arr.remove(s);
}
}
for (int i = 0; i < arr.size(); i++) {
shangpin s=arr.get(i);
System.out.println(s.getName() + "\r\n\t" + s.getId() + "\r\n" +
"\t" + s.getAge());
sum += s.getAge();
}
System.out.println(sum);
}
}
|
|