• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Print organisation details.

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Nkay

Registered
Joined
Feb 11, 2013
Here is one question me and my friend are trying to solve.

Design, write in Java, test and document a prototype program for maintaining a registry of non-profit
organisations. The program must have at least two class definitions - an organisation class and a client
class of the organisation class.
The organisation class will have data members described as follows, which should be declared as
private:
(a) Organisation name (a string)
(b) Organisation ID number – a three digit number between 100 and 999
(c) Organisation’s registered address – house number and street name (a string), suburb (a string),
state (one of WA, SA, VIC, ACT, NSW, QLD, NT, and TAS) and postcode (a four digit number)
(d) The date of registration (day, month and year)
(e) The name of the Chairperson (a string)
(f) The number of executive committee members in addition to the Chairperson (up to four) and their
names (each of them a string).
The organisation class will have at least the following constructors and methods:
(i) two constructors - one without any parameters (the default constructor), and one with
parameters to give initial values to some instance variables.
(ii) a reasonable number of set and get methods
(iii) an input method and an output method
(iv) a method for comparing whether two organisations are the same entity based on the following
criteria
- either two organisations have the same organisation ID number, or
- two organisations have the same name and address (ignoring the cases of letters in the
name and address) and the same registration date.
(v) a method to determine whether a given person is an executive committee member of a
registered organisation (ignoring the cases of letters in the name)
(vi) a method to determine whether a given person is the Chairperson of a registered organisation
(ignoring the cases of letters in the name)

You may need to add other methods as you progress with the solution. For example, you may find that
it is better to have a method to handle a certain feature within the organisation class than outside of it.
The client program will allow entry of these data for several organisations into an array (the registry)
and then some analysis and queries.
Your client class (program) will provide the user with a menu which allows the following actions:
1. Quit (exit the program)
2. Add (to the registry) all information about a new organisation
3. View all information about an organisation chosen via the organisation’s ID number
4. View all information about an organisation chosen via the organisation’s name (ignoring case)
5. Edit (ie change) information about an organisation chosen via the organisation ID number
6. List the names of all organisations in the registry
7. List all organisations in which a given person serves as an executive committee member (a
person may serve as an executive committee member for more than one organisation)
8. List all organisations that were registered after a certain date
9. List the number of organisations in each state
10. Sort the registry (array) into ascending (alphabetical/dictionary) order of organisations’ names
(ignoring case), and output the sorted registry.


I started this question about half an hour back and I came up with something like this.

Code:
import java.util.Scanner;

public class Organisation {

    /** data members described as follows below.
      * which is declared as private */
     
    private String organisationName;
    private int organisationID;    
    
    /** Organisation’s registered address */
    private int houseNumber; 
    private String streetName;
    private String suburb;
    private String state;
    private int postcode;
    
    /** The date of registration */
    private int date; 
    private int month;
    private int year;
    
    private String chairpersonName;
    
    /** Name of the executives and number of executives
      * Maximum 4 executives */
    private int numberOfExecutives;
    private String executiveNames;
    
    String[] orgName = new String[6];
    int[] orgID = new int[6];
    int[] houseNo = new int[6];
    String[] stName = new String[6];
    String[] sub = new String[6];
    String[] stateName = new String[6];
    int[] pCode = new int[6];
    int[] dateJoined = new int[6];
    int[] monthJoined = new int[6];
    int[] yearJoined = new int[6];
    String[] cpName = new String[6];
    int[] execNum = new int[6];
    String[] execNames = new String[6];
    
   
    public Organisation()
    {
        organisationName = "Organisation name";
        organisationID = 0000000;
        houseNumber = 0000000;
        streetName = "Street Name";
        suburb = "suburb";
        state = "state";
        postcode = 0000;
        date = 01;
        month = 01;
        year = 2013;
        chairpersonName = "Chairperson Name";
        numberOfExecutives = 4;
        executiveNames = "Executive names.";
        
                
    }

    public String getOrganisationName() {
        return organisationName;
    }

    public void setOrganisationName(String organisationName) {
        this.organisationName = organisationName;
    }

    public int getOrganisationID() {
        return organisationID;
    }

    public void setOrganisationID(int organisationID) {
        this.organisationID = organisationID;
    }

    public int getHouseNumber() {
        return houseNumber;
    }

    public void setHouseNumber(int houseNumber) {
        this.houseNumber = houseNumber;
    }

    public String getStreetName() {
        return streetName;
    }

    public void setStreetName(String streetName) {
        this.streetName = streetName;
    }

    public String getSuburb() {
        return suburb;
    }

    public void setSuburb(String suburb) {
        this.suburb = suburb;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public int getPostcode() {
        return postcode;
    }

    public void setPostcode(int postcode) {
        this.postcode = postcode;
    }

    public int getDate() {
        return date;
    }

    public void setDate(int date) {
        this.date = date;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getChairpersonName() {
        return chairpersonName;
    }

    public void setChairpersonName(String chairpersonName) {
        this.chairpersonName = chairpersonName;
    }

    public int getNumberOfExecutives() {
        return numberOfExecutives;
    }

    public void setNumberOfExecutives(int numberOfExecutives) {
        this.numberOfExecutives = numberOfExecutives;
    }

    public String getExecutiveNames() {
        return executiveNames;
    }

    public void setExecutiveNames(String executiveNames) {
        this.executiveNames = executiveNames;
    }

    
    
    
    public void inputInformation()
    {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter organisation name: ");
        organisationName = scan.nextLine();
        
        System.out.println("Enter organisation ID: (only 3 digit numbers)");
        organisationID = scan.nextInt();
        
        System.out.println("Enter organisation's registered address: \n");
        System.out.println("Enter house number: ");
        houseNumber = scan.nextInt();
        System.out.println("Enter street name: ");
        streetName = scan.nextLine();
        System.out.println("Enter suburb: ");
        suburb = scan.nextLine();
        System.out.println("Enter state: (WA, SA, VIC, ACT, NSQ, QLD, NT or TAS only)");
        state = scan.nextLine();
        System.out.println("Enter postcode: ");
        postcode = scan.nextInt();
        
        System.out.println("Enter the date of registration: \n");
        System.out.println("Date: ");
        date = scan.nextInt();
        System.out.println("Month: ");
        month = scan.nextInt();
        System.out.println("Year: ");
        year = scan.nextInt();
        
        System.out.println("Enter Chairperson's name: ");
        chairpersonName = scan.nextLine();
        
        System.out.println("Enter the number of executives: (maximum 4 only!)");
        numberOfExecutives = scan.nextInt();
        
        System.out.println("Enter name of executives, please separate them with commas)");
        executiveNames = scan.nextLine();
       
    }
    
    public void outputInformation()
    {
       
        int i = 0;
        while(i <= 6)
        {
           orgName[i] = organisationName;
           orgID[i] = organisationID;
           houseNo[i] = houseNumber;
           stName[i] = streetName;
           sub[i] = suburb;
           stateName[i] = state;
           pCode[i] = postcode;
           dateJoined[i] = date;
           monthJoined[i] = month;
           yearJoined[i] = year;
           cpName[i] = chairpersonName;
           execNum[i] = numberOfExecutives;
           execNames[i] = executiveNames;
           
           System.out.println("Do you want to enter more? (yes/no)");
           Scanner input = new Scanner(System.in);
           String option = input.nextLine();
           
           if("yes".equals(option))
           {
               i++;
               inputInformation();
               continue;
               
           }
           else
           {
               break;
           }
        }
      }
   }


We need to use arrays, which makes it worse.
Could you correct me if I'm going wrong somewhere and also help me with the checking of the equality part?
 
Last edited:
Can you show me how to use multidimensional arrays?
I think it will be easier for me.
 
I'm having trouble reading through the assignment and code, but here goes :D

- If I read that correctly, the Organization class should be more simple. I don't understand why you have all the arrays for orgId etc? Re-read what fields are required.

- The client is a gui, and will probably have an array (if that's what you have to use) of Organizations, new ones added when needed.

- The methods to input fields should probably not be in the Organization class, rather in the Client which would read the fields and then call the Organization constructer with the inputted values.

- For comparing Oranizations based on the ID look at comparator and how to implement it.

It's hard to give too concrete ideas without knowing what you have gone through in the course till now, and anyway it's good to think yourself too :)
 
Code:
public static void outputInformation()
    {
       for(int i=0;i<orgName.length;i++)
    {
        if(orgName[i] == null) {
            orgName[i] = organisationName; 
           
        }break;
        
       
    }
        for(int i=0;i<orgID.length;i++)
    {
        if(orgID[i]== 0) {
            orgID[i] = organisationID;
            
        }break;
    }
        
        
        
        for(int i=0;i<=houseNo.length;i++)
    {
        if(houseNo[i]== 0) {
            houseNo[i] = houseNumber;
            
        }break;
    }
        
        for(int i=0;i<=stName.length;i++)
    {
        if(stName[i]== null) {
            stName[i] = streetName;
        
        }break;
    }
        
        for(int i=0;i<=sub.length;i++)
    {
        if(sub[i]== null) {
            sub[i] = suburb;
          
        }break;
    }
        
        
        for(int i=0;i<=stateName.length;i++)
    {
        if(stateName[i]== null) {
            stateName[i] = state;
         
        }break;
    }
        for(int i=0;i<=pCode.length;i++)
    {
        if(pCode[i]== 0) {
            pCode[i] = postcode;
      
        }break;
    }
    
        for(int i=0;i<=dateJoined.length;i++)
    {
        if(dateJoined[i]== 0) {
            dateJoined[i] = date;
         
        }break;
    }
        
        for(int i=0;i<=monthJoined.length;i++)
    {
        if(monthJoined[i]== 0) {
            monthJoined[i] = month;
            break;
        }break;
    }
      
        for(int i=0;i<=yearJoined.length;i++)
    {
        if(yearJoined[i]== 0) {
            yearJoined[i] = year;
            
        }break;
    }
    for(int i=0;i<=sub.length;i++)
    {
        if(sub[i]== null) {
            sub[i] = suburb;
            
        }break;
    }
    
    for(int i=0;i<=cpName.length;i++)
    {
        if(cpName[i]== null) {
            cpName[i] = chairpersonName;
            
            
        }break;
    }
    
    for(int i=0;i<=execNum.length;i++)
    {
        if(execNum[i]== 0) {
            execNum[i] = numberOfExecutives;
    
        }break;
    }
    for(int i=0;i<=execNames.length;i++)
    {
        if(execNames[i]== null) {
            execNames[i] = executiveNames;
    
        }break;
    }
    
    
        }

That is my output method.
What I want to do is, each time the user enters a new organisation name or anything, it searches the array for a null space and puts it in
The problem I'm facing is that, the first time I DO IT, it works, then it doesn't save the rest.
I know there is a problem with my code, I just don't know what!

[[P.S. Don't advice me to use arrayList... I'm not allowed to use them...sadly]]
 
The problem is not that you should use an arrayList, rather that you should maybe have one array with organisations instead of 100 with different variables?

The break statement should probably be inside the "if" block, otherwise it will always break after the first loop whatever happens.
 
Can you show me how to use multidimensional arrays?
I think it will be easier for me.

a multidimensional array in java is set up with.

string stringArray[][] = new string[row][column];

so for example
string orgArray[][] = new string[6][5];

Would set up an array that is 5 columns wide, by 6 rows deep.


I also wouldn't recommend having the array of organisations contained within the organisations class as each new object will form a new array.

Have it either in a separate manager class or within Main.


To assist you in sorting, look up the "bubble sort" methodology, it's the easiest way of getting your feet wet without having to go into complicated recursive techniques.


I am not gonna write code out for you etc, just point you in the right direction, as this seems like a homework assignment and people don't learn from having it done for them :)
 
Back