Computer Science Canada [Tutorial] Easy Database in Java! (Under Construction) |
Author: | the_short1 [ Sat Jul 23, 2005 12:58 pm ] | ||||||||||
Post subject: | [Tutorial] Easy Database in Java! (Under Construction) | ||||||||||
please save the comments till i am fully done, i am aware i might have made mistakes but i will fully test b4 i call it done, i just need a place to work on it .. i have a working version of this code that i am extracting this out of, and i have to re-write a lot of it to make it easier ~~INTRO: for my Final Project in gr.11, i made a reminer program, set the date and time, and what you need to be reminded of, and it will alert you then.. And i needed to store the date, time, and reminder into a database, and i thought ide share the easy (IMO) way to do this kind of db manipulation ~~WRITE TO DATABASE (WHEN ITS EMPTY) ~~STEP 1: First off you must decide how many elements you want in your database, and of what type, for the rest of this tutorial, i will be using 3, the postion (int), the name(string), and the score(int), most likely youll use this for a highscore table anyways. Im asuming in this tutorial that you know how to start a program off, and where to insert code like this.
~~STEP 2: gather all the input from user and store into array
~~STEP 3: Decide on the format in which to store the information // example --------- Entry:## Name: Kevin Folz Score: 1337 --------- ~~STEP 4: Add New info to DB
~~Part 2: ~~Getting all the entries from the db and storing into array, and amending new entries, notice the substring command, this is the heart and soul of this. This command checks to make sure that the data you are reading corresponds with the thing you want, making it a LOT more solid, to prevent db corruption and glitches.
in this code, it checks to see if the line read from the file has "Name:" (using indexOf), at the start if yes, then it will take everything after the first 5 characters, and store it into nameEntry
//remeember folks.. its not done and may not work yet it hasn't passed my vigurous testing, but yes i know what i am doing I WILL POST A FULLY WORKING COPY OF THIS CODE AS A .java FILE FOR YOUR CONVENIANCE (when done tut), maybe i will make into methods later, or a class.. . but rite now i felt i havnlt contributed much to compsci.. lately so .. im trying to make up for that |
Author: | Martin [ Sat Jul 23, 2005 1:08 pm ] |
Post subject: | |
Create a class to hold the information for you, and then when events are pushed into the queue, put them in order from first to last to occur. This is called a priority queue. Let's say that I'm sorting things for the day, with 1 happening in 1 hour, 2 in two and so on. put 3 onto the queue. {3} put 5 onto the queue {3, 5} put 2 onto the queue {3, 5, 2} two is smaller than 5 (the back of the queue) so it moves up {3,2,5} two is smaller than 3, so it moves up {2,3,5} This way, you only have to wait for the front event to happen, instead of searching through the entire list. |
Author: | the_short1 [ Sat Jul 23, 2005 1:29 pm ] |
Post subject: | |
please dont post replies till its done! probally by end of tomroow. !! |
Author: | wtd [ Sat Jul 23, 2005 1:58 pm ] | ||||||
Post subject: | |||||||
the_short1 wrote: please dont post replies till its done! probally by end of tomroow. !!
I'd wait, but it's already flawed rather horribly.
Don't store these things separately. A name and a score make for a record. Make that one thing.
Then you can have an array (or other collection) of records.
|
Author: | 1of42 [ Sat Jul 23, 2005 2:30 pm ] |
Post subject: | |
And what is with all the addign empty strings to the end of your printlns? I'm pretty sure that you're not required to. |
Author: | the_short1 [ Sun Jul 24, 2005 12:09 am ] |
Post subject: | |
records are a lot more complex .. i wana keep this avaiable to noobies too! and...";// the +"" makes newline " .. so its like name score instead of name score |
Author: | wtd [ Sun Jul 24, 2005 1:28 am ] | ||||||||
Post subject: | |||||||||
the_short1 wrote: records are a lot more complex .. i wana keep this avaiable to noobies too!
No, using objects is not more complex. Consider passing a database to a function to read information from it. You'd have to pass in two arrays and several integers separately, and hope like heck that you don't mix them up along the way, since that would give you a program that compiles and runs, but produces the wrong output. Object-oriented programming is an integral part of Java. If you don't want to deal with it, don't deal with Java. Additionally, do not work too far beyond your capabilities. If you don't understand the tools necessary to build a "database", then don't try to build a "database" until you do. the_short1 wrote: and...";// the +"" makes newline " .. so its like
name score instead of name score Adding an empty string does nothing. Really. The following does exactly the same thing.
Oh, and as for this:
Variables in Java should never ever begin with capital letters. Additionally, use more descriptive variable names. For instance:
As:
Now I don't need the comment, because the variable name tells me all I need to know. With all due respect, I suggest you learn Java a bit better yourself before writing tutorials. |
Author: | 1of42 [ Sun Jul 24, 2005 2:19 am ] | ||
Post subject: | |||
While wtd is a bit harsh, he is also entirely correct. And going
honestly does nothing unless the other side of the expression is a primitive data type (it may work on objects too, i dunno), in which case it converts it to a String. |
Author: | rizzix [ Sun Jul 24, 2005 4:06 pm ] |
Post subject: | |
Concatenating "" with any Object, simply concatenates the empty String with whatever is returned from the Object's toString(); method. Concatenating "" with a primitive first creates the Object represntation of that primitive and then calls the toString(); method of that object and concatenates the result with the empty String. |
Author: | wtd [ Sun Jul 24, 2005 5:11 pm ] | ||
Post subject: | |||
rizzix wrote: Concatenating "" with any Object, simply concatenates the empty String with whatever is returned from the Object's toString(); method.
Concatenating "" with a primitive first creates the Object represntation of that primitive and then calls the toString(); method of that object and concatenates the result with the empty String. And, as you've mentioned before, a generally preferable way to achieve this is something like:
|
Author: | 1of42 [ Sun Jul 24, 2005 5:34 pm ] |
Post subject: | |
rizzix wrote: Concatenating "" with any Object, simply concatenates the empty String with whatever is returned from the Object's toString(); method.
Concatenating "" with a primitive first creates the Object represntation of that primitive and then calls the toString(); method of that object and concatenates the result with the empty String. Ah, I see. I thought it did something like that, but being clear is always nice. |
Author: | the_short1 [ Sun Jul 31, 2005 8:29 pm ] |
Post subject: | |
wahhh!!!! i left for vacation for work wihtout finishing this ! :S my bad! im leaving a link to this on my desktop! i MUSt complete and make this awsome! |