how can I import class of another package into my package [closed]
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; }
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论