Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Karel the Robot.
#1
So, I decided to learn some java before I go to college.

I'm still a newbie at this, but do I just suck or is it normal to take hours on just one program? It forces me to think, which is good, but I feel like I'm going so slow.

I've been doing:
http://see.stanford.edu/materials/icspmc...-karel.pdf

Number 1 was super easy, number 2 took me a while to figure out how to get it for all the worlds, and I started number 3.

Anyone want to check my work?
 Spoiler

http://see.stanford.edu/see/courseinfo.a...6adcae1111 for the class if anyone cares.
Reply
#2
It's normal to take hours to do one program. Typically a problem of that complexity should take 10-15 minutes for a rough algorithm, another 30 minutes or so to write, and anywhere from 30 minutes to hours and hours to debug Wink

I hate Java though.
Reply
#3
If only you had asked at the beginning of summer when i will have finished learning java. :/

Anyway, yeah, programming takes a long ass time. Even my labs in computer science have me working for hours trying to figure it out.
Reply
#4
Arg. I can't seem to make #3 a general code. I make it work for one world, but the other ones don't work.
Reply
#5
I do not have time to look over the code thoroughly atm, but I'll try to comment as soon as I'm able =)

I'm fairly sure others will agree with me on this, but I would request that you present your java code in [NOPARSE][/NOPARSE] tags. Additionally, make the code inside the methods and for-loops and whatnot indented; a single space is just fine. This is so the code is more readable!

 Example Code

Right off the bat though, I'd say that the goBack method doesn't work as one would assume it would. I mean, why does Karel need to turn left after going back? The main reason I complain is because it can be a bit confusing to others, and who knows, maybe you'll confuse yourself too. The latter will definitely happen if you decide to look at the code a month later or something.

EDIT: For making programs, it takes time. Think about what objects you need, how you'll go about telling the computer what to do, etc. If anything, practice makes you a lot faster with programming. Knowing what kind of standard tools you have also helps. For example being able to use Hashtables for instant data recall as opposed to parsing through a huge array to see if something exists.

Java API
Just look for what you need, don't worry about what the rest of this stuff means, especially if you're not going to use it.
Btw, I don't think you really need to use the API for this particular problem. I just put it up so you can use it as a reference.
Reply
#6
o: Forgot to put it in the code box; it was indented when I pasted.

Is it better now? I moved the turnLeft to the nextColumn.

 Spoiler

Yeah, I'm saving the harder stuff for later and just going to follow the class now. The class learns Karel first, then eventually transitions to Java (I haven't gotten there yet). I'm still trying to figure out how to make 3 work x___X
Reply
#7
Kiley Wrote:
 Spoiler

Yeah, I'm saving the harder stuff for later and just going to follow the class now. The class learns Karel first, then eventually transitions to Java (I haven't gotten there yet). I'm still trying to figure out how to make 3 work x___X

Red: The while loops in the run() and fixWall() methods are redundant. You should change one of them to an if statement instead so the computer doesn't end up checking the while loop condition twice. In this case, I would change the one in run() to an if statement.

Purple: fixWall() has a pretty bad issue. Let's say you are fixing the column and you are checking if there's a beeper there. There isn't one. Then in your else statement, you put a beeper there. Then you run the while loop again, and you find out there is a beeper there. That's because you didn't move. If a column was entirely devoid of beepers, then the run time on the fixWall() method would be roughly twice as long. You don't want that. A simple solution is to include a move() method in the else statement too, so instead of just putting a beeper there, you also move after you put a beeper.


Also, with the nextColumn() and turnLeft() thing, I'm questioning the convention on that, but I think it might be passable.
Reply
#8
:x I didn't even think about the purple.

I still have so much to learn just on the basics D:
Reply
#9
I don't think doing this exercise helps you to learn java as much as if you started making mini applications. i.e. spell a word the user inputs backwards.

All this is doing is calling predefined stuff. You're really doing just basic if-else and some loops.
Reply


Forum Jump:


Users browsing this thread: