CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2010
    Posts
    10

    [RESOLVED] Java help with basic object programming

    have multiple cars print out.
    Last edited by NewToJava1; July 5th, 2010 at 12:53 PM.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Java help with basic object programming

    HOW to do more than one car
    Where is the definition for the Car class?
    I don't see where you create any cars.
    If you had a Car class, you would use the new statement to create new cars.
    Norm

  3. #3
    Join Date
    Jul 2010
    Posts
    10

    Re: Java help with basic object programming

    of the class?
    Last edited by NewToJava1; July 5th, 2010 at 12:53 PM.

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Java help with basic object programming

    what all should i include inside of the class
    What ever needs to be there to define a Car. All the properties of a car that you need.
    Norm

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java help with basic object programming

    So are you saying i need to create a 3rd .java class and call it Car.java or NewCar.java?
    It's normal to give classes a name that describes what they are modeling (representing). NewCar is not a sensible name unless the class can only represent new cars and not old cars which clearly isn't the case as your second car is 1 year old. Therefore, the class should probably be called Car.

    If anyone can help me figure out HOW to do more than one car, because currently no matter what i do it only will add one car, then i would greatly appreciate the help!!
    It's a bit hard to tell you how to do more than one car when you haven't shown us the code you are using at the moment.

    Please post all of your code and remember to use CODE tags when posting the code.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  6. #6
    Join Date
    Jul 2010
    Posts
    10

    Re: Java help with basic object programming

    e: 10
    Color: Black
    Car Price: $18,500
    Last edited by NewToJava1; July 5th, 2010 at 12:53 PM.

  7. #7
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Java help with basic object programming

    How does your code generate the output you want?
    Norm

  8. #8
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java help with basic object programming

    Car Class
    So why is your 'Car' class called 'Cars'. The word 'Cars' implies more than one car but the class is a representation of a single car.

    Your code won't even compile, how can you have run it? If your code doesn't compile you should post the compilation error messages so we can fix those points first. For example: Your main method declares a variable 'aUsedCar' but then uses a variable called 'aCar' which hasn't been declared anywhere.

    Whilst this won't stop the program compiling, you make lots of getXXX() method calls but you don't assign the returned values to any variables so what is the point in calling the methods?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  9. #9
    Join Date
    Mar 2006
    Posts
    54

    Re: [RESOLVED] Java help with basic object programming

    edit: Didn't see that this was resolved.

  10. #10
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: [RESOLVED] Java help with basic object programming

    edit: Didn't see that this was resolved.
    It's not obvious it's resolved (apart from the [RESOLVED] in the title ) because after sorting the problem the OP has gone through the thread and changed all of their posts, so our comments no longer make sense.

    @NewToJava1: please do not retrospectively alter your posts - it makes the thread nonsensical and prevents anyone else learning from your problem.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured