[Bluej-discuss] java Arrays

Reid Edwards reidbedwards at gmail.com
Mon Jun 19 05:12:36 BST 2006


I am working on a project that requires a dog grooming service that
has 3 classes, Person, Dog, and Groomer.  The problem I am having is
that this project must be done with arrays (not ArrayLists) whereby I
store the information about the dog in the groomer class as well as
information about the person in the groomer class.  Then print out a
list of the information about the Dog and their owner.  Here's what I
have so far:

public class Groomer
{
    private String dog[];
    private String customer[];


    /**
     * Constructor for objects of class Groomer
     */
    public Groomer()
    {
        // initialise instance variables
        dog = new String[10];
        customer = new String[10];
    }

    public void setDogName(String first, String second, String third,
String fourth, String fifth, String sixth, String seventh, String
eigth, String ninth, String tenth)
    {
       dog[0]= first+"";
       dog[1]= second+"";
       dog[2]= third+"";
       dog[3]= fourth+"";
       dog[4]= fifth+"";
       dog[5]= sixth+"";
       dog[6]= seventh+"";
       dog[7]= eigth+"";
       dog[8]= ninth+"";
       dog[9]= tenth+"";
    }

    public void printDogNames(){
	    for(int i=0;i<dog.length;i++){
	        System.out.println(dog[i]);
	       }
	   }

       public void setCustomerName(String first, String second, String
third, String fourth, String fifth, String sixth, String seventh,
String eigth, String ninth, String tenth)
    {
       customer[0]= first+"";
       customer[1]= second+"";
       customer[2]= third+"";
       customer[3]= fourth+"";
       customer[4]= fifth+"";
       customer[5]= sixth+"";
       customer[6]= seventh+"";
       customer[7]= eigth+"";
       customer[8]= ninth+"";
       customer[9]= tenth+"";
    }

    public void printCustomerNames(){
        for(int i=0;i<customer.length;i++){
            System.out.println(customer[i]);
           }
       }
}

My first problem is that I think that there must be an easier way to
set the items in the array without having to go Sting first, String
second, etv...  Also, to combine the Customer list with the groomers
list.  i.e. Customer[]=dog[] or something??


More information about the bluej-discuss mailing list