Results 1 to 3 of 3
  1. #1
    Big-D is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default BlueJ project need some help with

    Ok, so I've got this program I'm writing for a class and I have it all working except one part keeps baffling me
    Heres the code:

    public class Car
    {
    private int Year;
    private String make;
    private int speed;
    private String Type;
    private String Name;


    public Car (int Year, String carMake, int topSpeed, String carType, String carName)
    {
    Year = Year;
    make = carMake;//brand
    speed = topSpeed;//top speed
    Type = carType;//sports car, luxury, exoitic, etc.
    Name = carName;//Mustang, cammaro, etc.
    }

    public void setYear(int Year)
    {
    Year = Year;
    }
    public void setMake (String carMake)
    {
    make = carMake;
    }
    public void setSpeed(int carSpeed)
    {
    speed = carSpeed;
    }
    public void setType(String carType)
    {
    Type = carType;
    }
    public void setName(String carName)
    {
    Name = carName;
    }

    public int getYear()
    {
    return Year;
    }
    public String getMake ()
    {
    return make;
    }
    public int getSpeed ()
    {
    return speed;
    }
    /*public void AccelerateSpeed (int speed)
    {
    speed = speed + 5;

    }
    public void BrakeSpeed (int speed)
    {
    speed = speed - 5;
    }*/


    }

    So my problem is that I create the object
    BlueJ project need some help with-untitled.jpg

    And then I input all the values
    BlueJ project need some help with-untitled2.jpg

    And when I go to get the value "int Year" it will show the year as "0" even if I go to the object and do "void setYear(int Year)"
    BlueJ project need some help with-untitled3.jpg

    can someone help me out?

  2. #2
    Big-D is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default Re: BlueJ project need some help with

    If anyone replies to this sorry. I feel kinda stupid, I just fixed it, that right there was my problem, public int getYear()
    {
    return Year;
    }
    those parentheses were empty, this is what it should be public int getYear(int Year)
    {
    return Year;
    }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default Re: BlueJ project need some help with

    No it shouldn't.
    That's wrong.

    The reason you weren't seeing the year is:
    Java Code:
    public Car (int Year, String carMake, int topSpeed, String carType, String carName)
    {
    Year = Year;
    That assignment is assigning the Year parameter to itself.
    Either change the name of the parameter, or use this.Year on the left hand side.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. bluej help
    By xpanhol in forum Java Applets
    Replies: 4
    Last Post: 01-29-2012, 01:46 AM
  2. BlueJ - UML
    By Nghi97 in forum New To Java
    Replies: 5
    Last Post: 11-28-2011, 12:03 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
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 03:28 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
  •