开发者

how can I import class of another package into my package [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

Write a package called Company. Under this package create on开发者_JAVA技巧e 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/!!!


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; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜