Results 1 to 20 of 20
  1. #1
    rahilz is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default How do I create a class called Dog in Java?

    I am really struggling with this assignment for my Computer Science I course. If anyone could help me that would be amazing. The attach documents are the data needed to be used in the programme

    This is exactly what I need to have:


    Design and implement a class called LostDog that contains instance data that represents the dog’s name, gender, breed, and owner status (as a Boolean flag to represent whether the owner is unknown or found).
    Define the LostDog constructor to accept and initialize instance data. Include getter and setter methods for all instance data. Include a to String method that returns a one line description of the dog.
    Create a driver class call DogPound that will contain an array that will reference all lost dogs, using the LostDog object. You will use an input file to upload lost dogs into the array (the file and code to process it will be provided). Copy the input file lostdogs.csv to the project folder of your eclipse workspace.
    In addition, include code to enable someone to search the pound for a lost dog.
    Prompt the user to enter the name of the dog, and search the array to see if any dogs match that name (you can assume all dog names in the pound are unique). If there is a match, change the dog’s status to “owner found” and report to the owner that you have found the dog.
    Optional extras:
    • allow the user to continue to search for dogs until they decide to quit
    • create your own input file with a larger set of lost dogs (need to change SIZE)
    • once the user quits, produce a report of all lost dogs, followed by a report of all found dogs
    • allow the user to search by breed (this may result in duplicates)
    • other ideas?



    DogPound.txt

    lostdogs.txt

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Brilliant, and what is your attempt?

  3. #3
    rahilz is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    Something like this but i'm not sure

    Java Code:
    class Dog {
          private String name = "";
          private int age = -1;
          private String owner = "";
    
    public Dog(String n, int a, String o) {
    name = n;
    age = a;
    owner = o;
    }
    
    //get/set methods
    public void setName(String n) {
    name = n;
    }
    public String getName() {
    return name;
    }
    
    public void setAge(int a) {
    age = a;
    }
    public int getAge() {
    return age;
    }
    
    public void setOwner(String o) {
    owner = o;
    }
    public String getOwner() {
    return owner;
    }
    
    public int humanYears() {
    return age * 7;
    }
    
    public String toString() {
    String str = "Dog Name: "+name+", Age: "+age+", Owner: "+owner;
    return str;
    }
    }
    Last edited by Eranga; 12-19-2010 at 03:21 AM. Reason: code tags added

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Looks like a lovely Dog class

    where is this:
    Create a driver class call DogPound that will contain an array that will reference all lost dogs, using the LostDog object.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    @rahilz, please use code tags next time when you are posting again in the forum. Unformated codes are really hard to read. If you don't know how to do that, check on my forum signature.

    And also think about intending line of codes, it's much clear then. :)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    See how nice when it is formatted properly. ;)

    Java Code:
    class Dog {
    
        private String name = "";
        private int age = -1;
        private String owner = "";
    
        public Dog(String n, int a, String o) {
            name = n;
            age = a;
            owner = o;
        }
    
        //get/set methods
        public void setName(String n) {
            name = n;
        }
    
        public String getName() {
            return name;
        }
    
        public void setAge(int a) {
            age = a;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setOwner(String o) {
            owner = o;
        }
    
        public String getOwner() {
            return owner;
        }
    
        public int humanYears() {
            return age * 7;
        }
    
        public String toString() {
            String str = "Dog Name: " + name + ", Age: " + age + ", Owner: " + owner;
            return str;
        }
    }

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    show off :) :)
    See how nice when it is formatted properly.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Of course. :D Because you must attractive others to answer to your question is such ways. The thing is personally I don't like to read codes very hardly and answer them. So I encourage others to do that. ;)

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by Eranga View Post
    Of course. :D Because you must attractive others to answer to your question is such ways. The thing is personally I don't like to read codes very hardly and answer them. So I encourage others to do that. ;)
    I agree ;) I was just being sarcastic because it was so obvious he shoulda done it to begin with :)

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    As a newbie have to learn lost of things. So we must help them to move in right way.

    Even me not start in a perfect way, with the time I think I grape things.

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Yeah you are right

  12. #12
    rahilz is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    Thank You Eranga will do this next time.

  13. #13
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Any joy on the DogPound class?

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by rahilz View Post
    Thank You Eranga will do this next time.
    Cool. :)

    SO how things going with your coding?

  15. #15
    rahilz is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

    Default

    I'm stuck the code doesn't work i'm not sure how to use the data

    Create a driver class call DogPound that will contain an array that will reference all lost dogs, using the LostDog object. You will use an input file to upload lost dogs into the array (the file and code to process it will be provided). Copy the input file lostdogs.csv to the project folder of your eclipse workspace.
    In addition, include code to enable someone to search the pound for a lost dog.
    Prompt the user to enter the name of the dog, and search the array to see if any dogs match that name (you can assume all dog names in the pound are unique). If there is a match, change the dog’s status to “owner found” and report to the owner that you have found the dog.

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Firs of all, step down your requirement. Think about one at a time.

    Create a driver class call DogPound ....
    Did you do that?

  17. #17
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    From reading that it would appear that you need a LostDog class, but I am not so sure, in the DogClass you could have a setDogStatus and getDogStatus that return booleans as to whether they are lost or not, false being lost and true being found/has owner...

  18. #18
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    When writing your DogPound class take it one step at a time, I would try to implement an array of DogClass objects in there first (composition) and worry about the .csv file later..

  19. #19
    hockey9999 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    I just posted a very similar thread regarding the same programming project.

    Some of my code is attached, perhaps it will be useful to someone..

    Programming Project trouble..

  20. #20
    rahilz is offline Member
    Join Date
    Dec 2010
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2010, 08:25 PM
  2. I need to create a comlicated java class
    By globo in forum New To Java
    Replies: 8
    Last Post: 10-07-2010, 05:50 PM
  3. JFrame Hanging When Called From Another Class
    By al_Marshy_1981 in forum AWT / Swing
    Replies: 5
    Last Post: 03-30-2010, 07:04 PM
  4. Create a java class for a bank account!!?
    By singh345 in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 04:26 PM
  5. How to create a class in java?
    By pawankumarom in forum New To Java
    Replies: 2
    Last Post: 09-05-2008, 07:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •