标题:JAVA封装
取消只看楼主
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
得分:0 
import java.util.Scanner;

public class PlaneTicket {

    public static void main(String[] args){
        int n=0;
        PlaneNumber p=new PlaneNumber();
        Discount d=new Discount();
        p.setPrice(1000);
        System.out.println("请输入需要购买的张数:");
        Scanner scanner=new Scanner(System.in);
        n=scanner.nextInt();
        p.setNumber(n);
        System.out.println(p.getPrice()*d.way());
        
    }
   
}
--------------------------------------------------------------------
import java.util.Scanner;

public class PlaneNumber {
    private int number,price;
    public int getNumber() {
        return number;
    }
    public void setNumber(int number) {
        this.number = number;
    }
    public int getPrice() {
        return price*number;
    }
    public void setPrice(int price) {
        this.price = price;
    }

}
--------------------------------------------------
public class Discount {
    public double way(){
        double dis=0.0;
        PlaneNumber p=new PlaneNumber();
        if(p.getNumber()>20){
            dis=0.7;
        }else if(p.getNumber()>=11){
            dis=0.8;
        }else{
            dis=0.9;
        }
        return dis;
    }
}
---------------------------------------------------------
最后在林版主的帮助下勉强做出来了,谢谢林大版主这么晚也不睡来教育我!
2015-05-04 00:24
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
得分:0 
回复 17楼 林月儿
····没啥多大区别,只是class属性改下而已,Scanner语句能放在class PlaneNumber上么?
2015-05-05 08:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444797-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.137812 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved