创建测试类ClothingDemo,实现如下功能:
1、初始化三种品牌的上衣信息,例如:(品牌:优衣库类型:风衣价格:399风格:通勤风)
2、将三种服装存入到集合中,要求泛型。
3、输出集合中的所有服装信息。
4、显示集合中百搭风格的服装信息。
5、输入任意服装类型(如连衣裙),在集合中查找是否存在该服装类型。
6、查找服装价格小于200的服装信息。
import java.util.*;
import java.lang.Math;
public class Main {
static class ClothingDemo {
private String brand;
private String type;
private int price;
private String style;
public ClothingDemo(String brand, String type, int price, String style) {
this.brand = brand;
this.type = type;
this.price = price;
this.style = style;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
@Override
public String toString() {
return "ClothingDemo{" +
"brand='" + brand + '\'' +
", type='" + type + '\'' +
", price='" + price + '\'' +
", style='" + style + '\'' +
'}';
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList arrayList = new ArrayList();
ClothingDemo demo1 = new ClothingDemo("优衣库", "风衣", 399, "通勤风");
arrayList.add(demo1);
ClothingDemo demo2 = new ClothingDemo("优衣库", "卫衣", 199, "百搭风");
arrayList.add(demo2);
ClothingDemo demo3 = new ClothingDemo("太平鸟", "女装", 1399, "连衣裙");
arrayList.add(demo3);
System.out.println("所有信息:");
for(Object object:arrayList){
System.out.println(object.toString());
}
System.out.println("百搭风:");
for(Object object:arrayList){
if (((ClothingDemo)object).getStyle().equals("百搭风")) {
System.out.println(object.toString());
}
}
System.out.println("请输入类型:");
Scanner scanner = new Scanner(System.in);
String type = scanner.next();
for(Object object:arrayList){
if (((ClothingDemo)object).getStyle().equals(type)) {
System.out.println(object.toString());
}
}
System.out.println("价格小于200的信息:");
for(Object object:arrayList){
if (((ClothingDemo)object).getPrice() < 200) {
System.out.println(object.toString());
}
}
}
}
我愿称你为人才