Re: Need basic help....
Lew wrote:
TheBigPJ wrote:
Final. Another other advice?
Overall it looks good.
---------------------------------------
import java.io.*;
I never import whole packages. To me it isn't clean. I'm not sure if
everything really is included, but anyway I think it's overkill. Also.
if that package happened to have a class with a name you also use it
gets messy.
Actually when it's used as little as it is in your code, you might just
as well type the whole package name in the code and remove the import.
On the other hand, an import shows immediately what external classes is
used. Forget what I said, keep the import :p
class Q4 {
private char a;
private boolean charIsSet = false;
Again, you keep this class name that tells nothing about what this class
is. Since it stores a char only the name should reflect that it has to
do with a char. I'm guessing Q4 might relate to your assignment. Make a
project/package that tells you what assignment it is instead.
You actually don't need this explicit initialization, since member
booleans initialize to false anyway. Naturally you have to initialize
local variables, but instance and class members initialize to
"zero-like" values (0, 0L, 0F, 0D, false, null).
I'd say initializing is a good practice nevertheless, if not time
consuming. I wouldn't place them there though. Initialize them in the
constructor(s).
*snip*
else if(temp.equals("2"))
{
if(m_charIsSet() == true)
{
System.out.println("You char value is: " + (int)this.returna() +
"." + savea() + "\n\n");
}
else
m_charIsSetErrorMessage();
You forgot the braces for this else body.
According to the Java code convention (I read it last night :p) it
should be done so. Personally I think it's "cleaner" to rid of
unnecessary braces, but good practice is good practice.
*snip*
public boolean m_charIsSet()
Do not use underscores except in constants' names. What is "m",
anyway? Most languages that use an "m" prefix use it to indicate a
member variable, but this is a method.
Ugh I hate such things. Use whole words only I say.
By convention, methods that access a boolean property "X" are called
"isX()". This also helps certain auxiliary tools. It's part of the
JavaBeans pattern.
Yep;
public boolean isSet() { ... }
{
return charIsSet;
By convention, but weaker than the other conventions, a boolean variable
is either an adjective ("alreadySet"), or an adjective preceded by "is"
("isSet").
Naming it char is quite pointless - this class only store a char so it's
logical that it's about a char.
*snip*
public boolean m_gt(char newChar)
public boolean gt( char other )
I avoid "new" as part of an identifier because it's a keyword, unless
it's really the right word. There's nothing "new" about "newChar", so
it isn't. Also, it's usually best to avoid putting implementation
details (like Char) in variable names. Here the "charness" is part of
the problem domain so it's not as bad.
Good point. "char c" would be sufficient and preferable.
[snip]
Damn TAB characters! Half my time writing this response was snipping
out the TABs.
Ah, the TAB-discussion again. I was looking through the settings in
Thunderbird myself, but so far I found no option to convert tabs to
spaces D: