Java Help NEEDED
Results 1 to 6 of 6

Thread: Java Help NEEDED

  1. #1
    Banned
    Join Date
    Jun 2004
    Posts
    154

    Java Help NEEDED

    Ok in the java course that i am taking i am givin an outline like this:
    Code:
    public class sd {
      //declare a private integer instance variable to store count of diamonds;
      //declare a private double instance variable to store percentage;
      //declare a private String instance variable to store a name;
    
      //construtor bengin here...
    
      public sd() {
      //Initialize all instance vairables to zero;
    }
    
      void Init(String s) {
       //this method initialized the count and percentage to zero and stores the string value in the name     variable
    }
    ............
    
      String GetName() {
      //this method returns the name varialbe;
    Ok so my question is in the Init(String s), how do i store the string value in the name variable?
    Is it something like s = new String(); ?
    Sorry if this is a bit vague, for more info this is the actual lab go here http://www.cs.wright.edu/~rrea/lab1_142.html. Let me know if you need to see my entire code for method and object class.

  2. #2
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    You really need to read your text.

    The variable s is created when the method is called and initialized to whaver value you pass in (unless it is a reference but that is another story).

    To store s into the name variable (after you finally declare and initialize it) you simply use the assignment operator from one to the other.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  3. #3
    Banned
    Join Date
    Jun 2004
    Posts
    154
    I tried s = name, and i didnt get the right string. It came out as some wierd garbage. If you look at the lab, i can get the right output all except for the 'tiny' 'warm' and the other 2 to show up when i do my System.out.print(t.GetName()) or o.GetName(). Sorry if i am a n00b at this and dont get it right away, but i am just learning this stuff.

  4. #4
    Banned
    Join Date
    Jun 2004
    Posts
    154
    ah, I found my problem. It was name = s; Thanks for the help though.

  5. #5
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    Dude, about one third of your posts are Java-related. You do know that there's a huge Java-forum at http://forums.java.sun.com, do you? There's a list of topics that covers most questions you could ever think of. It's not just for professionals, there are fundamentals and new to Java Technologie sections as well.

    I really think you'll profit from asking these questions there, as you'll direct your questions to a topic-related audience at those forums.
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  6. #6
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    You'll also greatly benefit from learning some debugging techniques such as liberal use of print statements, commenting and reintroducing portions of code, and the use of your debugger to step through code and watch variables.

    Especially the last one.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

Posting Permissions

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

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides