Page 1 of 1

My first Java programs! ^-^

PostPosted: Wed Sep 07, 2005 2:48 am
by Slater
the first real original Java programs that I've made that actually serve some purpose! I'm learning this language very quickly and having a blast while at it, but these are still mind-numbingly simple. Still, they may prove useful for anybody in a physics course in here.

1: Weight Calculator: measures the weight of an object provided that you give the mass. This is for the average gravitational acceleration on earth. Note, this program will only work for mass measurements in kilograms! It will, however, convert to Pounds for you at the end.

2: Initial Velocity Solver: Used to calculate the initial velocity of an object provided that you know its linear acceleration, velocity, and the change in time at the point you chose the velocity (in other words, you need to know a, v, and t). Why I did it this way, I don't know, but it does have practical uses in the field of physics. Note that the terminology in it is made for the SI system, but it will work for FPS system as well (just pretend that the m is ft., or whatever unit of length you wanna use). It's a bit buggy if you try to input letters or characters other than numbers... but why would you want to do that? :P

To run these programs, all you need is to have Java installed on your comp. If you can get into the CAA chatroom, then you have Java. To run them, first extract the .class files to somewhere you can find them. Then go to dos (or Unix equivalent) and browse to the directory you put them in. then, simply type in "java intVelocitySolver" to run the program (NOTE: do not put .class extension in command prompt!). Follow the instructions and have fun.

I plan to make a lot more of these simple programs for you physics people out there (several more related tothe velocity one), but it's almost 3 AM here, and considering that I have class in 9 hours I better get some sleep ^^;
So, if you could like... check these out for me and gimme questions/comments/rottenfruit, it would be appreciated!

PostPosted: Wed Sep 07, 2005 11:32 pm
by Warrior4Christ
I tried the inital velocity program - I like warning about relativistic speeds :lol:.
It dies when you enter non-numbers, but you probably already knew that.

I made a simlar program a while ago on the Casio 9850GB Plus calculators, but it solved for a much larger range of values. You enter in the all known values of time, inital & final speed, acceleration, initial & final momentum, force, mass, and distance (I think thats all of them) and then it solves for all the unknown quantities that it can given that information (and prints the formula it used too).


Also, I made a program in VB I like to call "Java Developer"* (attached). It make the tedious command line compile/run cycles much less tedious as it is a GUI for doing the repetitive commands, and it is recommended if you do lots of Java programming and get sick of using the command line. I know it does contain some minor bugs if you try to do something obscure, but I haven't been bothered ironing them out as of yet.

*Requires VB5 runtime.

PostPosted: Sun Sep 11, 2005 11:53 pm
by Slater
yeah, now I need help. I've been making a lot more (kewler) programs that I'll upload later, but when it comes to the homework I'm lost.

Ok, the scenerio is this. I'm supposed to display and explain the difference between the following things...

System.out.println(2 + "2");
System.out.println(2 + '2');
System.out.println(2 * '2');

the first yields 22, and I understand that perfectly. But the second yields 52, and the third 100. I don't understand the second and third at all... can someone enlighten me?

PostPosted: Mon Sep 12, 2005 5:02 am
by Warrior4Christ
The single quotes makes it the digit of type char (value from -128 to 127). So when you use it with the add operator with a char, it just interprets it as a number, hence 2 + [ASCII code of '2'] = 52. So we can say '2' = 50.
And for the second line, 2 * 50 = 100, naturally.

PostPosted: Mon Sep 12, 2005 1:34 pm
by Kaligraphic
Warrior4Christ is correct, '2' is treated as a character, which functions as its ascii value in mathematical calculations. Really, the odd result is the first one, in which it treats the + operator as concatenation, rather than as addition.

There's a convenient ascii table at lookuptables.com, if you're interested.

PostPosted: Mon Sep 12, 2005 2:48 pm
by Slater
yeah, we were never given the ascii table in class, but Kacha went into superflux detail about concatenation and stuff...

PostPosted: Tue Sep 13, 2005 12:27 am
by Slater
Double post oh noes!

Ok, here's the program I was talking about..

Also, I added another zip with two programs and source codes in it. The first is a madlib... run the program and notice how sometimes the program fails to go on to the next question without the user pressing enter twice. I tried to fix that, but... I can't figure out how! It's not a fatal bug, but it's annoying me.

Second is a pseudo-random number generator I made. again, it's a bit glitchy if leters are entered instead of numbers, but other than that it's stable... but... well, I don't understand why a modulo (% arithmetic expression in java) would output a negative number... anyone know why?

PostPosted: Tue Sep 13, 2005 2:02 am
by Warrior4Christ
My API specification doesn't have java.util.Scanner. Is that only with Java 1.5?
It runs still, anyway. With the double entering, I noticed sometimes you used data.next, and other times it is data.nextLine... Should they be different?

With the random number generator, when comparing strings, use stringVar.equals(anotherStringVar), rather than the standard number compares.

I don't have a lot of time to look at them at the moment, I'll come back to them later...

PostPosted: Tue Sep 13, 2005 2:25 am
by Slater
java.util.Scanner is only in the newest version of Java. I know, our teacher (and the CSC department's server) has outdated Java and Java books whereas us students have the 5.0 based book, lol... data.next and data.nextLine are different. Next takes everything before the next whitespace delimiter that is taken in by the program whereas nextLine only cares about \n as a delimiter.

I will try that with the RNG program

PostPosted: Wed Nov 02, 2005 11:50 pm
by Slater
bump because I just finished my homework for tomorrow. I feel particularly happy about this program cause...

1. It took me very little time to make starting from scratch
2. I had never worked with arrays before this
3. I found it very easy and think that this may be my most organized program yet.
4. Random arrays :D!!!!!!!

PostPosted: Wed Dec 07, 2005 11:23 pm
by Slater
anothar program, a prelude to my project due in less than a week that I'll be doing. I swear, it took me an hour of google time to figure out how to center things... because of all the trouble this very small program gave me, I decided it was worth uploading. I'll also upload my whole project once it's done, but it'll be located in the Tutorial forum as a tool for the Algebra students here.
(main(String[] args) is located in tester.class)

PostPosted: Wed Dec 07, 2005 11:35 pm
by Roll
Man, you've become a programmer Dee-luxe!! You can make cooler stuff than I can now! Way to go!!

PostPosted: Thu Dec 08, 2005 12:29 am
by Slater
lol, you should learn Java.
btw, since we finished the book early, tomorrow my Java instructor's gonna make us cookies for class.

PostPosted: Thu Dec 08, 2005 8:10 am
by Warrior4Christ
Uh... which kind?

And also... where's the quadratic solver? Or was it just the about box with the centred text? I don't remember centering being that hard... (but then again I hated GUI Java stuff and tried to forget it).

PostPosted: Thu Dec 08, 2005 11:21 am
by Slater
easy, I haven't done it yet, lol

PostPosted: Thu Dec 08, 2005 10:31 pm
by Warrior4Christ
I made a quadratic solver once (in Javascript *shudder*). Do you want it?

Also, cool "avatar" BTW. (Is avatar the right term in a non-online-forum context?)

PostPosted: Sun Dec 11, 2005 11:37 pm
by Slater
lol, I guess. I couldn't think of a better word for it.

http://www.christiananime.net/showthread.php?p=639986#post639986
here's the final (hopefully) project. I put it in another thread because it puts the rest of my programs to shame.