Results 1 to 10 of 10

Thread: BlueJ IDE

  1. #1
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default BlueJ IDE

    Hello all the portion of the assignment I am working on asks:

    (new) In Step 5 above, you examine the relationship between a UML class diagram and an existing program. In this step, you will do the opposite: construct a class given a UML class diagram. Start a new BlueJ project called Dog-unit1. Include a single class called Dog, based on the UML class diagram below.
    Dog

    + age : int
    + owner : String

    + setOwner( String newOwner ) : void
    + getOwner() : String
    + birthday() : void
    + dogAge() : int


    A point of order for the Dog class: dogAge() should use the traditional method to calculate age in dog years—it multiplies the age value (expressed in human years) by seven.

    (new) Create two new dog objects named pluto and bess. Pluto is a 7-year-old dog owned by Mark Smith, and Bess is a 2-year-old dog owned by Jens Hanson. Your BlueJ window should resemble the following screenshot.

    Here is the code I have so far:
    public class Dog
    {
    public int age;
    public String name;
    public String dogMother;
    public String dogFather;

    public Dog(int dogAge,String dogOwner)
    {
    age = dogAge;
    owner = dogOwner;
    }
    public int getAge(){
    return age;
    }
    public String getName(){
    return name;
    {
    publicjava.util.DateBirthday(){
    return birthday;
    }
    public void setBirthday(java.util.Date birthday) {
    this.birthday = birthday;
    }
    age = age *7;
    {


    public String getOwner;
    public String owner;
    public void printDog() {
    }
    }

    I have 4 instance fields and two parameters for my constructor. The current error message I am getting is: ',' expected. I think I may have a brace out of place or one too many since I know I do not need a " or a ; at this point. When I remove and add a few braces around public void birthday I get an error message of illegal start of expression. Any help would be appreciated!

  2. #2
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    I am also confused why should instant fields be private when in the UML diagram everything is + set to public. If I have not answered enough or asked correctly to receive proper help, please let me know, thanks!

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: BlueJ IDE

    Don't make random guesses by adding/removing brackets. You have to read through your code line by line and make sure all your brackets match and in the correct order.
    Java Code:
    public void methodA() {
    
    {
    
    public void methodB() }
    
    }
    That code has the correct number of brackets but they are not in the correct order.

    As for your code, what is this?
    Java Code:
    publicjava.util.DateBirthday(){
    and this?
    Java Code:
    }
    age = age *7;
    {

  4. #4
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    Quote Originally Posted by Junky View Post
    Don't make random guesses by adding/removing brackets. You have to read through your code line by line and make sure all your brackets match and in the correct order.
    Java Code:
    public void methodA() {
    
    {
    
    public void methodB() }
    
    }
    That code has the correct number of brackets but they are not in the correct order.

    As for your code, what is this?
    Java Code:
    publicjava.util.DateBirthday(){
    and this?
    Java Code:
    }
    age = age *7;
    {
    Thanks for the advice on the braces. I thought I needed to add the publicjava.util... code based upon a textbook I was looking at, and the need to make the birthday function a publicly found feature, but other than that I could not tell you why I was placing it there. However, I was able to get my code to work and add extra features--please see below, as this compiles and runs 100%:



    /* File: Dog.java
    * Author: Jacob Mack
    * Last Modified: 08/07/2012
    */




    /**
    * Purpose: Defines the Dog class
    * Objects of this class will represent individual dogs
    * and will be used to calculate the type and amount of food given
    * @author Sharon Stansfield
    * Last Modified: 08/07/2012
    */
    public class Dog {

    //input properties:
    private String name; //name of dog
    private String owner; //last name
    private double weight; //in pounds
    private double age; //in years

    //determined properties
    private String typeOfFood;
    private double amountOfFood;

    //methods:

    /** Purpose: parameterized constructor
    * @param nameIn is the name of the dog
    * @param ownerIn is the name of the dog's owner
    * @param ageIn is the age of the dog in years
    * @param weightIn is the weight of the dog in pounds
    * <p>Output: none
    * <p>Properties modified: name, owner, breed, weight
    */

    public Dog(String nameIn, String ownerIn, double ageIn, double weightIn){

    //assign input values to properties
    name=nameIn;
    owner=ownerIn;
    weight=weightIn;
    age=ageIn;
    // initialize determined properties
    typeOfFood = "";
    amountOfFood = 0.0;
    }

    /** Purpose: determines the type of food the dog is supposed to get
    * if the dog is younger than 1.5 years it gets puppy food
    * if the dog is between 1.5 and 7 years it gets regular food
    * if the dog is older than 7 years it gets mature food
    * <p>Input: none
    * <p>Properties modified: name, owner, breed, weight
    * <p>Output: none
    * <p>Properties modified: typeOfFood
    */

    public void determineTypeOfFood(){
    //determine type of food
    if(age < 1.5)
    typeOfFood="puppy";
    else if (1.5 <= age && age <= 7.0)
    typeOfFood="adult";
    else typeOfFood="mature";
    }


    /** Purpose: determines the amount of food the dog is supposed to get
    * using the dogs weight: the dog gets 2 ounces per pound of body weight
    * <p>Input: none
    * <p>Output: none
    * <p>Properties modified: amountOfFood
    */

    public void determineAmountOfFood(){
    //determine the amount of food
    amountOfFood=weight*0.5;
    }


    /** Purpose: accessor method
    * <p>Input: none
    * @return name
    * <p>Properties modified: none
    */
    public String getName(){
    return name;
    }

    /** Purpose: accessor method
    *<p>Input: none
    *@return owner
    *<p>Properties modified: none
    */
    public String getOwner(){
    return owner;
    }

    /** Purpose: accessor method
    *<p>Input: none
    *@return age
    *<p>Properties modified: none
    */
    public double getAge(){
    return age;
    }

    /** Purpose: accessor method
    *<p>Input: none
    *@return weight
    *<p>Properties modified: none
    */
    public double getWeight(){
    return weight;
    }

    /** Purpose: accessor method
    *<p>Input: none
    *@return typeOfFood
    *<p>Properties modified: none
    */
    public String getTypeOfFood(){
    return typeOfFood;
    }
    /** Purpose: accessor method
    *<p>Input: none
    *@return amountOfFood
    *<p>Properties modified: none
    */
    public double getAmountOfFood(){
    return amountOfFood;
    }

    }//Dog class

    I appreciate the reply, since this had stumped me for a week.

  5. #5
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    Oh the age = age * 7 was supposed to convert each human year to be multiplied by 7 but I see where I went wrong there too... thanks!

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: BlueJ IDE

    Quote Originally Posted by jcbmack View Post
    I thought I needed to add the publicjava.util... code based upon a textbook I was looking at
    You need to use "java.util.whatever" when you want to use a class from another package. Alternatively you use an import statement. I don't see how it applies to a method you are writing. Plus there was no space (typo?) and no return type. Several reasons why that code would not compile.

    As for the age = age*7 statement to me it appeared outside a method, which why I mentioned it.

  7. #7
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    Thanks for the follow up reply Junky... between a hectic semester as a student and GA it is easy to forget things and miss things with tired eyes, so it is appreciated all of your feedback and I do find what you are stating from earlier chapters in my textbooks... it is easy to forget the fundamentals on low sleep:) Thanks again!

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

    Default Re: BlueJ IDE

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    Quote Originally Posted by DarrylBurke View Post
    Thanks, all read.

  10. #10
    jcbmack is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Re: BlueJ IDE

    Quote Originally Posted by Moderator edit: spammer banned View Post
    [Moderator edit: link removed]:BlueJ is a Java IDE specifically designed to learn and teach object-oriented programming and Java.
    Yes it is and I teach students in BlueJ as one of the IDE's and I am required to take courses using it as well. However, I prefer working in/learning in/teaching in NetBeans, jGRASP and Dr. java. I realize that BlueJ is fully functional java, so code from another IDE runs mostly smoothly with the occasional exception, however, I do better with the aforementioned IDE formats. Still, having to learn and teach Greenfoot and BlueJ is overall a rewarding experience. Sometimes I find asking a rudimentary question in a good java forum is better than relying on tired eyes:)
    Last edited by DarrylBurke; 08-08-2012 at 01:12 PM. Reason: Removed spam

Similar Threads

  1. bluej help
    By xpanhol in forum Java Applets
    Replies: 4
    Last Post: 01-29-2012, 12:46 AM
  2. BlueJ - UML
    By Nghi97 in forum New To Java
    Replies: 5
    Last Post: 11-28-2011, 11:03 AM
  3. Need help with blueJ
    By samd89 in forum Other IDEs
    Replies: 6
    Last Post: 12-06-2010, 04:59 PM
  4. BlueJ help
    By Cid17 in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:38 PM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 02:28 PM

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
  •