<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-688720751375958276</id><updated>2011-11-08T07:02:05.407-08:00</updated><title type='text'>Programming I - Java</title><subtitle type='html'>This blog will guide you to learn java through several classes.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cop2210.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cop2210.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Pabs</name><uri>http://www.blogger.com/profile/06197759215287571103</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-688720751375958276.post-6756821440067173583</id><published>2007-10-02T19:34:00.000-07:00</published><updated>2007-10-02T23:15:50.462-07:00</updated><title type='text'>Continuation of Class 2</title><content type='html'>&lt;span style="font-weight: bold;"&gt;ScrollBars&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;As you know, when you make a JOP.SMD(null,"Message"); a small pop up window will come, sometimes you need MORE than that. You want to have a window with scroll bars to have enough space for all the information you'd like to enter.&lt;br /&gt;&lt;br /&gt;Well, this is what you need to do:&lt;br /&gt;&lt;br /&gt;JTextArea textBox = new JTextArea(20,20);&lt;br /&gt;textBox.setText(someString);&lt;br /&gt;JOP.SMG(null, new JScrollPane(textBox));&lt;br /&gt;&lt;br /&gt;And well, that's it.&lt;br /&gt;&lt;br /&gt;-----&lt;br /&gt;&lt;br /&gt;Now, we are going to move on, and I'll post two of the assignments you can try, and if you have any questions you can post comments, and such.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;    &lt;span style="font-size:85%;"&gt;I&lt;span style="font-family:Bitstream Vera Sans,sans-serif;"&gt;n this exercise you are to create a new main class to do the following:&lt;/span&gt;&lt;/span&gt; &lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Declare  a String variable and assign to it a String object constructed from  your name.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Write  a statement to display the variable in a JOptionPane window.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Declare  an int variable and assign to it the value of the String variable's  length method.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Write  a statement to display the variable in a JOptionPane window.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Declare  a String variable named out and assign to it the name variable  followed by a space followed by the int variable (use the +  operator).&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Construct  a BankAccount object using "123456789" as the account  number and assign it to a Bank Account variable. The BankAccount  class is available from Lab Exercise One.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Deposit  100 dollars into the account using the variable and the BankAccount  class's deposit method.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Use  the + operator to concatenate the BankAccount variable to the String  variable out.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Construct  a JTextArea with 20 rows and 20 columns and assign it to a JTextArea  variable.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Use  the setText method of JTextArea to output the String variable out on  the JTextArea.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Construct  a JScrollPane from the JTextArea and display it in a JOptionPane  window.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style=";font-family:Bitstream Vera Sans,sans-serif;font-size:85%;"  &gt;Run  your program.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SOLUTION FOR THE ASSIGNMENT -- DO IT, TRY IT, ASK QUESTIONS, IF YOU STILL CAN'T FIGURE IT OUT, LOOK BELOW.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;import javax.swing.*;&lt;br /&gt;/**&lt;br /&gt;* Write a description of class Main here.&lt;br /&gt;*&lt;br /&gt;* @author Pablo&lt;br /&gt;* @version (a version number or a date)&lt;br /&gt;*/&lt;br /&gt;public class Main&lt;br /&gt;{&lt;br /&gt;  /**&lt;br /&gt;   * Constructor for objects of class Main&lt;br /&gt;   */&lt;br /&gt;  public Main()&lt;br /&gt;  {&lt;br /&gt;      // initialise instance variables&lt;br /&gt;  }&lt;br /&gt;  public static void main(String[] args)&lt;br /&gt;  {&lt;br /&gt;      String myName = "Your Name";&lt;br /&gt;      JOptionPane.showMessageDialog(null,myName);&lt;br /&gt;      int nameLength = myName.length();&lt;br /&gt;      JOptionPane.showMessageDialog(null,"Name length is: " + nameLength);&lt;br /&gt;      BankAccount userAcc = new BankAccount ("123456789");&lt;br /&gt;      userAcc.deposit(100.00);&lt;br /&gt;      String accountBalance = userAcc.getAccountNumber() + " " + userAcc.getBalance();&lt;br /&gt;      JTextArea scrollArea = new JTextArea(20,20);&lt;br /&gt;      scrollArea.setText(accountBalance);&lt;br /&gt;      JOptionPane.showMessageDialog(null, new JScrollPane(scrollArea));&lt;br /&gt;  }&lt;br /&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/688720751375958276-6756821440067173583?l=cop2210.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cop2210.blogspot.com/feeds/6756821440067173583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=688720751375958276&amp;postID=6756821440067173583' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/6756821440067173583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/6756821440067173583'/><link rel='alternate' type='text/html' href='http://cop2210.blogspot.com/2007/10/continuation-of-class-2.html' title='Continuation of Class 2'/><author><name>Pabs</name><uri>http://www.blogger.com/profile/06197759215287571103</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-688720751375958276.post-6842410139070872350</id><published>2007-10-02T19:17:00.001-07:00</published><updated>2007-10-02T19:33:59.982-07:00</updated><title type='text'>Class 2</title><content type='html'>BankAccount class* (http://rapidshare.com/files/59886458/BankAccount.java.html)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;You need NETBEANS to code in Java&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;An object of the BankAccount class has a String as an account number, and a double indicating your balance.&lt;br /&gt;&lt;br /&gt;void deposit (double amount)&lt;br /&gt;void withdraw (double amount)&lt;br /&gt;double getBalance()&lt;br /&gt;&lt;br /&gt;A &lt;span style="font-style: italic;"&gt;variable&lt;/span&gt; in Java is he name of a place to store values.&lt;br /&gt;Variable names start with a lowercase letter (like methods).&lt;br /&gt;Variables can only hold one type of data, so the type must be declared.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;synatax: &lt;/span&gt;type variableName;&lt;br /&gt;&lt;br /&gt;Examples:&lt;br /&gt;- int numberOfItems;&lt;br /&gt;- double price;&lt;br /&gt;- String word;&lt;br /&gt;- BankAccount myAccount;&lt;br /&gt;&lt;br /&gt;Assignment operator is &lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;=&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;numberOfItems=37;&lt;br /&gt;price = 15.99;&lt;br /&gt;word = new String("abcde") or word = "abcde";&lt;br /&gt;&lt;br /&gt;A constructor of a class object is a method of the class that has the same name as the class. It can have inputs like any other class but its description does not have a return type.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;new ClassName(input)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To "call" a method to operate on an object we use the dot (.) notation&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;syntax: &lt;/span&gt;variable.method(...)&lt;br /&gt;&lt;br /&gt;int lenght= word.length();&lt;br /&gt;myAccount.deposit(10000.00);&lt;br /&gt;&lt;br /&gt;Primitive types (int, char, double, boolean) hold values and class types (BankAccount, String, ...) references to class objects.&lt;br /&gt;&lt;br /&gt;Class objects must be constructed using the class method called a constructor. A constructor method has the same name as the class and new returns a reference.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SomeClass someClassVariable = new someClass(...);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To access methods of the object that &lt;span style="font-style: italic;"&gt;someClassVariable&lt;/span&gt; refers to, use . notation &lt;span style="font-style: italic;"&gt;someClassVariable.aMethod(...);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Examples:&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;BankAccount anAccount = new BankAccount("377");&lt;br /&gt;anAccount.deposit(100.0);&lt;br /&gt;JOptionPane.ShowMessageDialog(null, anAccount.getBalance());&lt;br /&gt;String aWord = new String("abcde");&lt;br /&gt;String anotherWord = "12345";&lt;br /&gt;String s= aWord + anotherWord; This equals: &lt;span style="font-weight: bold;"&gt;abcde12345&lt;/span&gt;&lt;br /&gt;*JOP.SMD(null, "Balance is" + anAccount.Balance());&lt;br /&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-style: italic;"&gt;Abbreviation of JOptionPane.~&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;+ is the concatenation operator for the String class&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Methods of the String class&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;int length()&lt;br /&gt;char charAt(int position) where 0&lt;=position&lt;length else an error occurs&lt;br /&gt;int indexOf(char ch) returns left most position of ch; returns -1 if ch is not there&lt;br /&gt;int indexOf(String s) same as above&lt;br /&gt;String substring(int frmPosition) returns the substring starting at frmPosition to the end&lt;br /&gt;where 0&lt;=frmPosition&lt;=length&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/688720751375958276-6842410139070872350?l=cop2210.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cop2210.blogspot.com/feeds/6842410139070872350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=688720751375958276&amp;postID=6842410139070872350' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/6842410139070872350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/6842410139070872350'/><link rel='alternate' type='text/html' href='http://cop2210.blogspot.com/2007/10/class-2.html' title='Class 2'/><author><name>Pabs</name><uri>http://www.blogger.com/profile/06197759215287571103</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-688720751375958276.post-2338337319719687952</id><published>2007-10-02T16:02:00.000-07:00</published><updated>2007-10-02T16:21:44.804-07:00</updated><title type='text'>First Class</title><content type='html'>Java is an OOP (Object Oriented Programming) language i,e Java has classes.&lt;br /&gt;&lt;br /&gt;A &lt;span style="font-style: italic;"&gt;class&lt;/span&gt; is a description of an object&lt;br /&gt;An &lt;span style="font-style: italic;"&gt;object&lt;/span&gt; contains data and methods (We can call it &lt;span style="font-style: italic;"&gt;instructions)&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;/span&gt;An &lt;span style="font-style: italic;"&gt;object&lt;/span&gt; is like a special purpose computer.&lt;br /&gt;A &lt;span style="font-style: italic;"&gt;class&lt;/span&gt; is like the specs of the object computer.&lt;br /&gt;&lt;br /&gt;There are 3 kinds of classes:&lt;br /&gt;&lt;br /&gt;(I) &lt;span style="font-weight: bold;"&gt;Main class: &lt;/span&gt;contains the main method i,e, the start instruction&lt;br /&gt;(II) &lt;span style="font-weight: bold;"&gt;Utility class: &lt;/span&gt;general tools&lt;br /&gt;(III) &lt;span style="font-weight: bold;"&gt;Data class: &lt;/span&gt;used and defined by programmer i,e, custom class&lt;br /&gt;&lt;br /&gt;A &lt;span style="font-style: italic;"&gt;data type&lt;/span&gt; is a collection of values and operations on those values. Example: A class&lt;br /&gt;&lt;br /&gt;Primitive types in Java:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;:&lt;/span&gt;&lt;br /&gt;values: 37, -4, 0&lt;br /&gt;operations: +, -, *, /, %&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;double:&lt;/span&gt;&lt;br /&gt;values: 37.0, 14.99, -3.2&lt;br /&gt;operations: +, -, *, /&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;char:&lt;/span&gt;&lt;br /&gt;values: 'a', '3', '\', '\\'&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;boolean: &lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;values: true, false&lt;br /&gt;operations: !, &amp;amp;&amp;amp;, ||&lt;br /&gt;&lt;br /&gt;To create an object of a class use the class constructor.&lt;br /&gt;Classes have descriptions of methods.&lt;br /&gt;A description has the following form:&lt;br /&gt;&lt;br /&gt;return-type name(input)&lt;br /&gt;&lt;span style="font-style: italic;"&gt;or&lt;/span&gt;&lt;br /&gt;void name(input)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;NOTE: &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;pricePerItem -&gt; &lt;span style="font-weight: bold;"&gt;method&lt;/span&gt;&lt;br /&gt;PricePerItem -&gt; &lt;span style="font-weight: bold;"&gt;class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;String class&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;An object of the String class is a list (or sequence) of characters. The positions are 0, 1, 2, 3...&lt;br /&gt;&lt;br /&gt;Example: "house" where h is at position 0, o at position 1, etc.&lt;br /&gt;&lt;br /&gt;Some methods are:&lt;br /&gt;&lt;br /&gt;char charAt(int position);&lt;br /&gt;int indexOf(char ch);&lt;br /&gt;int indexOf(String s);&lt;br /&gt;boolean contains(String s);&lt;br /&gt;String substring(int first, int last);&lt;br /&gt;String replace(s1, s2); //replaces instances of s1 by s2&lt;br /&gt;&lt;br /&gt;End of class 1, if questions or would like to give feedback, please, comment.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/688720751375958276-2338337319719687952?l=cop2210.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cop2210.blogspot.com/feeds/2338337319719687952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=688720751375958276&amp;postID=2338337319719687952' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/2338337319719687952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/688720751375958276/posts/default/2338337319719687952'/><link rel='alternate' type='text/html' href='http://cop2210.blogspot.com/2007/10/first-class.html' title='First Class'/><author><name>Pabs</name><uri>http://www.blogger.com/profile/06197759215287571103</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
