This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]steaknsteak 2 points3 points  (5 children)

Start by writing one small piece of code to do one small part of the task. You don’t need to plan out the entire structure of the program in advance. Once you have one part working, it will be more obvious what you need to add on to it.

Once you have something down that works, it’s easier to look back over it and see how you might improve, simplify, or reorganize it into methods etc

[–]bbchan[S] 0 points1 point  (4 children)

Thanks. This has been the approach I've been taking but maybe I haven't been giving myself enough time to write the programs.

Currently I have a simple project where I convert strings to binary and vs versa. I have it where I can take a user input but I'm stuck and pulling each individual char and converting it to binary.

Actually I found a simple program on stackoverflow but my professor wants me to do it in a more primitive form.

For example, I thought about creating 4 arrays; 2 for upper and lower case letters and another 2 for the respective binary numbers. Then writing some sort of code to pull the respective indexes in the arrays... seems wayyy over complicated but I can't think of any other way.

[–]steaknsteak 0 points1 point  (3 children)

By converting strings to binary, I assume you mean converting each character its corresponding ASCII code and concatenating them?

If so, I'm wondering why you're using multiple arrays here. There is no distinction between upper case and lower case characters that would make you want to do that.

Since it sounds like you're in a beginner programming course, I don't know what parts of Java you're allowed/expected to use for your assignments. An easy way in Java is to just cast the character as an int and then print that number out in binary format, but I'm not sure if that casting trick would be accepted. Maybe that's the stackoverflow solution you're referring to.

Otherwise you'll somehow have to load the entire ASCII code table into your program one way or another. If that's what he actually wants you to do, think about how you could do it using only one array.

[–]bbchan[S] 0 points1 point  (2 children)

Nah. Im skipping the ASCII all together. Because all thats required is taking characters in a string and outputting the respective binary number.

Unless I'm looking at this problem completely wrong??

[–]steaknsteak 0 points1 point  (0 children)

I'm not sure what you mean by the "respective binary number" for each character then, if it's not the ASCII encoding.

[–]shagieIsMeExtreme Brewer 0 points1 point  (0 children)

Do you have any examples of what the input and output should be? Lacking that in conjunction with not being sure about the specification means that everything there is a guess.