|
In sed I am trying to take a string where a single quote occurs inside a set of single quotes, pinpoint the middle quote, and do something with it. Here is where I am at. code:
code:
|
# ¿ Mar 28, 2008 06:23 |
|
|
# ¿ Apr 29, 2024 17:32 |
|
I really like Notepad++ for all my coding needs. One of the selling points for me is the build in console plugin. Great for quick compiling and execution.
|
# ¿ Mar 28, 2008 07:04 |
|
Who wants to help me complete a basic java assignment that's due tomorrow morning? I don't want you to do it for me, but kind of just walk me through the whats and whys in a collab online editor. If you're successful in helping me finish it I'll get you an upgrade/whatever of your choice.
|
# ¿ Feb 21, 2012 06:04 |
|
Look Around You posted:
I just don't have a solid grasp on OOP. Reading about it isn't doing much good, so I figure it's tutor time. E: Feel free to make fun of me/deface my retard program here: http://collabedit.com/k4w9y Assignment detail here: https://www.dropbox.com/s/djars6tl1vyghyu/HW6_Methods.pdf Yes I know I'm retarded and should quit programming etc etc Tots fucked around with this message at 06:33 on Feb 21, 2012 |
# ¿ Feb 21, 2012 06:30 |
|
Just wanted to give a big thanks to LookAroundYou and orenj for helping me wrap my head around some pretty important concepts. I'll rain down the good karma on new beginners in a few months.
|
# ¿ Feb 21, 2012 08:02 |
|
In Java I have a switch statement depending on a variable declared as int. I collect the value to apply to the switch statement using the scanner class. How can I return an error if the user inputs a string? IE code:
E: As it is now, the application simply crashes when a string is entered.
|
# ¿ Feb 22, 2012 01:08 |
|
Oh, awesome. Still new to the game and I didn't think of looking at the documentation, which in hindsight should have been my obvious first resource. Thanks.
Tots fucked around with this message at 01:24 on Feb 22, 2012 |
# ¿ Feb 22, 2012 01:17 |
|
ToxicFrog posted:This is not true of all languages or libraries, but the Java documentation is actually quite good if you already know what you're looking for (ie "how do I use class X"). Is there a recommended go to resource around here for explaining Java related things at a very rudimentary level? For instance, I have never used a try-catch block before. Instead of just googling and blindclicking links I'd like a go-to resource that I know is thorough and easy to digest. E: Actually, the oracle.com tutorials (which was the first google result) looks pretty good. I'm still open to suggestions though. http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html Tots fucked around with this message at 01:42 on Feb 22, 2012 |
# ¿ Feb 22, 2012 01:36 |
|
Holy christ is this frustrating. I don't even actually need to do this for the assignment, but I got curious and now I loving hate that I can't make it work. Why does this just give me a blank screen instead of prompting for input? It starts out with tryAgain == true, so then it should run the code inside the try block. Right? RIGHT?! gently caress. code:
|
# ¿ Feb 22, 2012 04:35 |
|
csammis posted:You have a semicolon after the while(). Take it out. gently caress me. Okay, so it works, but it looks like after it gets an error it just exits with my error message. What I was going for is to have it continue running from the beginning of while (tryAgain = true) after it catches the error. That was the whole reason I stuck that while statement in there. E: I put together code for testing purposes for what I want to accomplish. Should be easier to see what's going on and what I want code:
Tots fucked around with this message at 05:03 on Feb 22, 2012 |
# ¿ Feb 22, 2012 04:59 |
|
Look Around You posted:You're gonna have to take the return; out of the catch block then; return leaves the entire function, not just the catch block that you're in. When I don't put anything in there it repeats the error message ad infinitum.
|
# ¿ Feb 22, 2012 05:02 |
|
Look Around You posted:What error message is printing all the time? As an aside, that code is not really structured the best way... you don't really need the inner while loop. Try replacing it with an if statement or just using the switch statement. You almost certainly don't want nested loops here. Actually I was wrong. The output when a string is entered is this: code:
|
# ¿ Feb 22, 2012 05:11 |
|
ToxicFrog posted:Back to the documentation we go: Thanks a lot for your help. Most of my problem at this point is just lack of exposure I think. This is literally my 1st java assignment that isn't just changing very basic code that's already written for me. Even though the docs are extremely helpful, "When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method." doesn't mean very much to me at this point. E: When I put my brain to breaking it down it begins to make sense, but the concepts aren't really internalized at this point. It didn't register as 'important' to me until someone else explained why it's important. quote:
Just to reaffirm what I am doing here (I got it to work just by adding in a nextLine() statement at the end of the catch), the exception handler is just going to keep reading that bad input until another method tells it to do something else with it. Is that correct? So the catch statement finishes, then returns to the beginning of the loop using whatever the most recent input was unless I specify that it should skip that input, or otherwise do something with it. Tots fucked around with this message at 05:33 on Feb 22, 2012 |
# ¿ Feb 22, 2012 05:30 |
|
ToxicFrog posted:Maybe I've just been reading Structure and Interpretation too much, but it seems that functional abstraction and how to break down your program into smaller, easy to reason about chunks thereby should be the first step after super-basic things like "what is a program". (This is a bitch about the course, not you.) I'm going to try to stick input collecting and error reporting in its own method tomorrow after I've gotten some sleep. Expect me back in this thread. E: How long until I am not retarded at programming? Tots fucked around with this message at 06:10 on Feb 22, 2012 |
# ¿ Feb 22, 2012 06:07 |
|
Alright, I'm probably wearing out my welcome, but the cogs are turning. If I wanted to abstract the input and error handling, would this be the right track? code:
Tots fucked around with this message at 06:26 on Feb 22, 2012 |
# ¿ Feb 22, 2012 06:24 |
|
Look Around You posted:This looks pretty good. Are you sure you want to return '99' on an InputMismatchException and not display an error, discard the invalid input and get a new input? This is more up to you, but if you return 99 on invalid input (strings etc) then your program will end after you do that. There's more ways to break it up even further too. If you find yourself typing the same thing over and over again (or at least extremely similar things), see if there's a way to make it into it's own function (or method or whatever the hell you want to call them). Well the plan was to print a generic error message in Case 99. I was under the impression that the method would end resulting in the method returning to main with a value of 99 (or 1-4 if it's valid). Then I would call the method again at the end of each case.
|
# ¿ Feb 22, 2012 06:47 |
|
Look Around You posted:Well, why not pull the method out of the switch statement so that you're only using it at one point? Also, if you print a generic error on 99 and return it, when will your program halt? Is there another specific code to terminate? Was going to put the switch in a while statement and end at -1, as it is in my original program. If I only use it once, wouldn't I then have to put all the output associated with each case, as well as the incrementer that will keep track of how many time they are used, inside this new method?
|
# ¿ Feb 22, 2012 06:57 |
|
Look Around You posted:Oh, it looks like the cases are significantly different. One way to break it apart (and probably the best way for larger applications) would be to take each case and turn it into it's own function. That way you can just do case 1: calcManagerSalary(); break; case 2: calcBlahWages(); break; and move the actual logic for calculating the wages into their own functions. This has the side effect of being a lot easier to debug too. But yes, you would have to figure out a place to store the incrementers and increment it when you calculate that specific type of wage. I am really tired right now, but I can't make sense of how this would work unless a method could return a string E: Okay, yah I need to go to bed. They wouldn't need to return anything. Good night.
|
# ¿ Feb 22, 2012 07:15 |
|
Since my questions sparked the intro debate I should mention that I am in IST which is slightly different than CS. The introduction course for CS uses C++ as does the introduction course for students that aren't going into technology related major. Before taking this course which uses Java I had to take the generic intro which uses C++. That course just taught concepts like using variables and basic loops.
|
# ¿ Feb 23, 2012 00:21 |
|
I'm reading through my Java book and one of the end of chapter questions has this example code in which I'm supposed to find the error:code:
The output of code:
0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999 1.0999999999999999 1.2 1.3 1.4000000000000001 1.5000000000000002 1.6000000000000003 1.7000000000000004 1.8000000000000005 1.9000000000000006 2.0000000000000004...ad infinitum. Can anyone tell me what the hell is going on here?
|
# ¿ Feb 26, 2012 06:40 |
|
I'm trying to figure out a way to return the expected output based on that same for structure, but I can't think of anything that will work and not be absolutely retarded. Any ideas?
|
# ¿ Feb 26, 2012 07:02 |
|
I get what you're all saying, but I was trying to achieve the exact output of .1 - .9 using that same basic for structure somehow... just because. Anyway, I thought about it for like half an hour then gave up after getting frustrated... My brain is sort of goop at this point from lack of sleep. Anyway, turns out that the solution in the book doesn't actually say anything about initializing the value, rather it says "Don't use floating point numbers for a counter you fucktard." code:
Tots fucked around with this message at 07:56 on Feb 26, 2012 |
# ¿ Feb 26, 2012 07:48 |
|
Look Around You posted:This would work. That prints 1.0 2.0 etc... I really need to sit down one night and learn all the printf poo poo. It looks ridiculously useful. This works code:
Tots fucked around with this message at 08:31 on Feb 26, 2012 |
# ¿ Feb 26, 2012 08:01 |
|
Look Around You posted:I'm guessing you know that's not what you're looking for though, right?
|
# ¿ Feb 26, 2012 08:35 |
|
Look Around You posted:What happens if you pass it a negative number? Ah, didn't think of that.
|
# ¿ Feb 26, 2012 08:42 |
|
Look Around You posted:There's some other major flaws in it too though. Notice anything else? Haha, no I know there is since it doesn't run. I really need to get to sleep though. I have work in the morning. Going to look at it again tomorrow.
|
# ¿ Feb 26, 2012 08:45 |
|
Oh, no poo poo. Even if the difference is inconceivably small it will evaluate to true. E: Really going to bed now. Thanks for the late night coding session once again. oh loving christ and the fact that it doesn't take into account how many powers it removed I'm going to chalk this up to being tired since they were both terribly obvious. Tots fucked around with this message at 08:51 on Feb 26, 2012 |
# ¿ Feb 26, 2012 08:48 |
|
Master_Odin posted:For class, we're currently looking at caches, and just looked at profilers (in my case, it was gprof).
|
# ¿ Feb 28, 2012 16:58 |
|
Where can I get a cheap or free off brand TLD domainname? E: Nevermind, I just remembered I still own a domain name. Whoops
|
# ¿ Mar 20, 2016 02:26 |
|
|
# ¿ Apr 29, 2024 17:32 |
|
Gravity Pike posted:Namecheap.com has some sort of $0.88/yr deal for some of the crappier TLDs right now. It looks like they probably pop up to $8-33/yr after the first year, where .com's are steady at $11. Thanks, I might still check this out
|
# ¿ Mar 20, 2016 15:05 |