Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm fairly new to Java and I'm having a bit of trouble completing an assignment.

We are asked to create a program that takes information from companies (we are supposed to create at least three). From each company we have to enter the number of departments, from each department the number of employees, from each employee the projects assigned and whether if the project is completed or not. We were told as a hint that the departments are not subclasses but rather properties.

I've so far created a class that creates the companies but I'm stuck on how to do next...

I was thinking on creating an array of department objects of some sort then another array for employees, Am I heading in the right direction?

class Company{

    String companyName;
    int numberOfDepartments;      

    Company (String companyName, int numberOfDepartments){
        this.companyName= companyName;
        this.numberOfDepartments = numberOfDepartments;
    }

    void message(){
        System.out.print (companyName + " has " + numberOfDepartments + " Departments ");
    }

    public static void main (String [] args){
        Company myCompany= new Company("myCompany", 10);
        myCompany.message();
    }
}

Any help will be appreciated.

share|improve this question
1  
I don't think you want to store the number of departments: instead, store a list of department objects and use the number to determine how many to add. I think List<Department> and ArrayList will work better than an array. –  Rup Jun 20 at 0:07
 
..*"deparments"* Tip: deparments -> deparTments -> departments –  Andrew Thompson Jun 20 at 0:13
add comment

1 Answer

Lucky, since it is an homework it's better you try to develop the design you have in mind before asking for other's suggestion. If it doesn't work or you think it would work better, you can ask for some advice.

By the way, the right way of deal with this kind of problem is starting with the smallest class: it is simple, it is easily manageable and you can design it pretty quick (in your case it should be the Project, having a name and a boolean flag isCompleted and, perhaps, a pointer to its employee). Then you can manage the Employee class and head up to the top.

This is called bottom-up and it is one of the most used programming style principles (the top-down is specular and used in symmetrical cases). Just consider the Matrioska game. Build the smallest one and just let it go inside the 'a little bigger' one. Then iterate :)

matrioska

Good luck

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.