My first Java programs! ^-^

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

My first Java programs! ^-^

Postby Slater » Wed Sep 07, 2005 2:48 am

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!
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Wed Sep 07, 2005 11:32 pm

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.
You do not have the required permissions to view the files attached to this post.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Slater » Sun Sep 11, 2005 11:53 pm

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?
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Mon Sep 12, 2005 5:02 am

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.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Kaligraphic » Mon Sep 12, 2005 1:34 pm

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.
The cake used to be a lie like you, but then it took a portal to the deception core.
User avatar
Kaligraphic
 
Posts: 2002
Joined: Wed Jul 21, 2004 12:00 pm
Location: The catbox of DOOM!

Postby Slater » Mon Sep 12, 2005 2:48 pm

yeah, we were never given the ascii table in class, but Kacha went into superflux detail about concatenation and stuff...
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Slater » Tue Sep 13, 2005 12:27 am

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?
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Tue Sep 13, 2005 2:02 am

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...
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Slater » Tue Sep 13, 2005 2:25 am

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
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Slater » Wed Nov 02, 2005 11:50 pm

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!!!!!!!
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Slater » Wed Dec 07, 2005 11:23 pm

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)
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Roll » Wed Dec 07, 2005 11:35 pm

Man, you've become a programmer Dee-luxe!! You can make cooler stuff than I can now! Way to go!!
[color="YellowGreen"]Got a Wii? PM me to trade numbers! ^^[/color]

[color="Yellow"]As a supporter of MOES, I would like to take this opportunity to kindly ask that the content of your signature be kept to a minimum as a courtesy to your fellow forum members. Thank you![/color]
User avatar
Roll
 
Posts: 249
Joined: Sat Dec 13, 2003 8:50 pm
Location: Missouri

Postby Slater » Thu Dec 08, 2005 12:29 am

lol, you should learn Java.
btw, since we finished the book early, tomorrow my Java instructor's gonna make us cookies for class.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Thu Dec 08, 2005 8:10 am

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).
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Slater » Thu Dec 08, 2005 11:21 am

easy, I haven't done it yet, lol
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Thu Dec 08, 2005 10:31 pm

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?)
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Slater » Sun Dec 11, 2005 11:37 pm

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.
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 184 guests