abstract class Product {
String name;
String date;
int sale;
int price;
abstract void sell();
abstract void output();
}
class Mobile extends Product {
void output() {
System.out.print(name + "," + price + "元 ");
}
void sell()
{
System.out.println("销售的日期和时间:" + date+" " + "sales:" + sale + "¥");
}
Mobile(String date, int price, String name, int sale) {
this.date = date;
this.price = price;
this.name = name;
this.sale = sale;
}
}
class Pad extends Product {
void output() {
System.out.print(name + "," + price + "元 ");
}
void sell()
{
System.out.println("销售的日期和时间:" +date+" " + "sales:" + sale + "¥");
}
Pad(String date, int price, String name, int sale) {
this.date = date;
this.price = price;
this.name = name;
this.sale = sale;
}
}
public class Products {
public static void main(String [] args) {
Mobile mobile1 = new Mobile("2019-09-14 22:03:41.054", 107780, "iphone 11 pro max",106800 );
Mobile mobile2 = new Mobile("2019-09-14 22:03:41.054", 5450, "huaiwei p30", 6000);
Pad pad1 = new Pad("2019-09-14 22:03:41.054", 6999, "huaiwei pad", 7980);
Pad pad2 = new Pad("2019-09-14 22:03:41.054", 1380, "xiaomi pad", 1400);
Pad pad3 = new Pad("2019-09-14 22:03:41.054", 9500, "iphone pro", 9500);
Product[] products_ = {mobile1, mobile2, pad1, pad2, pad3};
for (int i = 0; i < 5; i++) {
products_[i].output();
products_[i].sell();
}
}
}