如何将另一个包的类导入到我的包中

发布于 2024-10-20 10:44:30 字数 257 浏览 3 评论 0原文

编写一个名为 Company 的包。在此包下创建另一个名为 salary 的包。 这个工资包创建了“收入”和“支出”两个类别。收入类别包括基本、DA 和 Hra...而“支出”包括食物、衣物和家庭支出。

在软件包公司中创建一个“预算”类,它使用上述两个类并计算家庭储蓄。

我的问题是我在“收入”和“支出”类中都使用了构造函数。

但是预算类中存在一些问题,而导入这两个类..

你能解释一下我该如何编写“预算”类吗??????谢谢/!!!

Write a package called Company. Under this package create one other package called salary.
This salary package creates two classes "income" and "expenditure". Income class contain Basic, DA and Hra...and "expenditure" contain food, cloth and home exp.

Create a class "Budget" in package company which uses above two classes and calculate savings of family..

My problem is i have used constructor in both the classes "Income" and "Expenditure"..

but there are some problem in Budget class while importing these two classes..

can you explain me how can I write the "Budget" class ??????? Thank you/!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靖瑶 2024-10-27 10:44:30

这并不是 100% 完整,甚至不是一个好方法,但它可能会让您思考。

package company;

import company.salary.Income;
import company.salary.Expenditure;

public class Budget
{
    private List<Income> credits;
    private List<Expenditure> debits;

    // Other stuff here
    public Money calculateSavings()
    {
        Money savings = new Money();

        for (Income credit : credits)
        {
           savings.add(credit.getValue());
        }
        for (Expenditure debit : debuts)
        {
           savings.sub(debit.getValue());
        }

        return savings;
    }
}


package company.salary;

public class Income
{
    private Money value;

    public Money getValue() { return this.value; }
}

public class Expenditure
{
    private Money value;

    public Money getValue() { return this.value; }
}

This is not 100% complete or even a good way to do it, but it might get you to think.

package company;

import company.salary.Income;
import company.salary.Expenditure;

public class Budget
{
    private List<Income> credits;
    private List<Expenditure> debits;

    // Other stuff here
    public Money calculateSavings()
    {
        Money savings = new Money();

        for (Income credit : credits)
        {
           savings.add(credit.getValue());
        }
        for (Expenditure debit : debuts)
        {
           savings.sub(debit.getValue());
        }

        return savings;
    }
}


package company.salary;

public class Income
{
    private Money value;

    public Money getValue() { return this.value; }
}

public class Expenditure
{
    private Money value;

    public Money getValue() { return this.value; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文