Thursday, 20 February 2014

Little mini rant:

Out of all the sorts, the quick sort is (obviously) the quickest, given its' name. But that's not the only reason (it would be cool if it was - just say QUICKSORT and it becomes the quickest). The REASON it's a quick sort is because it uses recursion which always quick (and really confusing). And then there are a bunch of other sorts that don't use recursion like insertion, selection, and bubble sort. The insertion sort, I have a feeling is the one of the slower sort seeing as though it compares every single value, and then checks to see whether it is greater or less than, and then moves them accordingly. For example, if you were searching fro something that is alphabetical, the insertion sort would look at a certain index, say '1', and check whether the current index or the one above it is greater. If it is greater, they are flipped; if not, they remain the same, and we test it on another value. One of the problems with this method is that even though something is at the top of the list and in the right space, the program still has to check it unlike in selection sort or bubble sort, where the minute something is moved, it's officially moved. The selection sort, makes this a lot more convenient, where instead of checking one next to the other, it finds the largest item in the list and exchanges that with the top (cause it would be on the top either way). And then, it switches every one that needs to be switched in the remaining list. The bubble sort, which, I think is the easiest to memorize does this in a different way. The bubble sort goes through the list exchanging the larger values to the right side and keeps going until the largest value is at the top. And it continues this until the entire list is sorted when nothing else has to be sorted, it's done.

Searching

Sigh..I'm definitely not getting anything done todaay or like..any time soon. Bloody cough never seems to stop!

Well beside the point, I got a bit done. And that's the uh..well, a bit of the sorting bit. I'm just testing it now.




So hmm, yeah. That's what pops up. Okay, time for cough syrup or finding something to stop the cough. Bai. 


Wednesday, 19 February 2014

Sorting Done

So the sorting bit is done. I'm going to get the user to entire it mm/dd/yyyy though. It'll make it a lot easier to sort so instead of August 01 it would be 08/01/2014 or something like that. That way, Java will make it a lot easier to see and the program would be a lot more user friendly. 

Last night

I didn't have a chance to post what I did last night, last night. So here goes:

I ended up fixing the whole array thing, in which when you add an entry, it shows up in the table. So that's all done with.

Although I edited this morning because I felt like that code wasn't something that I could use...instead, I've created a copy of an array and then made them equal.

But unfortunately, they are showing the object positions rather than the value inside the array now..so I'm really confused.

Oh. I should have made the for loop thing with boundaries of the shorter array rather than the longer one. Okay, that totally makes sense now. And I'm done the adding entry bit now..

Onto the searching and sorting!

Tuesday, 18 February 2014

Yay!

So from work that I did this morning and stuff that I've just done, this is what it looks like when you "search" for something (It doesn't actually search yet).


I've run into a dilemma, which I'll have to ask Ryk about. UGH. 

Confuzzle

Running into a pretty big problem because the table is being created in a separate class. But if I have the addEntry thing in the main class, then the other class will not be able to access it.

One thing I can do is create a temporary object item, and then merge them at the end and print the updated thing into the file.

Or, I can just add it into the file and get the program to read it in again. It's going to take a heck lot of memory though.

Sunday, 16 February 2014

DJFLSKDJVDSK

Okay, I keep running into errors - so I'm going to revert it back to what it was the last time, and ask Ryk if i can just add search and call it a day. Creating my own sorting is just such a headache.

Ok....

Okay, well good news first:

I do know what I am doing and what I am supposed to do..

3 classes, one that extends JPanel; the other that extends and implements the Table stuff.

And so when I got to create the panel for the table, I should have the "new ClassNameForPanel()" inside the brackets along with the = new JPanel thing.

But for the table itself, I should go through the Panel then table because then I can send the array rather than have it being created - which would work for the "reusing" bit.

Adding Rows: To add rows, I think I'm going to do it in a JOptionPane asking each individual question when it pops up. 

Deleting Rows: I have to allow the user to select a certain row or something that they want to delete, and then have to go through the array and copy everything but that row, and then make the original array equal to the new one. 

Describing Array of Objects

So this is another thing that we need for the documentation and after accomplishing so much with what I did so far (LOL), I'll do this documentation bit.

RYK: ALL DOCUMENTATION/PARAGRAPHS REQUIRED FOR ASSIGNMENT IS IN YELLOW.

Arrays of Objects are very helpful when programming. Because an object is at the very top of the hierarchy, it can use methods from anything below it; string, double, float, integer, and more. This makes it a lot easier to compare objects because they will be of the same type. It is the same thing for a Comparable object, but I cannot use this type of Object to create a JTable, so my main focus will the Array of Objects. I created an array of objects so that all previous entries could be shown on a table where the user can choose to delete, add, or view entries. The array of objects makes this a lot easier because I can search or sort things much easier. In JTables, they have to be in a 2D array, so instead of an array of different object inside, I used just an array of objects to store all the information. It is very useful because it is easy to interact with and easy to see. 

Frame?


So the JFrame is showing up, from the original class. But I don't really know what is wrong..

*TWO HOURS LATER* 

HOLY MY CORNELIUSING FUDGE I JUST OH MY AHH! 




HOLY WHAT? It totally worked! OH MY AHHH! 

I'm so confused

I'm actually so confused, I'm not sure what is going on.

Okay, so everything that changes the array has to go into the other class. I get that.

But then..

UGH.

So I just had to make everything a class field (meaning static) in order for the bloody thing to work, but I don't know what to do next..at all O.o

Like...if I have to make the showGooey thing static, I can't because the JPanel would have to be static, and I can't make a static class ugh this is so unbelievably confusing.

Small Steps?


LOL, if you would like to call it small...I've created a table using that class. I'm not sure if it is going to help. I sure hope it is, cause I can't see the class hierarchy on this.

I'm in the process of moving the readFile and writeFile to the other class..I think the table thing is just creating an instance of all that data, so I believe it makes sense. But I'm not entirely sure. :/ 

I guess I'll find out soon...

But the process is kind of making sense now. I'm creating an array in a different class, and editing that array only in that class. So when I declare the JTable, if I use that one, the entire thing will be edited as well. If the user adds any other information, it will be handled inside the secondary class, not the primary. But DANG, that's confusing. 

Saturday, 15 February 2014

Confusing

Okay, yeah, now THIS is getting confusing. In JTables, you have to create and update the array within the class, you cannot outside of it, so I'm going to have to create everything that has to do with the table inside the MyTable method.

Which means anything to do with methods, and then I can call it from the original class.

Dang, that's confusing - but there are always confusing things here and there, aren't there? :(

Until tomorrow then..not going to finish anything in this state of mind.

HOLY!

Wow. That's amazing. I'm already done converting everything into a 2 dimensional array! I thought it would take a lot longer, but pop and it's done + 2 minutes or so for solving a Rubiks Cube! Good chance to get started on programming the JTable then :)

Comparing Linear and Binary Searches

I've realized for the assignment, that I need to have this somewhere in documentation - so here it is (I might as well do the documentation now, when I'm a bit braindead than program it now and screw it up. By the way, I've thought about it, and I'm going to convert the entire program into a 2D Array so I can make room for the JTable that I will be programming tomorrow along with doing Advanced Functions.)

Anyway, here goes:

The linear search is a lot less efficient than the binary search because the linear search has to go through every single element with in the array to search for the one thing you are looking for. It takes a lot more memory space (luckily Java has a garbage collector) and understandably, takes a lot less time. The binary search, on the other hand, finds the median of the set of numbers, cuts the list in half, and checks whether the value you are looking for is above or below middle value. If it is below, it takes the lower half and if it is above, it takes the upper half. It repeats this process until it finds the value (or doesn't find the value). This is much more efficient because you don't have to look at every single value - only the top, the bottom, and the average of top and bottom. It is just so much more efficient than the linear search, in which it goes back and forth - possibly even finding two of the same values, and returning either the lower one or the upper one depending on how it was coded. The binary search cuts the search in half compared to the linear search which looks through every single one individually. In this case, it is totally understandable that the binary search is ½ the time.

There are many different types of sorting algorithms, and this becomes very useful in binary searches, because binary searches require the list to be sorted before searching - otherwise the median value would be inaccurate. Paragraph to come later.

Also, here is an updated version of how the JTable will be organized (colour to think about later).
NamePlaceLocationDateCostTypeOther Info







This will be the setup, and so all of the entries will have to be put into a 2 dimensional array, that has these types of angles - and that is how they will look. When I read to and from the file, they must all be in this order, otherwise nothing is going to work. I think I'm going to convert everything into a 2 dimensional array, and then do most of the JTable stuff like sorting and whatnot tomorrow. I'm not so concerned about the like illegal values or whatnot, but the creation of the table is a little intimidating. 

So first off, I would have to create an array that contains all the table headings that will be in the JTable, and they have to be declared in the class so that the whatever listener thing can listen to it and find out what is going on. 

Then, I would have to change the readFile and writeFile methods - not in like reading and writing, but where to store the data, because now the new array cannot be of type Location...that would not be useful. 

I've gooogled a few stuff on like JTables and such, and it's a bit irritating cause they don't mention what happens when you have a one dimensional array of objects, whether a table would work as well.  I don't think I'm going to take my changes on it. I'll leave all the one dimension array values in like...documentation, so I can can always go back to it if I need it. 

uhoh.

Okay, so I've finally understood the uh J-table thing. And it looks like I have to convert my one dimensional array to a 2-D array. I actually have no idea how to print that to a text file..it would require a nested for loop.

So I think I'm going to convert it today, and start on the creation of the JTable. And then get on the J-Table thing tomorrow. I'm going to use it to

WOAH. No..I just thought of another way. I can always create a second 2D array and just organize it the same way, something like this (assuming second array has also been declared)

for (row = 0; row<length of 1d array; row++)
{
for (col = 0; col<row; col++)
if (col == 0) 2darray[row][col] = 1dayarray[row].getName(); 
if (col == 2) 2dayarray[row][col] = 1darray[row].getTown(); type thing until the end 
 And then when row == 1, we are talking about position 1 in the array, all the way until the length of the 1d array is complete. 
 }
}

Tuesday, 11 February 2014

JCOMBOBOX!

HOLY MACARONI


AHA! I created a JComboBox...I'm not sure if it is functional 

Invalid Entry

So the continue button now has a bit of a function - if it finds that one of the fields is empty, it displays a JOptionPane that looks like the following:



So that's successful! The clear button also works, by clearing all the fields. (actually before, I had accidentally set it to clear the west rather than the centre so POP and everything on the left disappeared.)

Also, given that these are the index numbers;

         if (i == 0) addWestFields[i] = new JTextField("Place of Stay");  
         if (i == 1) addWestFields[i] = new JTextField("Name of Accommodation: ");
         if (i == 2) addWestFields[i] = new JTextField("Date of Stay (mm, dd): ");
         if (i == 3) addWestFields[i] = new JTextField("Type of Accommodation: ");
         if (i == 4) addWestFields[i] = new JTextField("Price Per Person");
         if (i == 5) addWestFields[i] = new JTextField("Other Information");

Well, yeah. Self explanatory.

Monday, 10 February 2014

Update Update

Well I'm almost done the adding an entry page, just gotta give the buttons a use. So here it is!


NullPointer

So I've run into an error with adding the things into the JPanel. I wanted to do it using a loop so that if I ever change it then I wouldn't have to worry about it, but I'm not sure how to do it without going "outside of the loop." I'm thinking that if i == 7, then to make it equal to 0, but that's not the effect I am trying to achieve either.

I've also changed the arrangement to something like this:



Place of StayJTextField (empty)
Name of Accommodation JTextField (empty)
Date of Stay JTextField (empty)
Type of Accommodation JTextField (empty) 
Price per person JTextField (empty)
Other Info JTextField (empty)

Clear Fields
CONTINUE

Rather than the previous one, where you had to enter month and date separately. Seems redundant. but in that case I gotta edit the class and the text file and all. So for the date, they can just enter something like "August 1" or something like that. It'll make it a lot easier - maybe not for sorting, but I can assign each month a value and then sort it that way rather than alphabetical because that just won't work, haha.

And then I just ran into another error..all that code and nothing is showing up. 

Sunday, 9 February 2014

Add Entry Tomorrow

I've decided that I'm just going to do the addEntry one tomorrow. Instructions and the add entry is just too much to take on today, and there's just to much work and all. I can't handle doing so much. I'm going to get started on other things, and then go back tomorrow with a clean slate.

Adding Entries

So after a day of like solving Rubiks Cubes and programming (pretty good combination), I've created or designed a template for the Add Entries Page. This is the template:


Quackin' Old Programs!

Been looking at my old program, and it looks horrible! Like, the "ask the user" lalallaa, and the "display to user" console window is all so ugly.

So I've been getting started on converting it into a gooey, and this is how it looks so far - the menu at least.

Okay, yeah, it looks a bit plain right now. I've got to get the instructions screen to pop up, and the JMenuBar (You can see it at the top - it's just not functioning)...not working - at all. 

Gotta get the "Add an Entry" and "Instructions" methods working, and that'll be all for today. Tomorrow, instead of solving Rubik's Cubes, will be reading about JTables tomorrow, and working with the "See all previous entries" 

Saturday, 8 February 2014

JTables and such.

Okay, I've decided - I AM going to convert it into a gooey, but it's going to take a heck lot of work. That'll start tomorrow - I'll get started on asking the user to enter things into the array (instead of solving Rubiks Cubes). And in the meantime, I'll spend extra time looking at how to use JTables. I've really got to get on that. I kind of get it, but I just need to make sure I understand it.