This discussion is archived
1 2 Previous Next 15 Replies Latest reply: Nov 18, 2012 4:27 PM by EJP RSS

Objects and

968909 Newbie
Currently Being Moderated
I am trying to write the code you would need to create an object of type Example, and then call its method setValue to inititalize it.

This is what I have so far and I am a little lost.
Any help would be great!
Thanks!

class Example
{
int a;

public void setValue (int x)
     {
a = x;
}
public void print()
{
System.out.println(a);
}
}
  • 1. Re: Objects and
    Kayaman Guru
    Currently Being Moderated
    SunshineJava wrote:
    I am trying to write the code you would need to create an object of type Example, and then call its method setValue to inititalize it.
    So this is a school assignment of some sort?
    This is what I have so far and I am a little lost.
    Then off you go to the Java Tutorial. You'll learn all the basics and more from there!

    http://docs.oracle.com/javase/tutorial/getStarted/index.html
  • 2. Re: Objects and
    Kayaman Guru
    Currently Being Moderated
    I don't understand. I looked at your earlier posts and you seemed to know how the basics work. Now you act like you don't know how to create an object?

    Or have you just asked for help and blindly copied the code that other people give you? Not a good way to learn.
  • 3. Re: Objects and
    gimbal2 Guru
    Currently Being Moderated
    Kayaman wrote:
    Or have you just asked for help and blindly copied the code that other people give you? Not a good way to learn.
    Its a good way to not learn.
  • 4. Re: Objects and
    968909 Newbie
    Currently Being Moderated
    Yes it is a school assignment. Yes I do understand the basics. Yes I don't appreciate the smart a$$ answers.
    This is code that the teacher gave us and sometimes I just don't understand what he is asking. Yes I could go ask the teacher, but its an online course and sometimes its days before I get an answer. I was hoping that someone here might be able to lend a hand. I don't want anyone to write it for me but to help me to understand. In the past he has given us examples which has helped. In this situation this was all that was provided.
    If you have thoughts or ideas, direction = great. If your going to be a smart a$$ = keep your comments to yourself please.
    The last thing I want is for anyone to DO my work.
    thank you
  • 5. Re: Objects and
    gimbal2 Guru
    Currently Being Moderated
    SunshineJava wrote:
    Yes it is a school assignment. Yes I do understand the basics. Yes I don't appreciate the smart a$$ answers.
    Oh dear. I'm sorry but... you're going to get them! Over and over and over and over and over.

    Until you start asking questions that don't warrant them.
  • 6. Re: Objects and
    Tolls Journeyer
    Currently Being Moderated
    You need a class with a main() method.
    You know about those because at least one of your prior posts has code in it that has a main() method.
  • 7. Re: Objects and
    Kayaman Guru
    Currently Being Moderated
    SunshineJava wrote:
    Yes I don't appreciate the smart a$$ answers.
    Well we don't appreciate dumba$$ questions, but it's not like that has done any good.
    This is code that the teacher gave us and sometimes I just don't understand what he is asking. Yes I could go ask the teacher, but its an online course and sometimes its days before I get an answer. I was hoping that someone here might be able to lend a hand. I don't want anyone to write it for me but to help me to understand. In the past he has given us examples which has helped. In this situation this was all that was provided.
    I was going to help you. I immediately saw that it's clearly an assignment, but I was willing to provide some gentle hints towards the right direction.
    Then I looked at your previous posts and became confused. You hadn't learned anything from them. You obviously don't know what the main method is for. You don't seem to know how to create an object. Even though in all your previous posts you seemed to be able to do them. That's when I noticed that you were just copying people's code and not understanding what you're doing.
    If you have thoughts or ideas, direction = great. If your going to be a smart a$$ = keep your comments to yourself please.
    You can't control who comments, just like we can't control who asks questions, so don't bother crying about that.
    The last thing I want is for anyone to DO my work.
    Then make an effort. Explain where you're stuck, what you've tried and so forth. Just dumping your assignment and saying "I don't know what to do" sounds a lot like you DON'T want to do your work.

    I gave you the link to the Java Tutorial. If you can't bother to read that, don't bother continuing with Java.
  • 8. Re: Objects and
    gimbal2 Guru
    Currently Being Moderated
    Kayaman wrote:
    I gave you the link to the Java Tutorial. If you can't bother to read that, don't bother continuing with Java.
    That is actually a harsh lesson that is very true. If you can't EVEN be bothered to study this stuff and try to understand it yourself - give up now. Java programming (and software engineering as a whole) is difficult and requires constant personal development and expansion of knowledge of not only technical skills but also that knowledge which you need to apply software engineering to a specific field (finance, marketing, science, whatever); in other words it takes up a huge chunk of your life and if you want to be in any way competitive: your free time as well.

    You're always reading, always studying, always taking part in discussions, visiting events, contributing to open source stuff (even if it is only reporting bugs), busy busy busy busy. this is not a field of work for people who want to get by doing close to the minimum.
  • 9. Re: Objects and
    968909 Newbie
    Currently Being Moderated
    I have never copied anyones post or code.
  • 10. Re: Objects and
    968909 Newbie
    Currently Being Moderated
    And I have read the oracle java docs and every piece of documentation that he has given us.

    So if we can be a little more mature...

    So I need a main. Okay. That is one of those things thats obvious but I over looked it.

    I will add a main and get back. Hold please....
  • 11. Re: Objects and
    Tolls Journeyer
    Currently Being Moderated
    SunshineJava wrote:
    ... Hold please....
    Great.
    Now I have The Girl From Ipanema going through my head.
  • 12. Re: Objects and
    968909 Newbie
    Currently Being Moderated
    So after finally hearing back from the teacher all he was looking for was to create an object. I still have some trouble understanding objects and classes but I am sure it will get easier.

    Answer:

    Example ex = new Example();

    call setValue now:

    ex.setValue(5);

    Thank you all for you input :-)
  • 13. Re: Objects and
    rp0428 Guru
    Currently Being Moderated
    >
    I still have some trouble understanding objects and classes but I am sure it will get easier.
    >
    Then you might want to go through the Classes and Objects section of the Java Tutorial
    http://docs.oracle.com/javase/tutorial/java/index.html
    Classes and Objects describes how to write the classes from which objects are created, and how to create and use the objects.
  • 14. Re: Objects and
    968909 Newbie
    Currently Being Moderated
    Thank you - I have read them. Its just going to take me some time to understand. Funny I have no problem with C++
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points