本帖最后由 刘胜寒 于 2013-5-18 03:36 编辑
- //打折卡小软件
- //通过曾经的消费数额来确定折扣 1000-2000元 9折 2000-5000元8折 5000元以上7折
- //思路:先定义打折卡的 用户的名称、消费金额、地址和所享受到折扣
- class Dazheka
- {
- private String name;
- private int cost=10;
- private String address;
- private double zhekou=1;
- public void setCost(int a)
- {
- if (a>0)
- {
- cost +=a;
- }
- else
- cost -=a;
- }
- public int getCost ()
- {
- return cost;
- }
- public void setName(String n)
- {
- name=n;
- }
- public String getName()
- {
- return name;
- }
- public void setAddress(String b)
- {
- address=b;
- }
- public String getAddress()
- {
- return address;
- }
- public void setZhekou()
- {
- if (cost>=1000)
- {
- zhekou-=0.1;
- }
- else if (cost>=2000)//这一块 不管cost怎么变 折扣 都不变是怎么回事啊
- {
- zhekou-=0.2;
- }
- else if (cost>=5000)
- {
- zhekou-=0.3;
- }
-
- }
- public double getZhekou()
- {
- return zhekou;
- }
- void dayin()
- {
- System.out.println("name:"+name);
- System.out.println("address:"+address);
- System.out.println("cost:"+cost);
- System.out.println("zhekou:"+zhekou);
- }
- }
- class Zhekou1
- {
- public static void main (String[] args)
- {
- Dazheka z=new Dazheka();
- z.setName("zhanghao");
- z.setCost(3000);
- z.setAddress("xiangyang");
- z.dayin();
- }
- }
复制代码 无论我的cost的值怎么变 我的zhekou的值就是不变。。
这是怎么回事啊??? |