I'm not including code yet as to the fact I've restarted several times. I think if I can determine how to start I can make some headway. Here are my beginning instructions.

High-level specifications
Your project manager has assigned you the task of developing a subsystem that tracks the populations of political units like nations, states, and cities. Each object representing a political unit has these responsibilities:
• Know its name and population.
• Compare its population with that of another political unit.
• Determine whether it is equal to another object.
• Produce a String representation of itself.
There are 2 types of political units:
• Simple units like cities.
• Composite units, like states, that consist of other political units.
The subsystem will also need to manage a collection of political units.
Interface and classes
• Political unit interface for common behaviors to allow polymorphism
o compare to a political unit
o equals another object
o toString that includes all the subunits
o getters (accessors) for name and population
• Simple political unit class that implements the interface
o Constructor with 2 parameters for name and population.
o compare to a political unit (use subtraction)
o equals another object
o toString
o getters (accessors) for name and population
• Composite political unit class that implements the interface
o constructor with 1 parameter for name
o add a political unit
o compare to a political unit (use subtraction)
o equals another object
o toString that includes all the subunits
o getters (accessors) for name and population
• Collection of political units
o constructor with 0 parameters to initialize an empty List
o size (i.e., number of political units in the collection)
o add a political unit
o toString that includes all the political units in the collection
o find unit with greatest population
o find unit with smallest population

I thought that I would need to make a class of Unit(within this class have my methods that the interface will use) then have my PoliticalUnit interface class. Then from here have my SimplePoliticalUnit and CompositePoliticalUnit that implements the PoliticalUnit. After all this I would create my collection class with my ArrayLists. Am I wrong in creating the Unit Class? I have trouble with calling my methods within the classes that implement the Political Unit class. When our professor taught us we used our collection as the interface not the unit itself. Any advise would be greatly appreciated.

I simplified class names ( too long for me )
Write new classes from scratch, only that, that you need to run
execute this main() line by line and show your results

public static void main(String args[]) {

        // at any phase write only, what things you need
        //write simple class SimpleUnit 
        SimpleUnit city = new SimpleUnit("Montgomery", 4599000);
        System.out.println(city.getName());
        //result   Montgomery
        System.out.println(city.getPopulation());
        //result   4599000

        // write Unit interface and check
        // 
        Unit cityI = new SimpleUnit("Montgomery", 4599000);
        System.out.println(cityI.getName());
        //result   Montgomery
        System.out.println(cityI.getPopulation());
        //result   4599000
        // overwrite method toString in class SimpleUnit
        System.out.println(city);
        //result   [CITY=Montgomery,4599000]

        //write simple class CompositeUnit 
        CompositeUnit state = new CompositeUnit("StateAlabama");
        System.out.println(state.getName());
        //result   StateAlabama
        System.out.println(state.getPopulation());
        //result   0

        System.out.println(state);
        //result   {STATE=StateAlabama,0}


        //In the CompositeUnit temporaily use ArrayList structure to replace
        // in future with CollectionUnit class
        //List<SimpleUnit> list;
        System.out.println();
        state.add(city);
        System.out.println(state.getName());
        //   StateAlabama
        System.out.println(state.getPopulation());
        //   4599000
        System.out.println(state);
        //   {STATE=StateAlabama,4599000[CITY=Montgomery,4599000]}

        //add second new city to state
        state.add(new SimpleUnit("Second", 999));
        System.out.println(state.getName());
        //   StateAlabama
        System.out.println(state.getPopulation());
        //   4599999
        System.out.println(state);
        //   {STATE=StateAlabama,4599999[CITY=Montgomery,4599000][CITY=Second,999]}
        
        // 
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.