Mike Tyler

Greenhorn
+ Follow
since Jan 13, 2015
Merit badge: grant badges
For More
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Tyler

Piet Souris wrote:If you look at the code in your opening post, the only thing that was missing
was in the 'else' branch. You needed a new value for the variable 'answer',
in order tp prevent getting into an infinite loop, in case the original 'answer'
was not 'y' or 'n'.



aah, yes... now I see what you mean

So after a bit of work, I got it working seamlessly.. here's the code (just fyi)


Thanks for help
9 years ago
thanks for all the response guys

Piet, I find the book very useful indeed, and also see the authors reasoning behind writing TextIO. However I don't like the fact that we are using something that is not going to be applicable in practice. But ye, it probably doesn't matter too much as it's only output and input. I still use Scanner everywhere else.

And sorry, I didn't quite get your solution.. what do you mean by 'or' ?


Junilu, you mean something like this ? (it's not a new method, I just want to make sure I did get the logic right. Because I think I don't understand your code completely



Just as a sidenote.. initially, I had the while condition without the !. I know the do-while loop is more commonly used with an expression (like x > 20) rather than boolean value. But I have to keep in mind, that unlike in a while loop, here, the condition has to be false instead of true.

/edit: this was a response to your previous post...
Wish I could use 'quote' within the reply window.

9 years ago

Junilu Lacar wrote:This wouldn't happen to be the same TextIO class you're using would it? http://math.hws.edu/javanotes/source/chapter10/TextIO.java


exactly I'd much rather use just standard System, but it's for a class project where we have to use it..


Junilu Lacar wrote:

Piet Souris wrote:For me, the code looks clear. True, it seems a bit sparse when it comes to
user communication, but apart from that...


Ok, assuming my sensitivity to code smells is just getting the best of me... or maybe I'm just not as forgiving as Piet.

I have reformatted the code to make it easier to read. Without making the assumptions that Piet has made about how this TextIO class works, I don't see where the variable answer, which I assume is a String, gets another value such that the loop can terminate. I don't see why there's a need to set the variable loop1 since it has no effect on anything inside this loop nor does it control the loop iteration.

I was thinking along the same lines about TextIO.putln() maybe having some way of getting user input but decided otherwise because of line 5. If the variable path is intended to be what its name implies, and based on the surrounding code, I would say that the putln method did not provide a way for the user to enter something. But I could be wrong.

Finally, I don't see why Mike would say "obviously, I need the loop to run 1 more time, after the last else statement" because if the last else statement were to be executed, then the loop would actually be executed at least one more time. Which brings me back to the question of "How does the variable answer get another value?" because without that happening, the if-else-if-else would just put you back in the last else and you would get into an infinite loop. Is that what's happening?

So, no, it's not really clear to me what exactly is happening unless I stretch my imagination and speculate about what this TextIO class is doing.



ye, I apologize.. should've made the problem a bit more clear and explain it. I was also in a rush when I was writing it..
The code was taken straight out of the whole program... so regardless of any variables, or output used.. Here's what I need the method to do:

1. ask user for input
2. if it is X, do action1
3. if it is Y, do action2
4. if it is something else (invalid input), let the user to enter it again (go to step 1)
9 years ago
So I've got this little issue, where I am checking for user input.



I think i's pretty obvious from the code.. obviously, I need the loop to run 1 more time, after the last else statement. Can't think of a good way to do it, although I am sure it is really simple...
The boolean value t is there just experimental and doesn't do anything (from the logical standpoint).

Thanks
9 years ago
ok, thanks for that..

Refactor would work quite well in theory.. However, it doesn't allow me to rename/move already corrupted (changed file paths) projects.
What's even more strange, when I rename the actual folder containing the project files and restart Eclipse, it still doesn't work. I wasn't expecting this.
So I am stuck with non-working projects that I am unable to open.

Anyway, for future use, I will need to refactor the projects to the desired path first and then change my folder structure in Windows explorer..
Hey,

is there a convenient way to change the resource path in Eclipse? I've found this quite irritating from the time I started using Eclipse.. when I change the path/name of the folder of an existing project, it just fails to open in Eclipse. This is absolutely understandable of course, but there should be a way to change the paths..

After opening properties from a project (which path is corrupt), this is the only thing I get...
I don't understand why I don't have the option to modify the path.

Thanks for help.

Stefan Evans wrote:Using a source control tool like git/svn would do what you are after.
Eclipse also maintains a "Local History" of changes to files. You can compare your current version against any version in the history, and recover the old one if you so wish using "Replace With"
Just right click any file in your project and look at the "Compare With" and "Replace With" options in the context menu.



this is exactly what I had in my mind.. thank you!
9 years ago
Thanks for all the input.
As you mentioned, I believe git would be quite a useful tool in a corporate environment, within a production team.

I am just starting out and don't intend to be a professional coder (hopefully ). But I might give Egit a go when I have some spare time...
9 years ago

Paweł Baczyński wrote:Get familiar with one of version control systems available.
I believe the most popular one right now is git.

Object serialization will allow you to save a state of an object, not a source code.


ok, thanks. It also seems to be kind of complicated, but I'll try to look into it some more.
9 years ago
Hey guys,

recently I was playing a lot in Eclipse, testing util classes, randomisation etc.
But always when I wanted to keep something for future reference, I had to either comment it out or start a whole new class, copy all the code and change just that little thing I was testing.

I was wondering if it's possible to actually save just the 'current state' of the code. The idea came back from my days when I was working with 3ds max and I saved the scene periodically so I could revert back anytime I messed up something.

I was looking into Object Serialisation and JUnit testing for this purpose, but that's just too complicated.

Is there a way in Java (Eclipse) to accomplish such thing?

9 years ago

Stefan Evans wrote:


exactly! that's my second issue.. I am not really sure how to make the game 'adaptable' (forgot the correct term for this, but I know there is one :P ) - where it's all built based on dynamic variables that the user can change at the beginning, rather than working with set numbers and strings.

I need a little break and then will give it a go one more time.. my knowledge of Java is still quite limited, so I always end up just staring at the code blankly, feeling miserable
9 years ago
Thanks for the response Fred.

You are absolutely right.. maybe I have just formulated my question badly. I have actually thought about this quite a lot so I know exactly what the program needs to be doing. It's just that I don't know about the different means in Java to accomplish it, so I was doing a lot of research on getting the data structure I want - 3 poles (A, B, C) with 3 disks on the pole A (small, medium, large). The goal of the game is to move all three disks to pole C according to the rules of the Hanoi towers (which I am sure you're familiar with).

I didn't manage to successfully use an online compiler for the code, so here are just screenshots of some errors from Eclipse:
The validation for the 1st user input runs alright (only s, m or l letters are accepted) but then crashes:


Here, the move is valid (taking the topmost disk from pole A to B) but it shows an error message and then doesn't even let me enter another input. (there is also an output of some of the variables - target shouldn't be null obviously)
9 years ago
Hey guys,

so I've got this game to code in Java. I don't need to come up with the actual recursion algorithm to solve the game as usual. Rather, the program has few simple steps:

- set the number of 'poles'
- set the number of 'disks'
- check for the current state of disks on poles
- ask for input - which disk and to which pole does the user want to move it
- validate the input against the rules
- if validated move the disk based on input, else return an error
- check for the current state of disks on poles
-repeat until solved

I am kind of new to Java. I managed to write this code with the help of my friend. I spent a lot of time on it, doing some prior research. I planned on using stack as this is an obvious example of it. But there's a lot of different ways to handle data structures in Java.. I've seen there are several types of arrays and stacks in and there isn't probably a single 'easiest' way to do it. Now my friend advised me to use a hashmap and a deque. Supposedly a deque is more advanced than a stack.

I am stuck at at point where if you run the code, it fails to validate the input for the target pole (A,B or C). I think there's an error in the validatePoleName method, but I am unable to correct it..
Also, in what way is using a hashmap and a deque more convenient than using a stack? Could I use an ArrayList that would act as a stack for this purpose?

Here's the unfinished code:
9 years ago