Win a copy of Head First Android this week in the Android forum!

marcus conway

Greenhorn
+ Follow
since Oct 30, 2008
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 marcus conway

Originally posted by Ulf Dittmer:
No, chars work fine in switch statements. Ask yourself this: Suppose getFace() returns 't', causing "val = 1;" to be executed. Now, what is the next statement that gets executed? And consequently, which value of "val" will be returned from the method?



how bout this?
13 years ago

Originally posted by Ulf Dittmer:
That's in a loop, so I'd assume that the loop is executed repeatedly. Check whether the loop termination condition works as you expect it to.

By the way, I'm almost positive that the getValue method does not work as you expect it to work. You may want to read about the "switch" statement, and what happens once one of the cases is matched.

Lastly, in the future UseAMeaningfulSubjectLine that states what the problem is.

[ November 17, 2008: Message edited by: Ulf Dittmer ]



Is it because I'm using the getValue() switch statement on chars?

Thanks for your help
13 years ago
Hello,

Can someone tell me why--after i create a cube--it display 'enter test operation' twice?



[ November 17, 2008: Message edited by: Bear Bibeault ]
13 years ago

Originally posted by marc weber:
I'm not sure what your question is, but your code above is not doing anything with the String returned by scan.next(). I'm guessing you'll want to assign these to some variables so that you can pass them to a Cube constructor.



Yes, thats correct. I want to pass them to the ...
Can you explain how to pass the two variables to parameters?


Thanks a lot
13 years ago
Hello,
I have a method:

What I'm trying to do is obtain input from the user and set their input as the 'String id' parameter in the above Cube(String id, String faceValues) method:

13 years ago

Originally posted by Ernest Friedman-Hill:
Not sure there's anything "unique" about this problem!

next() just returns one whitespace-separated token; the ints would be the next few tokens, not part of that first one. You can call next() twice more to get each additional token in turn as two more strings; or you can use nextInt() instead, to return the next token as an int (which is most likely what you'll want to do.)



Yeah I know that. But what if the user inputs, lets say, 'drop'? Won't the scanner be waiting for two ints as well?
13 years ago
Hello,

I'm have a scanner 'String str' that scans user imput via . The user has to input one of choices from this menu:

I have a series of 'if' and 'else if' statements to decipher the user's input:

...As you can see, I can't figure out how to make the scanner differentiate between a string (get, drop, etc.) and a string with two ints after it(go # #). The user should be able to input 'go # #'(replacing the two #s with integers).

How should I go about doing this? I've been playing around with 'StringTokenizer', but to no avail.

Any help would be greatly appreciated.
Thanks,

n
[ November 06, 2008: Message edited by: marcus conway ]
13 years ago

Originally posted by Campbell Ritchie:
You're welcome.

But try while (fileScan.hasNextLine()) . . .
It is much less error-prone than counting the lines.



Yeah, I know what you mean. But the problem is that I'm going to have to be reading each String (first name, last name, and salary) one at a time and invoke various methods on each string. So i kind of need the line to be broken up; I don't know how to separate a whole line into three different ones .hasNextLine().
13 years ago
Hey,

I'm having some trouble creating a method (in the form.....
)

that positions string s in a field of a desired width. If the string is longer than the desired field width, it will need to be truncated. If it is shorter than the desired field width it will need to be padded with blank characters. The alignment parameter determines whether the string will be left aligned ('L' or 'l') in the field (padding added to the right) or right aligned ('R' or 'r') in the field (padding added to the left). And if there are not enough spaces to display the string, at least one space must be provided on the appropriate side.

I've been playing around with it:



And I've been testing it in various ways. But ultimately the I/O should look similar to this:


I've been struggling with this for quite some time now, so any help would be greatly appreciated.

Thanks,

n
13 years ago

Originally posted by Campbell Ritchie:
Welcome to JavaRanch

Have you looked up NoSuchElementException and Scanner? Notice what it says about when a Scanner can throw a NoSuchElementException.

You need to alter the for loop. Get a pencil and paper and count how many times it repeats.

Probably not a good idea to use a for-loop which depends on counting lines. There are methods in the Scanner class which tell you whether you can read a next token. They will fit nicely into a while loop, then you can read a file of any size.




haha I just read your reply after I figured it out. Thanks for responding so soon.
13 years ago
And would you look at that; I figured it out.

I deleted a line of the employee.dat file (making it so there's only 9 lines), and I had a loop that would run 10 times. So I just switched the line in my for loop from to .

I'm sure I'll be coming to the saloon more and more often.

Thanks
13 years ago
Hello all,

This is my first post at the saloon. I've been writing a program that puts data from a .dat file into a table that I formatted. It's been going smoothly so far but recently I have been getting this error message and I don't know what it could be from.

Here are the two classes that are involved with it.




and here is the text in the data file (employee.dat)...



Any help would be greatly appreciated.

Thanks,

n
13 years ago