This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!

Susan Delph

Ranch Hand
+ Follow
since Feb 24, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Susan Delph

I wrote a short program to test these. Here are the results.
Options a,b,c all give compiler errors:

I got rid of these lines. The program then compiled OK, but gave me NumberFormatExeception on the line:
Long l = new Long("42L");
So I changed this line to read:
Long l = new Long("42");
The program then compiled and ran. The remaining tests all gave 'false' results:
d) i.equals(d);
e) d.equals(i);
f) i.equals("42");
Ravindra's message explained why these gave 'false' results.
Susan

[This message has been edited by Susan Delph (edited May 22, 2001).]
Mike Curwen gave an excellent example.
Here's a graphical representation:

So, if I were writing the Subclass1 code, and I wanted to refer to a variable or method from the Superclass, I would refer to them as super.variable or super.method().
This is exactly what Mike did with the line:
System.out.println("Value in SuperClass: " + super.value);
Susan

[This message has been edited by Susan Delph (edited May 22, 2001).]
18 years ago
As Cindy said, it's really tough to tell without seeing the code. (Especially for me, since I'm a Java Newbie!)
But if this is the line causing the error:
Console.run(new Village(),500,500);
1) Do you have a method called 'run', that accepts these particular parameters?
2) Do you have a method called 'Village'?
If the program is long, perhaps you could post just the relevant sections of code?
Susan
18 years ago
So then... why isn't b = one more?
I added some println's to the code:
This is the output I got:
In swap: a= One, b= Two
End of swap: a= One more, b= One more
a is One more
b is Two

Does it have something to do with the append() method, versus using b=a?
Susan

[This message has been edited by Susan Delph (edited May 11, 2001).]
I'm not a Java Guru, but I'll take a guess at your second question.
When you perform a method, you only pass references to variables - not the original variables. And then you don't automatically pass the values back to the originating method.
While you're performing method swap(), you have variables 'a' and 'b' -- but these are NOT the same as the 'a' and 'b' used in your main() method. They're just copies, and never get returned to the main() method.
Here, this might help:
main()
a = one
b = two
swap()
copy of a (also named a) = one
copy of b (also named b) = two
THEN:
copy of a = onemore
copy of b = copy of a = one more
THEN you return to main() -- but the copies (a and b) are gone. And you have only your original a and b which are STILL:
a = one
b = two
Someone please correct me, if I'm wrong about this....
Susan

[This message has been edited by Susan Delph (edited May 10, 2001).]
Well, I couldn't resist....

File test1.txt:
abcdeX
File test2.txt:
abcdZ
Printed on my screen:
abcdeX
abcdZ

I don't know if this is the most efficient/best way to write this -- but it DID check my record from file#1, and when it didn't see a Z, it went and opened the second file....
You'll have to adapt this so that rather than printing to System.out.println, you print to your new output file.
Susan

[This message has been edited by Susan Delph (edited May 10, 2001).]
18 years ago
Hi Jake,
Let's see if I'm understanding this:
First Record:
012345X.....
Last Record:
01234Z....
And sometimes, the file doesn't make it all the way to the last (Z) record.....
Why not add a check on your last record to see if it contains a Z in the 5th position?
This isn't "code" - more of a description, but you could develop the code from it:
while(still records)
{
process them as usual
}
//no more records, but the last one will still be in the "buffer"
if (buffer.charAt(5) == 'z') -> close the file //we have all the records
else {
open Punch002 and read the records in
}
Susan

18 years ago
Seema said, "but I think I am still not clear about the concept."
In this scenario, you ALWAYS get to the System.out.println statement:
finally
{
System.out.println("Inside finally");
}


But here, if you throw the exception, you won't reach the println - and that gives you the compiler error:
finally
{
throw new IOException(); //IF I EXIT HERE, I WON'T REACH THE NEXT STATEMENT
System.out.println("Inside finally"); //I MAY NEVER GET HERE!
}

It's not really an issue of 'finally' executing differently. For example, I bet you could get the same type of compiler error if you used break statements, or had something in some if-else logic that kept you from reaching a statement.
For example, this would probably give you the same unreachable statement error:
switch (something)
case 1:
break;
++x; //Will never get here. Should give an error.
case 2:
break;
Susan

[This message has been edited by Susan Delph (edited May 10, 2001).]
Well, I'm a real OO beginner, but here goes:
Objects:
- The screen
- User ID
- User Password
Methods:
- get information (ID and password)
- validate information (ID and password)
- handle invalid information
- Exception and Error methods (for example, if no info is entered in a field)
- allow valid user to proceed to next screen
- keep invalid user from proceeding, and give them 'error' messages so they know what information didn't "pass".
Also, you'd need to use something to keep multiple users from stepping all over one another. Threads maybe???
Ah, this is tough, isn't it? I don't think OO'ishly.
I look forward to seeing what the experts say!
Susan
18 years ago
Actually, dump my above suggestion. This is better -- in my opinion:

It printed out 'true' when I ran this.
Susan

[This message has been edited by Susan Delph (edited May 09, 2001).]
18 years ago
I'm definitely NOT a Java Guru, but....
lastIndexOf('z') will find the last occurrence of 'z' in the String.
int index = sBuffer.lastIndexOf('z');
This will search the String backwards, and index will be set to whatever position the final 'z' of the String is found in.
(If no 'z' is found, index is set to -1, as Richard explained above.)
Susan

[This message has been edited by Susan Delph (edited May 09, 2001).]
18 years ago
Passed assignment #2 -- BUT my hard drive crashed.
So, it may be a few days before I'm able to write the next assignment. (insert scream here). I'm PC-less at the moment....
So:
Assignment: Java-3
Name: Leap
Attempt: 0

I never thought I'd be submitting attempt #0, but.... Oh well.
Susan

[This message has been edited by Susan Delph (edited May 06, 2001).]
18 years ago
Try running your program using this:

java -classpath . a1

The -classpath . specifies "look in THIS directory for a1".
Susan
18 years ago
Bosun gave a nice definition. Here's an example:
You've probably seen:
int x;
This creates the integer variable 'x'.
But you could also use an Integer wrapper, so that 'x' is treated as an object:
Integer x = new Integer();
From the Sun documentation:
"The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int. "
There's a wrapper class for each primitive type.

Susan
[This message has been edited by Susan Delph (edited May 06, 2001).]
18 years ago
You can use the following to specify 'THIS' directory:
java -classpath . File
Replace File with the name of your program.
P.S. You said it compiled OK, but if you ever need to, you can also compile specifying 'THIS' directory:
javac -classpath . File.java

Susan
18 years ago