package 练习.商品入库;
import java.util.Scanner;
// 抽象手机类
public abstract class Phone {
//测试方法
public static void main(String[] args){
// 华为手机
huawei h = new huawei();
h.setName("华为P40");
h.setPrice(1999.99);
h.setConfiguration("8+128GB晓龙888");
// 小米手机
xiaomi x = new xiaomi();
x.setName("小米10X");
x.setPrice(1899.99);
x.setConfiguration("8+256GB晓龙8Gen1");
// 华为入库
System.out.println("请输入"+h.getName()+"手机的库存:");
Scanner sc = new Scanner(System.in);
int count =sc.nextInt();
h.setStorage(count);
// 小米入库
System.out.println("请输入"+x.getName()+"手机的库存:");
x.setStorage(sc.nextInt());
// 显示手机信息以及库存总价值金额
System.out.println("当前所有商品剩余库存数据如下:");
System.out.println("品牌:"+h.getName()+"\t价格:"+h.getPrice()+"元\t配置:"+h.getConfiguration()+"\t\t剩余库存:"+h.getStorage()+"部\t剩余库存总价值:"+h.Sum()+"元");
System.out.println("品牌:"+x.getName()+"\t价格:"+x.getPrice()+"元\t配置:"+x.getConfiguration()+"\t剩余库存:"+x.getStorage()+"部\t剩余库存总价值:"+x.Sum()+"元");
}
private String name;
private double price;
private String configuration;
private int storage;
private double sum;
// 总价值金额
public abstract double Sum();
public Phone(){}
public Phone(String name, double price, String configuration, int storage, double sum) {
this.name = name;
this.price = price;
this.configuration = configuration;
this.storage = storage;
this.sum = sum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getConfiguration() {
return configuration;
}
public void setConfiguration(String configuration) {
this.configuration = configuration;
}
public int getStorage() {
return storage;
}
public void setStorage(int storage) {
this.storage = storage;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
}
// 小米类
class xiaomi extends Phone {
public xiaomi(){
}
public xiaomi(String name, double price, String configuration, int storage, double sum) {
super(name, price, configuration, storage, sum);
}
@Override
public double Sum() {
setSum(getStorage()*getPrice());
return getSum();
}
}
// 华为类
class huawei extends Phone {
public huawei(){
}
public huawei(String name, double price, String configuration, int storage, double sum) {
super(name, price, configuration, storage, sum);
}
@Override
public double Sum() {
setSum(getStorage()*getPrice());
return getSum();
}
}