1 package duix; 2 3 public class Shu { 4 5 //书的种类 6 public String Shuzl; 7 8 //书的名字 9 public String Shumz; 10 11 //某本书的限定额 12 int Shuxde; 13 14 //当前本书的数量 15 int Dangqsl; 16 17 public Shu(String shuzl,String shumz,int shuxde) 18 { 19 this.Shuzl = shuzl; 20 this.Shumz = shumz; 21 this.Shuxde = shuxde; 22 } 23 24 //增添书本 25 public void Zengjia(int Zengsl) 26 { 27 //实际增添书本的数量 28 int sjzsl = Shuxde - Dangqsl; 29 30 Dangqsl += Zengsl; 31 32 //本书已达限定额 33 if (Dangqsl >= Shuxde) 34 { 35 System.out.println("本书已达限定额,请停止增添"); 36 37 Dangqsl = Shuxde; 38 39 } 40 else 41 { 42 sjzsl = Zengsl; 43 } 44 45 System.out.println("增添书量 =" + Zengsl + ",当前本书数量 =" + Dangqsl); 46 } 47 //每本书单价 48 public int Danjia = 50; 49 50 //出售书本 51 public void Chushou(int Shengyusl) 52 { 53 int Shouchusl = Shuxde - Shengyusl; 54 55 Dangqsl -= Shouchusl; 56 57 System.out.println("剩余书本数量 =" + Shengyusl + "当前书本数量 =" + Dangqsl); 58 59 int xiaoshouzj = Danjia * Shengyusl; 60 61 System.out.println("销售总价 =" + xiaoshouzj); 62 } 63 64 65 } 66 67 68 69 70 71 72 73 package duix; 74 75 public class shutest { 76 77 public static void main(String[] args){ 78 79 Shu shu = new Shu("小说","红楼梦",40); 80 81 shu.Dangqsl = 10; 82 83 shu.Zengjia(20); 84 85 shu.Danjia= 50; 86 87 shu.Chushou(20); 88 89 90 //书 91 Shu shu1 = new Shu("","",30); 92 93 shu1.Danjia = 50; 94
时间: 2024-10-14 12:27:28