Mike Stein

Ranch Hand
+ Follow
since Aug 29, 2014
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
22
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Stein

All,

Thank you so much for the explanation. I understand if statements much better now. It didn't occur to me that the if statement would only fire what was inside the brackets unless the value was true. Again, thanks for the help! You guys are the best!
4 years ago
Hi Ganesh,

Thank you for this explanation! It really does help to clear up some of my confusion. Just one more quick question, why, if in your example as in mine the non initilazied variable is set to false, does this code snippet not execute?



What it is effectively saying is "if flag is false print the following sys.out statement", but it doesn't execute even though the flag variable defaults to false. This bit I don't understand.
4 years ago
Hello,

I am having a bit of trouble understanding how booleans work. In the code snippet below I have a boolean variable that is not defined. I have read that when booleans are not defined, they default to false.


I am confused by the if statement. If booleanTest is false, why then does the sys.out statement in the if-statement print when I run this code? Wouldn't booleanTest have to be true in order for this statement to print? I never set booleanTest to true so I don't understand why it is printing what is in the if-statement. Could anyone explain to me what is going on?
4 years ago
Paul,

Thank you so much for the insight. I am going to try to implement the approach you suggested. Will let you know how everything works out!

Thanks again.
5 years ago
Hi,

I need a bit of help trying to figure out an issue I'm having with my program. If I run my program as is in my IDE (before exporting it to an executable JAR) I am able load in a txt file with some values, modify that file by making a temporary copy of it, and then renaming the modified file to the name of the original or source file. However, when I create my JAR, I am only able to load in the original file. There is no way, apparently, to do a write to the source file because the JAR essentially locks down the text file I need to modify.

Now, my question is how can I simulate this copying of the source file, modification, and then renaming of the modified file to the original? Am I thinking about this all wrong? Here is my code I'm using thus far (the deleteFromFile method is where I am stuck in terms of getting this to work with my JAR):

5 years ago
Hi all,

I am having some issues trying to format my milliseconds to mm:ss format for this little tea timer I'm making. The TimerListener constructor takes in a double which is the milliseconds I'm using for my countdown timer. I then convert that counter variable to a long for I can use it with TimeUnit. However, when I add the hms variable to my JLabel the timer only counts down one second. If I add in the counter variable or the formatTime variable the countdown works fine, but it isn't in the mm:ss format I want. Any help would be greatly appreciated as I am a bit lost at this point.

5 years ago
Hello, I am having trouble trying to figure out how exactly to setup my program to implement resource pools. If anyone could help me out I'd greatly appreciate it. I am confused about what to use and how to use it. Should I use Semaphore class, reentrant lock, etc. My program is a bit long and starting to get complex. I really need some one on one tutoring. If anyone is up for it please message me. It would be nice to use Skype or something to communicate in real time.
I have a new problem that I can't seem to work out.

I have to move the additional information in my data file (the middle initial in this example) to a separate array list. However, I keep throwing the following exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4

This is what I have tried but it doesn't seem to be getting me anywhere:










6 years ago
Greg,

Sorry, I am a complete fool. I had my printArray call inside of my while loop. I called the printArray method after the while and got the following output (NO MORE DUPES!):








6 years ago
Greg,

The assignment gives no direction on how to read in a file or what to use. The only reason I went with Scanner is because I have a vague familiarity with it. Never used BufferReader or LineNumberReader. That being said, I went ahead and toyed with Scanner a bit more to see if I could make some progress. Sadly, I've just managed to confuse myself even more! I am adding data from the text file to an array, but now, I have duplicates and data that should be on separate lines appearing on the same line. It is all a mess.

This is what I've tried and the output that results:


Output:








1001 Hank Jones

1001 Hank Jones 1002 Tom Smith

1001 Hank Jones 1002 Tom Smith

2001Java Programming1001 Hank Jones 1002 Tom Smith

2001Java Programming2002 Advanced Java Programming


The output is preceded by a sizable empty space.

Any ideas how I could remove the duplicate information?
6 years ago
Greg,

I tweaked the code a bit. Now I am able to get rid of the commented lines, but I still have the colons.



Output looks a bit better:

a : 1001 : Hank : Jones : M
a : 1002 : Tom : Smith : R
b : 2001 :Java Programming
b: 2002 : Advanced Java Programming
6 years ago
Hi Greg,

Thank you for the quick response!

You're calling nextLine() twice per iteration of the loop



Totally missed that!

How about changing the System.out.printlin() parameter to use the line variable, instead of reading a new line from the Scanner?



Okay, I changed the Sys out line to System.out.println(line)

However, that yielded the following output:

//commented text
// more commented text
// even more comments
// Author format:
// a:<index>:<first name>:<last name>:<middle initial>
a : 1001 : Hank : Jones : M
a : 1002 : Tom : Smith : R
// Book format:
// b:<index>:<title>
b : 2001 :Java Programming
b: 2002 : Advanced Java Programming


Looks like my delimiters aren't doing anything now!
6 years ago
Hello,

I am hitting a bit of a snag trying to parse a data file. I have a text file with the following format:

Input.txt

//commented text
// more commented text
// even more comments
// Author format:
// a:<index>:<first name>:<last name>:<middle initial>
a : 1001 : Hank : Jones : M
a : 1002 : Tom : Smith : R
// Book format:
// b:<index>:<title>
b : 2001 :Java Programming
b: 2002 : Advanced Java Programming


The text file above features varied spacing on purpose (for the sake of this project, I must assume that I don't have control over the text files, and therefore, I must account for random spacing).

Goals:
I need to read the text and do the following:
*skip over commented lines (//)
*skip colons
*handle white space
*accept spacing between title names (e.g. Java Programming)
*ignore any extra data.
In this case, the extra data that I need to ignore is the middle initial data. I would like to be able to ignore more data if need be.

I would like the output to look like this:

a 1001 Hank Jones

Ultimately, I'd like to pass this data into an array list. However, I won't even entertain that idea until I can sort out reading the file.

Any help would be greatly appreciated.

What I have so far only ignores at random (so it seems) and is throws the following exception:

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at TestFileReader.readFile(TestFileReader.java:30)
at TestFileReader.main(TestFileReader.java:41)

Please keep in mind that this java class is just a test class (it isn't meant to look pretty just trying to get the basic idea behind delimiters):


Output:

// more commented text
// Author format:
a : 1001 : Hank : Jones : M
// Book format:
b : 2001 :Java Programming
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at TestFileReader.readFile(TestFileReader.java:24)
at TestFileReader.main(TestFileReader.java:37)



6 years ago
Okay, so this is what I finally came up with for the linked list. I am still learning so I am well aware that my code isn't as clean or efficient as it should be. If you guys could look it over and possibly give me any suggestions to make it look and work better that would be fantastic. Also, thanks guys for the tips. I found that stepping back and writing down the nodes helped me to visualize what was going on.

6 years ago
For the program I have to create, I need to be able to work with the elements of a circular doubly linked list to do the following:

Find an element in the list (specified as an argument)
Insert an element after a specified element (specified as an argument)
Delete an element (specified as an argument)
Display the elements in the list

I can insert elements and display the elements, but I can't figure out how to search for an element, insert an element after a specified element, or delete an element.

What I am having trouble with is passing the elements in the list as arguments for searching, deleting, inserting after an element.



If anyone could give me some insight into how to solve my issues, I would greatly appreciate it.
6 years ago