|
Hey guys, I need some help with some code I am writing for my intro to programming class. The problem involves analyzing the vertical position of a cannonball. We are supposed to take the input of the initial velocity (and for the purposes of this assignment I guess we are not paying attention to angles and for all intents and purposes the cannon is firing straight up, the physics don't really matter). We are supposed to find its position every 1/100th of a second, and print to the screen its position every one second. I have gotten everything down to where it will print out EVERYTHING but cannot get it to print just every one second. So here is the code I have currently. code:
PS I hope I didn't break any rules for the forum or anything. I tried to get in to the right area and don't have enough time right now to read all of the full rules. Sorry in advance if I screwed up.
|
# ¿ Oct 5, 2009 20:51 |
|
|
# ¿ Apr 26, 2024 18:36 |
|
rjmccall posted:Much like decimal arithmetic isn't exact when dividing by numbers that aren't powers of 10 (or factors thereof), binary floating-point arithmetic is not exact when representing numbers that can't be represented as an integer multiplied by a power of 2. Thus adding .01 to 0 100 times is not guaranteed to produce exactly 1. Thank you. That did the trick. And I'm sure that tidbit will help me a whole hell of a lot in the future.
|
# ¿ Oct 5, 2009 21:34 |
|
MEAT TREAT posted:Just so that you know, if you really do need that kind of precision in your calculations checkout the BigDecimal class. Thanks, I appreciate it. I don't quite need that much precision. It just said to use double precision fps so I went with it. I am not quite sure why you would want them in a problem like this where the actual level of accuracy doesn't extend beyond 0.1 with a nice estimated hundredth. Of course, they have not done anything in our book with single precision fps. I imagine it is just to keep it simple.
|
# ¿ Oct 6, 2009 06:26 |
|
mustermark posted:I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");? If you are already familiar with SQL then start at the official tutorial. http://download.oracle.com/javase/tutorial/jdbc/ JDBC is (can be) very easy to use as long as you already have a decent understanding of DBMS.
|
# ¿ Jul 4, 2011 19:15 |
|
I believe he really meant == 0 or < 1.
|
# ¿ Jul 5, 2011 19:14 |
|
MrZig posted:What's with Java and null pointer exceptions, even though I check to see if the object is a null? How exactly are you initializing Camera? I don't want to make any assumptions, but you are saying you are trying to access Camera in a static way... I am assuming when you call Camera.getRelativex(int x) you are doing some conversion between the camera position and the position that you pass it. When are you initializing the Camera? I am guessing that may be where your problem lies.
|
# ¿ Dec 18, 2011 01:58 |
|
Doctor w-rw-rw- posted:Play framework is a really cool non-Servlet app framework. Klout and some other companies use it in production and its Scala support was good enough for Typesafe to anoint it officially as...something. I forgot. But its Java bindings are great, and I find it a lot of fun. Agreed, the Play framework is easily the best framework I have worked with. It is so good that it makes me sad when I have to go to work and use ASP.
|
# ¿ Jan 21, 2012 19:40 |
|
I am in posted:For one, it uses Object-Graph Navigation Language (OGNL), which makes it easy to parse input to Java objects and get values from Java objects using strings like "session.user.name.firstName". OGNL can also parse and execute arbitrary Java code. I think it is worth adding that there is no point picking up something like Struts right now if you are starting from scratch. The world of web development has largely moved on. Struts can be used to create a great website that is secure and full featured, but there is no point to using it. It isn't higher performing that other frameworks, it isn't more inherently secure, and most importantly, it is not as easy to create things with as one of the more modern frameworks.
|
# ¿ Jan 21, 2012 19:46 |
|
Creating a new Scanner will likely work. I would really recommend that you take a look at InputStreamReader or FileReader. Each of these will do what you need them to do, and you can call reset() to go back to the beginning of the file. Not as friendly as Scanner, but it is the more correct way of handling the problem.
|
# ¿ Jan 22, 2012 22:36 |
|
Are they loading and just not showing? You may need to apply some sizing info to the img tags there.
|
# ¿ Feb 6, 2012 04:38 |
|
Regarding the img tags. First, I would recommend opening up the developer tools in chrome, or installing firebug in ff, and looking at the errors that are being logged. The first thing you need to find out is if it is loading or not. And if it is logging a not found then you know at least that much. Also, I am not familiar really with tomcat, but I would make sure that requests for /src/images are really serving that directory. Also, I don't think this is likely the case, but if you are using XHTML, then you need to get that img tag to be lower case. ComptimusPrime fucked around with this message at 08:57 on Feb 6, 2012 |
# ¿ Feb 6, 2012 08:53 |
|
Sinestro posted:I am a Python programmer, and I need to learn semi-basic Java. All the books I see online are really old, designed for people that have no idea how to program, and/or designed for people who are already know Java to hone their skills. What do you mean by basic? Core Java is a pretty good place to go if you want something that will get you up to speed. Just skip the parts you don't need.
|
# ¿ Feb 29, 2012 19:32 |
|
fletcher posted:
Well... When you are doing something like this you could just change the code to... code:
|
# ¿ Mar 8, 2012 00:46 |
|
Newf posted:Does day-to-day programming ever get over this kind of boneheadedness? I'm sure that I spend half of my 'coding time' on these types of errors. Yes and no. They will become less frequent but there will always be times when something obvious becomes incredibly difficult due to either being tired, a cache bug, or something else miniscule that will cost you a couple of hours.
|
# ¿ Mar 9, 2012 15:59 |
|
Sedro posted:Crappy plugins drove me away from eclipse. Process for merging conflicts with Git and Netbeans: Close Netbeans. Start merge process. Merge all conflicts. Add/commit changes. Finish pull. Open Netbeans. Netbeans now thinks you have duplicate class files. Bang head against wall until finding Netbeans hidden cache folder. Delete cache folder. Repeat process for every merge until you remember Netbeans cache folder.
|
# ¿ Mar 9, 2012 20:52 |
|
I don't use the IDE for source control. I use git proper. And NetBeans does not like the way it handles merging files.
|
# ¿ Mar 9, 2012 21:14 |
|
Scala IDE 2.0.0 was just released. You should probably check it out.
|
# ¿ Mar 9, 2012 23:28 |
|
thegasman2000 posted:I have been given a nice problem to solve and have no idea what I am going to do... I need to us the JustGiving Javascript API to enable functionality to a flash app. Is there a way for me to utilise JS in actionscript 3? Here is a link to the API if anyone fancies a look. https://api.justgiving.com/docs Perhaps you will have more luck asking about this in the JavaScript thread.
|
# ¿ Mar 26, 2012 21:39 |
|
Think about using a temporary in that leave method.
|
# ¿ Apr 6, 2012 00:45 |
|
You're not even addressing his problem. You're suggesting a beefy architectural style to solve his inability to reason about how to both set the person to null and also return the person in the leave method.
|
# ¿ Apr 6, 2012 07:25 |
|
pigdog posted:Any particular reason you wouldn't just use LinkedList? That is, if you really need a linked list in the first place, as opposed to normal ArrayList. He is in an intro to data structures class. I am pretty sure.
|
# ¿ Apr 16, 2012 15:13 |
|
readLine will only return once it encounters a new line (which happens in the terminal when you press enter). New lines are not automatically entered in to an output stream unless you have a method called something like "writeLine". BufferedWriters have a method "newLine", which you can call after each write. Don't close the socket and reopen it. Hopefully this will get you on your way.
|
# ¿ Apr 18, 2012 17:08 |
|
You can do master slave to break down the 4 sections. But if you want to make it become truly scalable to as many cores as are present in the system then it will be a bit more complex of an algorithm. One question would be this: Does each node only care about where the other nodes are at the beginning of each calculation? At the end? Or at some point in between? (e.g. if node 1 carries out the distance computation, does the result effect node 2?) I would first write it out linearly and then look for sections of the code that can be broken out in to separate tasks.
|
# ¿ Apr 24, 2012 04:28 |
|
Are you buy chance trying to carry this out on the root drive of your Windows install (a.k.a C:\)? If so, I suggest placing the file in your User directory and trying to run your program again. I also suggest you trim the ends off of that input. Edit: Also, if you want, google "java FilePermission". ComptimusPrime fucked around with this message at 02:37 on Apr 26, 2012 |
# ¿ Apr 26, 2012 02:28 |
|
|
# ¿ Apr 26, 2024 18:36 |
|
Firstly, you are decrementing front after you take its modulus. Secondly, this code:
I assume is reversed.
|
# ¿ Apr 30, 2012 00:20 |