Results 1 to 3 of 3
  1. #1
    knightj is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default BlueJ project called Dog-unit1

    Help! I do not know what I am doing wrong. Can not pull the mother and fathers name. It keeps using String Name of the dog instead. Uggggg!!!

    Dog
    + age : int
    + owner : String
    + mother : Dog
    + father : Dog
    + setOwner( String newOwner ) : void
    + getOwner() : String
    + birthday() : void
    + dogAge() : int
    + setMother(Dog m) : void
    + setFather(Dog f) : void
    + hasMother() : Boolean
    + hasFather() : Boolean




    /**
    * Write a description of class Dog2 here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Dog
    {
    // instance variables - replace the example below with your own
    private int age;
    private String owner;
    private String getOwner;
    private String getName;
    private String name;
    private String getMother;
    private String getFather;
    private Dog mother;
    private Dog father;


    /**
    * Constructor for objects of class Dog
    */
    public Dog(int dogAge, String dogOwner, String dogName, String dogMother, String getFather)
    {
    // initialise instance variables
    age = dogAge;
    owner = dogOwner;
    name = dogName;
    mother = mother;


    }

    public String name()
    {
    return name;
    }

    public int getAge()
    {
    return age;
    }

    public void setAge(int age)
    {
    age=age;
    }

    public String getOwner()
    {
    return owner;
    }

    public void setOwner(String newOwner)
    {
    owner=newOwner;
    }

    public String getMother()
    {
    return name;
    }

    public void setMother(Dog m)
    {
    mother = m;
    }

    public String getFather()
    {
    return name;
    }

    public void setFather(Dog f)
    {
    father = f;
    }

    /**
    * Calculate and retun the birthday of the dog from its age
    */
    public void Birthday()
    {
    // put your code here
    age=age+1;
    }

    public boolean hasMother()
    {
    if(this.getMother()!=null)
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    public boolean hasFather()
    {
    if(this.getFather()!=null)
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    /**
    * returns if the dog is a puppy
    */
    public boolean isPuppy()
    {
    return (age>=1) && (age<=3);
    }
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: BlueJ project called Dog-unit1

    Because your getMother and getFather methods both return the "name" variable. Sorry, but what did you expect?

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: BlueJ project called Dog-unit1

    Compare the attributes you have given your Dog class with those in the class diagram.
    They're not a very good match.
    I see no getMother/getFather attribute in the diagram, for example.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. BlueJ project to a view-able JAR file
    By Dr_DerpyHooves in forum New To Java
    Replies: 1
    Last Post: 08-02-2013, 06:25 AM
  2. BlueJ project need some help with
    By Big-D in forum New To Java
    Replies: 2
    Last Post: 03-14-2012, 03:10 PM
  3. Bluej Project to exe
    By jds93 in forum New To Java
    Replies: 3
    Last Post: 11-12-2011, 02:07 PM
  4. Error Compiling Project in BlueJ
    By java1337 in forum New To Java
    Replies: 9
    Last Post: 06-17-2011, 09:04 PM

Posting Permissions

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