Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javadoc

 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner at Java. I have a project to turn in tonight. I have read what javadoc is... but I am having trouble labeling my program:


Can anyone help me with this? It counts 20% of the grade. And I need to know how for next time.
Thanks!!
 
Ulf Dittmer
Rancher
Posts: 42967
73
 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.. I have read that. And I see what it is.. but I need to actually see the javadoc being used on a project to give me an idea of what and where things go. Kind of like MLA - I had to see examples.
 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also having problems setting my decimals to 2. here is my automobile test...
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. Since you're relatively new I'll add them for you.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what your question is. You said that you're having "problems" but you've never said what those problems are. Can you tell us what you expect to happen and what actually happened? In short: TellTheDetails.

I have a small remark about your code: don't use public non-final methods in your constructor. The reasoning behind this is that extending classes will not be able to use instance variables in their implementations of those functions. The reason behind this is that the super constructor hasn't completed yet. This might be hard to understand (it isn't "Beginning Java" material) but it has to do with the sequence in which an object is build. In your case just use the instance variables directly.
 
Heather Dennison
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Wouter. And no.. i really do not understand.

(1)I need to have the correct javadoc format on this program. And I do not.. @para.. etc.
(2)When I run this program the output of the price amount does not have 2 decimals. I need it to be set to dollar and I am not sure how to.
(3) How do I set instant variables directly?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(2)When I run this program the output of the price amount does not have 2 decimals. I need it to be set to dollar and I am not sure how to.

Take a look at the String.format() method.

(3) How do I set instant variables directly?

You are doing it in your code here:
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heather Dennison wrote:Thanks, Wouter. And no.. i really do not understand.

(1)I need to have the correct javadoc format on this program. And I do not.. @para.. etc.


Because you're in a hurry, I am going to *try* a shortcut for you.

Put javadoc comments, as you have, between /** */.

Put one for the class after the import statements but before the class declaration (public class ...)

Put one for each method just before the method declaration.

Put the tag "@param" in for each parameter used by the method. go to this link

http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javadoc.html#comments

and read it about entering comments; search for "param" and follow a link specifically about writing param comments.

Most java code I've seen doesn't have anything approaching complete javadoc; if a class I'm using has class and method documentation I consider myself fortunate. If it actually matches the code I'm ecstatic. But that may not cut any ice with your class. However, if you're on real short time and want to do it "the industry way", if you got class and method descriptions in place it would look pretty good to me.



(2)When I run this program the output of the price amount does not have 2 decimals. I need it to be set to dollar and I am not sure how to.

Unfortunately, this is going to take a little digging. Your answer lies in the method String.format, in a class called Formatter. Since you're in a hurry, I recommend you google something like "java output 2 decimal places" and hope for the best.
(3) How do I set instant variables directly?


Within your constructor, there is no need to call a method to set the private variable values, you can just assign values to them, like


Hope that all helps
rc
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ralph Cook wrote:

There, I fixed it for you. The @param parameter names should of course match the actual parameter names.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I suppose it's neater that way, but I don't see why the name the programmer uses internally should matter to the name given to the calling programmer. They don't affect him. I mean, as a convention it's fine, but it wasn't broken.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Rob; the parameter names in the documentation comment (the official name for what we always call "javadoc") were different from the names of the parameters. I would personally use this conventionNotice here we are preserving the excellent names of the fields, which I chose after several seconds of hard work blood sweat and tears, and exposing those names to users of the constructor.The overloaded constructor with one argument can only throw a NullPointerException, never an IllegalArgumentException.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ralph Cook wrote:Well, I suppose it's neater that way, but I don't see why the name the programmer uses internally should matter to the name given to the calling programmer. They don't affect him. I mean, as a convention it's fine, but it wasn't broken.

The name used doesn't matter much, but the @param names must match the actual parameter name. It's not a choice, that's how Javadoc works. The method declaration as you wrote it will be part of the Javadoc. If the @param tags then have different names users will not be able to match the two together.

Taking your example, the Javadoc would say that "name" is "what we call this auto". So I check the method parameter list, and I can't find any parameter called "name". Now what?

But I would not use the "given" prefix either. Just use this. like Campbell did.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic