<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>cHILL 'em All</title>
	<atom:link href="http://chilloxk.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://chilloxk.wordpress.com</link>
	<description>Butterflies &#38; Hurricanes</description>
	<lastBuildDate>Sat, 31 Jan 2009 00:49:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='chilloxk.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>cHILL 'em All</title>
		<link>http://chilloxk.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://chilloxk.wordpress.com/osd.xml" title="cHILL &#039;em All" />
	<atom:link rel='hub' href='http://chilloxk.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Recent bits and bobs &#8211; Switch, Save/Load, For:each, Iterator</title>
		<link>http://chilloxk.wordpress.com/2009/01/31/recent-bits-and-bobs-switch-saveload-foreach-iterator/</link>
		<comments>http://chilloxk.wordpress.com/2009/01/31/recent-bits-and-bobs-switch-saveload-foreach-iterator/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 00:49:39 +0000</pubDate>
		<dc:creator>chilloxk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://chilloxk.wordpress.com/?p=23</guid>
		<description><![CDATA[The lab for monday is almost entirely the same as the DVD labs. Here I&#8217;ll post some minor bits we went over in lectures which might help a bit. Switch Statements These are handy for checking specific things like numbers&#8217; equality. They are useful if you want to have menus and use numbers for imput [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=23&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The lab for monday is almost entirely the same as the DVD labs. Here I&#8217;ll post some minor bits we went over in lectures which might help a bit.</p>
<p><strong>Switch Statements</strong></p>
<p>These are handy for checking specific things like numbers&#8217; equality. They are useful if you want to have menus and use numbers for imput and the like.</p>
<p>eg:</p>
<p>we have a menu that says &#8216;please enter a number to select an option&#8217;, which is stored in an int called choice:</p>
<p>println(&#8220;please enter a number to select an option: &#8220;);</p>
<p>int choice = readInt();</p>
<p>the syntac for switch is:</p>
<p>switch (expression){</p>
<p>case n:</p>
<p>method();</p>
<p>break;</p>
<p>case n+1:</p>
<p>method2();</p>
<p>break;</p>
<p>}</p>
<p>this checks if expression is equal to n, if not, n+1, and will keep going down the list. it will execute the methods inside the case: until it comes to break; which ends the statement.</p>
<p><strong>SAVE / LOAD<br />
</strong></p>
<p>as in the lectures:</p>
<p>save:</p>
<p>saveToFile(dvds, &#8220;DVDs.xml&#8221;);</p>
<p>in this case, what happens is the contents of dvds(which is an arrayList of type String) is saved in the file called DVDs.xml in the directory your project is saved in.</p>
<p>load:</p>
<p>dvds = (ArrayList&lt;String&gt;) readFromFile(&#8220;DVDs.xml&#8221;);</p>
<p>this overwrited the file dvds (which is an ArrayList&lt;String&gt;) with the contents of the file DVDs.xml in the project directory.</p>
<p><strong>FOR:EACH LOOP</strong></p>
<p>Watch out with these, in a for:each loop, you cycle through elements of an array, arraylist or whatever, but you cannot modify the contents of the thing you are cycling though. It actually gives you a copy of what is contained, not the file itself.</p>
<p>syntax:     for(type anyname: listname)</p>
<p>type: String, int, DVD, Song.</p>
<p>anyname: the name which you will refer to each element by.</p>
<p>listname: the exact name of the array/ArrayList.</p>
<p>eg:</p>
<p>public void listDVDs(){</p>
<p>for(String moo: dvds)</p>
<p>{    println(dvd);    }</p>
<p>}</p>
<p>This will pick the first element in the arrayList &#8216;dvds&#8217; (which holds String names), which shall be refered to as moo, and then execute whatever is inside the curly brackets. in this case it prints them out.</p>
<p>If it held DVD types, this would print the names of the dvds:</p>
<p>public void listDVDs(){</p>
<p>for(DVD moo: dvds)</p>
<p>{   print( moo.getTitle() );    }</p>
<p>}</p>
<p>Because we would get each DVD object stored in the arrayList, and all its methods inside it too, like a normal for loop.</p>
<p><strong>ITERATOR</strong></p>
<p>Don&#8217;t entirely know much about these, just that they are ways of cycling through and altering elements in lists/sets. Similar to a for-loop but with it&#8217;s own methods.</p>
<p>import the use of it by using: import java.util.Iterator;</p>
<p>we create it by the following: (not sure on the capital or small &#8216;i&#8217;/'I&#8217;)</p>
<p>Iterator&lt;Type&gt; iteratorname = collection.iterator();</p>
<p>eg: Iterator&lt;DVD&gt; it = dvds.iterator();</p>
<p>this creates an iterator which can cycle through DVD objects, we will call it &#8216;it&#8217;, and it will be attached to the dvds arrayList collection.</p>
<p>this iterator has its own methods;</p>
<p>hasNext() &#8211; which returns a true/false if there is another element in the list.</p>
<p>and next() &#8211; which gets the next element.</p>
<p>used generally (for the moment) like this:</p>
<p>while(it.hasNext() )</p>
<p>{ it.next(); }</p>
<p>to print the name of the DVDs:</p>
<p>while(it.hasNext() )</p>
<p>{ println(it.next().getTitle() ); }</p>
<p>Next: HashSets and HastMaps</p>
<p>specific questions to chilloxk[-at-]hotmail(-dot-).COM</p>
<p><strong><br />
</strong></p>
<p><strong><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chilloxk.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chilloxk.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chilloxk.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=23&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chilloxk.wordpress.com/2009/01/31/recent-bits-and-bobs-switch-saveload-foreach-iterator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e150e273cc3be19665608a2243027d4c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">chilloxk</media:title>
		</media:content>
	</item>
		<item>
		<title>Java 3: More on arrays and basic ArrayList</title>
		<link>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylist/</link>
		<comments>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylist/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 18:51:25 +0000</pubDate>
		<dc:creator>chilloxk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://chilloxk.wordpress.com/?p=17</guid>
		<description><![CDATA[Smash. // (Some things needed for the assignment) if, for any reason,(hint) you need to access an array outside of a class, you will need to create a method to access that method (basically, you will need 2: one method (a getter) that returns the full array, and another (another getter) that returns just the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=17&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Smash.</p>
<p>// (Some things needed for the assignment)</p>
<p>if, for any reason,(hint) you need to access an array outside of a<br />
class, you will need to create a method to access that method<br />
(basically, you will need 2: one method (a getter) that returns the<br />
full array, and another (another getter) that returns just the value<br />
of the array that you want.</p>
<p>This is slightly complicated, I didn&#8217;t cop it till Mairead answered an<br />
email I sent to her.</p>
<p>The reason you need to do this is simple:<br />
-you create the array as PRIVATE, therefore it cannot be accessed<br />
outside the CLASS it is created in.<br />
-this means that all the elements are also PRIVATE.</p>
<p>So to access them, you need something like:</p>
<p>// will return the entire array<br />
public String/int/double accessArray()<br />
{<br />
return String/int/double array[];<br />
}</p>
<p>// will return the contents of &#8216;i&#8217;<br />
public String/int/double accessArrayElement(int i)<br />
{<br />
return String/int/double array[i];<br />
}</p>
<p>ArrayLists are some job.</p>
<p>You can do the exact same stuff as arrays, storing data wise, but you<br />
don&#8217;t have to specify the size of the array initially.<br />
Better because:<br />
- save memory in the PC<br />
- can&#8217;t fill it</p>
<p>creation:</p>
<p>ArrayList&lt;String/TicketMachine/int/double&gt; smash = new</p>
<div class="msg">ArrayList&lt;String/TicketMachine/int/double&gt;;</p>
<p>this String/TicketMachine/int/double arraylist is created and referred<br />
to as smash.</p>
<p>again, it can only hold the above element^.</p>
<p>It differs to an array in some ways, namely;</p>
<p>arrays are added to by doing this:<br />
array[i] = x;<br />
that means x is added to index i of the array.</p>
<p>(will refer to the arraylist as smash)<br />
arraylists are added to by doing this:<br />
smash.add(x);<br />
this will add x to the arraylist smash&#8217;s NEXT FREE POSITION</p>
<p>to remove an element:<br />
smash.remove(i);<br />
this will remove the i&#8217;th element in the arraylist smash</p>
<p>the Length of the ArrayList is referred to as a method: length()</p>
<p>So if it&#8217;s 10 elements long, it&#8217;s labelled from 0 &#8211; 9.</p>
<p>to access data in the arraylist;</p>
<p>smash.get(i);</p>
<p>( the array equivalent is:<br />
array[i]; )</p>
<p>for instance, if I created an ArrayList that held a bank account</p>
<p>ArrayList&lt;BankAccount&gt; bacc = new ArrayList&lt;BankAccount&gt;;</p>
<p>add account:<br />
bacc.add(cust_1);</p>
<p>or remove account in position 0.<br />
bacc.remove(0);</p>
<p>or get the name of the person in that arrayList in position 0.</p>
<p>bacc.get(0).getName();</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
create a method that returns all the people&#8217;s names in the arrayList:</p>
<p>public String getTheNames()<br />
{<br />
String temp = &#8221; &#8220;; (make it an empty string)</p>
<p>for(int i = 0; i &lt; bacc.length(); i++)<br />
{<br />
temp  = &#8220;&#8221; + temp + bacc.get(i).getName() + &#8220;, &#8220;;<br />
}<br />
return temp;<br />
}</p>
<p>I think you have to have the &#8220;&#8221; which &#8216;tells&#8217; the compiler that it&#8217;s a<br />
string it&#8217;s adding to.<br />
If you&#8217;re not sure, google: string concatenation. prob better off doing that.</p>
<p>temp  = &#8220;&#8221; + temp + bacc.get(i).getName() + &#8220;, &#8220;;<br />
(line by line: )</p>
<p>&#8216; temp = &#8216; -&gt; if you dont know that this means at this stage&#8230; FUCK OFF. hah.</p>
<p>&#8216; &#8220;&#8221; &#8216; -&gt; this is just an empy String</p>
<p>&#8216; + temp &#8216; -&gt; adds temp to whats already in temp and what&#8217;s in &#8220;&#8221;</p>
<p>&#8216; + bacc.get(i).getName() &#8216; -&gt; adds the getName() value, which is in<br />
get(i), which is in bacc.</p>
<p>&#8216; + &#8220;, &#8221; &#8216; -&gt; adds a comma and then a space after the above are added.</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chilloxk.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chilloxk.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chilloxk.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=17&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e150e273cc3be19665608a2243027d4c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">chilloxk</media:title>
		</media:content>
	</item>
		<item>
		<title>Java 2: Basic Arrays</title>
		<link>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylists/</link>
		<comments>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylists/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 18:46:11 +0000</pubDate>
		<dc:creator>chilloxk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[java basics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://chilloxk.wordpress.com/?p=13</guid>
		<description><![CDATA[Right now, on a basic level, arrays are fucking fantastic. They are a way of storing data. The data they can store is predefined by the creator. The size of the array is also predefined. Neither can they be changed. The fact that the max size cannot be changed is where arrays fall down, so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=13&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Right now, on a basic level, arrays are fucking fantastic.<br />
They are a way of storing data. The data they can store is predefined<br />
by the creator. The size of the array is also predefined. Neither can they<br />
be changed. The fact that the max size cannot be changed is where<br />
arrays fall down, so that&#8217;s why we use ArrayLists. But you need to<br />
understand arrays first.<br />
How you create arrays:<br />
String[] a = new String[5];<br />
This creates an array, which can hold only Strings, it is of size 5.</p>
<p>int[] shit;<br />
shit = new int[10];<br />
The first creates the address block in memory, the second assigns the<br />
size of 10. Mairead is mad for that shit.</p>
<p>Visualise it like so:<br />
{ [] [] [] [] [] }<br />
It starts at 0, so you could consider the element names are<br />
{ a[0], a[1], a[2], a[3], a[4] }</p>
<p>Using for loops is really just about cycling through array&#8217;s elements.<br />
It would be possible, if you wanted to assign all the values of the<br />
int array equal to 0, to do this:<br />
a[0] = 0;<br />
a[1] = 0;<br />
a[2] = 0;<br />
a[3] = 0;<br />
a[4] = 0;<br />
But, as padraic kirwin says in maths, when u get to something of size<br />
1000 it doesn&#8217;t make sense, that&#8217;s where for loops come in.<br />
int[] smash = new int[1000]<br />
// creates an array from  { smash[0], smash[1],&#8230; smash[999] }<br />
for (int i = 0; i &lt;= 999; i++)<br />
{<br />
a[i] = 0;<br />
}<br />
this makes all the elements in the array equal to 0.<br />
why does this work? we&#8217;ll take it section by section.<br />
the for loop is really a better structured while loop. when i write it<br />
i think of it in 3 stages:<br />
stage 1 = &#8220;int i = 0&#8243;, the initialisation stage<br />
stage 2 = &#8220;i &lt;= 999&#8243;, the while stage<br />
stage 3 = &#8220;i++&#8221;, the finalisation stage<br />
here, i provides a counter, but it&#8217;s also a way of accessing the array.</p>
<p>each pass of the loop, a[i] is accessed and made equal to 0.<br />
because at the end of each loop, i++ is &#8216;done&#8217;, which means i is made<br />
what it is currently plus 1. so after the nth pass of the loop, i ==<br />
n.</p>
<p>so you could do different operations to it, such as:<br />
a[i]  = a[i] + 1;<br />
so this would make the value of a[i] equal to its current value, plus one.</p>
<p>a[i] = a[1] * [a2];<br />
this would make the value of a[i], which of course will change each<br />
time, be multiplied by the value of what is in element a[1] and a[2]</p>
<p>you might think ya whatever this is boring, which you are dead right.<br />
The major thing about arrays is that you can store much more than<br />
ints, chars or Strings, you can hold an entire class in each element<br />
of the array,<br />
which is great for storing things like records of information, etc.<br />
when you store a class object in an array, all the methods and fields<br />
can be accessed.<br />
for instance: if we had a method called getName(), in a class Customer.<br />
and we had an array that held customers:<br />
Customer[] list = new Customer[5];<br />
and this array was populated fully, as in it was full of customers:<br />
Customer[0] = cust1;<br />
..etc (cust1 would have to be already created)</p>
<p>we could find the name of the Customer in the Customer[] array, by doing:<br />
Customer[0].getName();</p>
<p>this would mean, we could make a String value equal to this case, for<br />
whatever reason:<br />
String coolest = Customer[0].getName();</p>
<p>if this was in a for loop:<br />
String coolest = Customer[i].getName();</p>
<p>when would you ever use that?</p>
<p>well imagine you wanted to get the name of the person in the array<br />
with the highest balance:<br />
(we need to assume that we have a getter method called getBalance)</p>
<p>public String getHighestBal()<br />
{<br />
int highestBal = 0;<br />
String name = &#8221; &#8220;;<br />
// the reason you need to do that^, is because.. well I don&#8217;t know. i<br />
think it just needs a value, if it is to be updated.<br />
for (int i = 0; i &lt; 5; i++)<br />
{<br />
if ( a[i].getBalance &gt; highestBal )<br />
{<br />
highestBal = a[i].getBalance;<br />
name = a[i].getName;<br />
}<br />
}<br />
return name;<br />
}<br />
what happens:<br />
- goes into a[i], which is initially a[0], and checks the Customer<br />
object in there, checks if the balance is greater than the value we<br />
created &#8216;highestBal&#8217;<br />
if it is, makes the highestBal value equal to it.<br />
then gets the name of the customer in this element of the array and<br />
makes the &#8216;name&#8217; String we created<br />
goes back into the for loop until i is no longer less than 5, then the<br />
return statement is carried out and it exits</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chilloxk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chilloxk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chilloxk.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=13&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylists/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e150e273cc3be19665608a2243027d4c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">chilloxk</media:title>
		</media:content>
	</item>
		<item>
		<title>Java 1: basics</title>
		<link>http://chilloxk.wordpress.com/2009/01/26/java-1-basics/</link>
		<comments>http://chilloxk.wordpress.com/2009/01/26/java-1-basics/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 18:39:36 +0000</pubDate>
		<dc:creator>chilloxk</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://chilloxk.wordpress.com/?p=8</guid>
		<description><![CDATA[For the Customer class: First thing to do, you need to create the class. For the Ticket Machine last week, creation of the class was done and is always done by: public class TicketMachine{ } Everything goes inside the CLASS braces ( the { and } ). All other methods, declorations, everything. They are the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=8&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For the Customer class:</p>
<p>First thing to do, you need to create the class.<br />
For the Ticket Machine last week, creation of the class was done and<br />
is always done by:</p>
<p>public class TicketMachine{</p>
<p>}</p>
<p>Everything goes inside the CLASS braces ( the { and } ). All other<br />
methods, declorations, everything. They are the first and last braces<br />
in the java file.</p>
<p>Mairead calls the Class the blueprint, but she never mentioned it is<br />
the blueprint for each specific physical thing. Like a Customer, a<br />
TicketMachine, a Car.<br />
All classes start with a capital letter.</p>
<p>Right, the fields.<br />
Fields store values.<br />
If the field type is an int, a &#8216;char&#8217;, a &#8220;String&#8221;; that means they<br />
hold integers, single characters, or a String of characters( ie a<br />
sentince).</p>
<p>- Creating a field<br />
If i wanted to create a field for the Customer class that held, for<br />
example, someone&#8217;s favourite colour,<br />
you would create a String type and name it something that made it<br />
kinda obvious like favColour.<br />
Note: you don&#8217;t have to, but it&#8217;s good to name them all in small<br />
letters, until the start if a new word, then that in a cap, so if i<br />
wanted to make a String called: When in Dome, I would write:</p>
<p>private String whenInDome;</p>
<p>What this actually does it it creates a space in the computers memory<br />
called whenInDome, and says; &#8220;Right, this can only hold &#8220;String&#8221; &#8216;s.</p>
<p>Imagine every field you create as a cardboard box, if you create, for example:</p>
<p>private int waa;</p>
<p>Then a cardboard box is set aside, its contents can only be ints, and<br />
it&#8217;s got &#8220;waa&#8221; written on it because that is what it is now referred<br />
to as.</p>
<p>So we&#8217;ve got our cardboard boxes set aside but there&#8217;s nothing in them<br />
right now.</p>
<p>//======================</p>
<p>Going back to Customer.class</p>
<p>for the assignment, we need to create 3 of these &#8216;cardboard boxes&#8217;,<br />
one that holds someone&#8217;s name, one that holds someone&#8217;s address<br />
address,<br />
and one that holds someone&#8217;s overdraft limit.</p>
<p>She even tells us what type we want, ie &#8211; as in the pdf,<br />
String name, String address, and double overdraftLimit.</p>
<p>(double is similar to int, it just holds decimal points, you need that<br />
for bank acc&#8217;s)</p>
<p>look up at the whenInDome and waa examples and make name, address and<br />
overdraftLimit your self! fuckers..</p>
<p>//====================</p>
<p>Constructors</p>
<p>Right, when you create a class for the first time, everything that&#8217;s<br />
(any assignments or anything, ill go into more detail)<br />
in the constructor is what happens initially, if you didnt have a<br />
constructor, nothing would happen when you created the class.</p>
<p>In the TicketMachine example, the constructor was something like:</p>
<p>public TicketMachine( )<br />
{<br />
total = 0;<br />
balance = 0;<br />
numCoins = 0;<br />
}</p>
<p>what this did was take the value 0, and put it into our carboard box<br />
called total that only stores ints.<br />
it then puts the value 0, and puts in into the cardboard box called<br />
balance that only stores ints, and ditto for numCoins.<br />
THIS IS NOT THE NAME AS HAVING THE BOX EMPTY.</p>
<p>there is another thing about the contstructor. Lets say you didnt want<br />
to set the initial balance to 0, you wanted that everytime you created<br />
the class,<br />
that you wanted to define what total, balance, and numCoins were. it<br />
would look like this:</p>
<p>public TicketMachine(int newTotal, int newBalance, int newNumCoins)<br />
{<br />
total = newTotal;<br />
balance = newBalance;<br />
numCoins = newNumCoins;<br />
}</p>
<p>in this example, the first line: public TicketMachine(int newTotal,<br />
int newBalance, int newNumCoins)</p>
<p>this tells the compiler, (the thing that checks all your code to see<br />
how wrong it is) that for TicketMachine, there are 3 parameters,<br />
the first is an int, the second is an int, and the third is an int.</p>
<p>the actual names of the parameters mean nothing, but I always name<br />
them newX, where X is the current thing they will be replacing. (eg<br />
total and newTotal).</p>
<p>&#8212;Bringing this back to Customer, she wants you to set the name,<br />
address, and overdraft limit.<br />
I&#8217;m refusing to give out the actual code coz you wont learn shit,<br />
but it&#8217;s not too bad when you think about it;</p>
<p>Substitute the names of the classes: Customer is the name we want,<br />
TicketMachine was last week.<br />
We have 3 variables (anything which value can be changed, ie vary)<br />
that are in Customer, and these defined in the parameters( the ( )&#8217;s )<br />
again,<br />
and as she told us in the PDF she wants them to be.</p>
<p>They want to be the 3 things from our cardboard boxes that we created<br />
earlier, the String type which is called name, the String type which<br />
is called address,<br />
and double (which holds a number with 2 decimal points) type called<br />
overdraftLimit.</p>
<p>So going by this logic,</p>
<p>(as in the TicketMachine) int newTotal took in an int that we wanted<br />
to call the &#8216;new total&#8217; because it was to replace total by new total.<br />
So here, we want to do the same, for all 3.</p>
<p>So here, we create Customer, like we created TicketMachine above, we<br />
take in 3 parameters, like we did above,<br />
and we must assign the values we took in, to the &#8216;cardboard boxes&#8217; we<br />
created earlier. something like &#8220;total = newTotal&#8221;.</p>
<p>//============================</p>
<div class="msg">========</p>
<p>Right, now for getters and setters.</p>
<p>Getters</p>
<p>When Mairead is on about getters and setters,<br />
she means that getters are &#8216;methods&#8217; (method = a block of code to<br />
serve a specific purpose) that return a value of a specific<br />
field/instance variable (field/instance variable = the cardboard boxes<br />
created at the start).</p>
<p>when i create a method for returning a balance, as in TicketMachine:</p>
<p>public int getBalance( )<br />
{<br />
return balance;<br />
}</p>
<p>the int means the value of the thing you are going to return is an int.<br />
We know it&#8217;s an int because when we created our cardboard box we wrote<br />
&#8216;can only contain ints&#8217; by saying<br />
private int balance; (as way above)</p>
<p>what this means is when you write &#8216;getBalance( )&#8217; anywhere, your<br />
actually using the value of balance,<br />
so whenever you say, in any way &#8216;getBalance( )&#8217;, its treated a number,<br />
because its actually a name of a number.</p>
<p>Kinda weird concept, but when something is returned, think of it as<br />
the name of the method (getBalance( ) ) actually holds the value of<br />
whatever you returned.</p>
<p>so,</p>
<p>public type getName( )<br />
{<br />
return name;<br />
}</p>
<p>type = int, String, char, double, etc&#8230;<br />
Name/name = the cardboard box name that holds a value (fields) that<br />
was created at the start.</p>
<p>just use that formula for all the getters you need. (in this case for<br />
name, address, overdraftLimit)</p>
<p>Setters</p>
<p>A bit more tricky, generally you will have to put in some condition<br />
checks here, ( if / else statements, while loops, etc)<br />
Setters take in a value, or more than one value (seperate by commas),<br />
and set something to that value ( ie make it equal to the newValue)</p>
<p>TicketMachine example (something like this):</p>
<p>public void setBalance(int newBalance)<br />
{<br />
if ( newBalance &lt; 0 )<br />
{<br />
balance = newBalance;<br />
}<br />
else{<br />
System.out.println(&#8220;Error: Enter a positive number&#8221;);<br />
}<br />
}</p>
<p>the void in the name means there is no return value.<br />
I&#8217;ll leave a note on public/private below.</p>
<p>Obviously, we can&#8217;t have a balance below 0, it wouldn&#8217;t make any sense.</p>
<p>All setters take this kind of format,</p>
<p>if (conditions associated with it) (each condition seperated by &amp;&amp;<br />
and, || or, == equal to, and !=, not equal to)</p>
<p>so you could have:</p>
<p>public void setBalance(int newBalance)<br />
{<br />
if ( ( newBalance &gt; 0 ) &amp;&amp; (newBalance  &lt; 300))</p>
<p>so if the value newBalance is 50, [setBalance(50); means newBalance is<br />
50, as your entering 50 into the parameters, thats how it works] then<br />
what ever is in the &#8216;if&#8217; parts brackets gets executed, here balance =<br />
newBalance.<br />
Generally she gives us conditions but sometimes we&#8217;ll have to cop them<br />
ourselves.</p>
<p>like overdraftLimit needs to be less than or equal to 0.</p>
<p>the else part is executed when the condition check if false, for<br />
instance if 400 was entered into setBalance. setBalance(400);</p>
<p>here, &#8220;Error: Enter a positive number&#8221;, is shown up on screen.<br />
&#8220;System.out.println&#8221; is used to show stuff on the monitor.</p>
<p>all setters are done this way.</p>
<p>public void setName(type newName)<br />
{<br />
if ( condition )<br />
{<br />
name = newName;<br />
}<br />
else{<br />
System.out.println(&#8220;asdfghjkjhgfdsa&#8221;)<br />
}<br />
}</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chilloxk.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chilloxk.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chilloxk.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chilloxk.wordpress.com&amp;blog=6291692&amp;post=8&amp;subd=chilloxk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chilloxk.wordpress.com/2009/01/26/java-1-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e150e273cc3be19665608a2243027d4c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">chilloxk</media:title>
		</media:content>
	</item>
	</channel>
</rss>
