investor.java

来自「Java程序设计大学教程程序源代码」· Java 代码 · 共 43 行

JAVA
43
字号
/**
 * <p>Title: 果园系统——投资者类</p>
 *
 * <p>Description: 教学演示程序</p>
 * <p>演示一个较复杂一点的面向对象应用程序的设计过程</p>
 * <p>帮助学生理解接口编程</p>
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 刘艺</p>
 *
 * @author 刘艺
 * @version 1.0
 */

package jbookch4.gardensys2;

public class Investor {
    public Investor(String name) {
        this.name = name;
    }

    public static void main(String[] args)  {
        Investor theInvestor = new Investor("休闲果园开投资公司");
        float g = theInvestor.getProfits();
        System.out.println(theInvestor.name + "投资总收益为" + g);
    }

    public float getProfits() {
        float sum = 0;
        profits[0] = new Realestate("果园别墅", 200000);
        profits[1] = new Realestate("温室", 100000);
        profits[2] = new Fruit("葡萄", 8000);
        profits[3] = new Fruit("香蕉", 100000);
        for (int i = 0; i < profits.length; i++) {
            sum += profits[i].gain();
        }
        return sum;
    }

    private IGain[] profits = new IGain[4];
    private String name;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?