<?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/"
	>

<channel>
	<title>Shibing&#039;s Blog</title>
	<atom:link href="http://shibingsprojects.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://shibingsprojects.net/blog</link>
	<description>Powerful New Features of PHP, Powerful New Shibing’s Blog~!</description>
	<lastBuildDate>Thu, 03 Feb 2011 23:38:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<atom:link rel="next" href="http://shibingsprojects.net/blog/?feed=rss2&amp;page=2" />

		<item>
		<title>Assignment #3, FactOrFib &#8211; Factorial and Fibonacci Number Calculator</title>
		<link>http://shibingsprojects.net/blog/?p=138</link>
		<comments>http://shibingsprojects.net/blog/?p=138#comments</comments>
		<pubDate>Thu, 03 Feb 2011 23:38:52 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shibingsprojects.net/blog/?p=138</guid>
		<description><![CDATA[Source Code update,  code is already commented. So they are easy to understand. JavaDocs are available at: http://doc.shibingsprojects.com/javadoc/FactOrFib Source codes are below. The main class and method for the program, aka, the kicker. package edu.heidelberg.factorfib.cps350.shuang; /** * FactOrFib main class. * * &#60;P&#62;The main class to drive the whole program. * * * @author Shibing [...]]]></description>
			<content:encoded><![CDATA[<p>Source Code update,  code is already commented. So they are easy to understand.</p>
<p>JavaDocs are available at: <a href="http://doc.shibingsprojects.com/javadoc/FactOrFib" target="_blank">http://doc.shibingsprojects.com/javadoc/FactOrFib</a></p>
<p>Source codes are below.</p>
<p>The main class and method for the program, aka, the kicker.</p>
<pre class="brush: java">

package edu.heidelberg.factorfib.cps350.shuang;

/**
* FactOrFib main class.
*
* &lt;P&gt;The main class to drive the whole program.
*
*
* @author Shibing Huang &lt;mr.shibing @ mac.com&gt;
* &lt;P&gt;Heidelberg University
*
* @version 2011.01.23
*/

public class FOFMain {

/**
* Main class for FactOrFib
*
* Just a short and quick driver
*
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub

FOFIODriver pgmStart = new FOFIODriver();

pgmStart.cmdEntry();

}

}
</pre>
<p><span id="more-138"></span></p>
<p>The IO Driver for the program for user/program interactions.</p>
<pre class="brush: java">

package edu.heidelberg.factorfib.cps350.shuang;

import java.math.BigInteger;
import java.util.Scanner;

/**
* User Input IO driver class - console based.
*
* &lt;P&gt;Class to collect user inputs and drive the calculator,
* to pass the user inputs to FactAndFib and collect the
* results that is returned from FactAndFib.
*
* &lt;P&gt;Please note that this class also has control and looping
* for users to easily &quot;Do-Again&quot; the calculator.
*
*
* @author Shibing Huang &lt;mr.shibing @ mac.com&gt;
* &lt;P&gt;Heidelberg University
*
*
*
* @version 2011.01.23
*/

public class FOFIODriver
{
////////////////fields/////////////
/**
* Protected value for check to see if user want to
* continue using the calculator.
*/
private boolean doAgain = true;

////////////constructors//////////////

/**
* Constructor.
*
* Default super() constructor.
*/
public FOFIODriver ()
{
super();
}

/////////////methods//////////////////

/**
* Command Entry Method.
*
* This method provides program and user interaction functions, and
* also drive the FactAndFib class, to collect user input to pass
* it on and collect the return results from the FactAndFib class.
*
*/
public void cmdEntry()
{
//Create user input variable
int usrNum;

//Create scanner object
Scanner usrCmd = new Scanner(System.in);

//Start console outputs
System.out.println (&quot;Welcome To FactOrFib Program.&quot;);

//When user want to do it again, it enters, else, out.
while (doAgain)
{
//command variables
String finalcmd = &quot;&quot;;
String repeatcmd = &quot;&quot;;

System.out.print (&quot;Please provide a integer of your wish:&quot;);

//check to see if user input the right data
//also catches wrong inputs to avoid exceptions
while (!usrCmd.hasNextInt())
{
System.out.println (&quot;Please provide me a Integer in order to continue.&quot;);
System.out.print (&quot;Please enter an integer:&quot;);
usrCmd.next();
}

usrNum = usrCmd.nextInt();

System.out.println (&quot;\nWould you like to find the factorial of the number or the Fibonacci number of that position?&quot;);
System.out.println(&quot;For Factorial, input \&quot;fact\&quot;. For Fibonacci Number, input \&quot;fib\&quot;.&quot;);
System.out.print(&quot;Your Command: &quot;);

//control variable to count user input error.
int factOrFibErrors = 0;

//check to see if user enters the right command
while (!finalcmd.equalsIgnoreCase(&quot;fact&quot;)&amp;&amp;!finalcmd.equalsIgnoreCase(&quot;fib&quot;))
{

factOrFibErrors ++;

//control block for wrong user inputs to remind user
if (factOrFibErrors &gt; 1)
{
System.out.println (&quot;Please only input fact or fib&quot;);
System.out.println(&quot;For Factorial, input \&quot;fact\&quot;. For Fibonacci Number, input \&quot;fib\&quot;.&quot;);
System.out.print(&quot;Your Command: &quot;);
}

finalcmd = usrCmd.next();

}

//when user input valid, check for factorial or fibonacci
if (finalcmd.equalsIgnoreCase(&quot;fact&quot;))
{
//create result variable (null for now)
BigInteger result;

System.out.println (&quot;\nFactorial Calculator: \n&quot;);

//While System RAM 1GB, BigInt does not display right, so control it to less than 9200
if (usrNum &gt;= 9201)
{
System.out.println (&quot;Your Value: &quot; + usrNum +  &quot; is Too Big, Answer won&#039;t show up in current platform.&quot;);
}

//Factorial calculation
else
{
result = FactAndFib.factorial(usrNum);
System.out.println (&quot;The factorial to &quot; + usrNum + &quot; is &quot; + result + &quot;. \n&quot;);

//output result and create bit counter variable
BigInteger  count = result;
int resultSize = 0;

//result bits counter
while (count.compareTo(BigInteger.ZERO) &gt; 0)
{
count = count.divide(BigInteger.TEN);
resultSize++;
}

//output result size
if (resultSize &gt; 10)
{
System.out.println (&quot;Your Result is &quot; + resultSize + &quot; bits long.&quot;);
}

else
{
System.out.println (&quot;Your Result is &quot; + resultSize + &quot; bit long.&quot;);
}

}
}

//If Fib, then use fibSeq
else
{
//create result variable (null)
BigInteger result;

System.out.println (&quot;\nFibonacci Sequence Calculator: \n&quot;);

//While System RAM 1GB, BigInt does not display right, so control it to less than 156757
if (usrNum &gt;= 156758)
{
System.out.println (&quot;Your Value: &quot; + usrNum +  &quot; is Too Big, Answer won&#039;t show up in current platform.&quot;);
}

//if input okay
else
{
//do calculation and output results
result = FactAndFib.fibSeq(usrNum);
System.out.println (&quot;The Fibonacci Sequence of &quot; + usrNum + &quot;th position is &quot; + result + &quot;. \n&quot;);

//bit size counter
BigInteger  count = result;
int resultSize = 0;

while (count.compareTo(BigInteger.ZERO) &gt; 0)
{
count = count.divide(BigInteger.TEN);
resultSize++;
}

//output bit size
if (resultSize &gt; 10)
{
System.out.println (&quot;Your Result is &quot; + resultSize + &quot; bits long.&quot;);
}

else
{
System.out.println (&quot;Your Result is &quot; + resultSize + &quot; bit long.&quot;);
}
}
}

//ask user to run again or not
System.out.print(&quot;\nWould you like to calculate another value? (y/n)&quot;);

//user input errors check
int doAgainerrors = 0;

while (!repeatcmd.equalsIgnoreCase(&quot;y&quot;)&amp;&amp;!repeatcmd.equalsIgnoreCase(&quot;n&quot;))
{

doAgainerrors ++;

if (doAgainerrors &gt; 1)
{
System.out.println (&quot;Please only use y or n&quot;);
System.out.print(&quot;Would you like to calculate another value? (y/n)&quot;);
}
repeatcmd = usrCmd.next();

}

//change fields for do-again control
if (repeatcmd.equalsIgnoreCase(&quot;y&quot;))
{
doAgain = true;
}

else
{
doAgain = false;
System.out.println (&quot;\nThank you for using the Calculator!&quot;);
}
}

}

}//end cmdEntry()
</pre>
<p>Finally, the functional code, the calculator methods</p>
<pre class="brush: java">

package edu.heidelberg.factorfib.cps350.shuang;

import java.math.BigInteger;

/**
* FactAndFib Class.
*
* &lt;P&gt;Factorial or Fibonacci Sequence Calculator Class - console interfaces.
*
*
*
* @author Shibing Huang &lt;mr.shibing @ mac.com&gt;
* &lt;P&gt;Heidelberg University
*
*
*
* @version 2011.01.23
*
*/

public class FactAndFib
{
///////fields//////////

///////constructor////////

///////methods///////////

/**
* Fibonacci Sequence Calculation method
*
* The method take an integer as a position parameter
* to plug into the method to calculate the value of
* the Fibonacci sequence of that position
*
* @param i position of the Fobonacci sequence
* @return the value of the given position
*/
public static BigInteger fibSeq(int i)
{
//Fibonacci Number 1, defined as int, later converted to BigInt
int preFebNum1 = 0;
String preFebNum1String = Integer.toString(preFebNum1);
BigInteger febNum1 = new BigInteger(preFebNum1String);

//fibnacci Number 2, defined as int, later converted to BigInt
int preFebNum2 = 1;
String preFebNum2String = Integer.toString(preFebNum2);
BigInteger febNum2 = new BigInteger(preFebNum2String);

//Calculate fibobacci number
for(long m =0; m &lt; i; m++)
{
BigInteger savedFebNum = febNum1;
febNum1 = febNum2;
febNum2 = savedFebNum.add(febNum2);
}

//hand back to answer
return febNum1;
}//end fibSeq

/**
* Factorial Calculation method
*
* The method take an integer as a base parameter
* to plug into the method to calculate the value of
* the factorial of that number
*
* @param i number that need to be calculated
* @return the factorial of the given number
*/
public static BigInteger factorial (int i)
{
//Convert the input integer to Bigint for calculation
String resultString = Integer.toString(i);
BigInteger result = new BigInteger(resultString);
int tempVal;

//calculate the factorial of that number
while (i &gt; 1)
{
tempVal = i - 1;
String tempValString = Integer.toString(tempVal);
BigInteger tempValBI = new BigInteger(tempValString);
result = result.multiply(tempValBI);

i = i - 1;
}

//hand back to result
return result;
}//end factorial
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=138</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Final Project Source Code *updating</title>
		<link>http://shibingsprojects.net/blog/?p=120</link>
		<comments>http://shibingsprojects.net/blog/?p=120#comments</comments>
		<pubDate>Wed, 28 Apr 2010 23:19:25 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.shibingsprojects.com/?p=120</guid>
		<description><![CDATA[MySQL PHP Examples &#60;?php $sqlUsrName = &#34;iw3htp4&#34;; $sqlPwd = &#34;iw3htp4&#34;; $database = &#34;bookmarks&#34;; mysql_connect(localhost,$sqlUsrName,$sqlPwd); @mysql_select_db($database) or die( &#34;Unable to select database&#34;); $query = &#34;SELECT * FROM user&#34;; $test = mysql_query($query); while($row = mysql_fetch_array($test, MYSQL_ASSOC)) { printf(&#34;ID: %s Name: %s Password %s&#34;, $row[&#34;user_id&#34;], $row[&#34;user_name&#34;], $row[&#34;password&#34;] . &#34;&#60;br /&#62;&#34;); } mysql_free_result($test); mysql_close(); ?&#62; SQL statement for INNER [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL PHP Examples</p>
<pre class="brush: php">
&lt;?php

$sqlUsrName = &quot;iw3htp4&quot;;
$sqlPwd = &quot;iw3htp4&quot;;
$database = &quot;bookmarks&quot;;

mysql_connect(localhost,$sqlUsrName,$sqlPwd);
@mysql_select_db($database) or die( &quot;Unable to select database&quot;);

$query = &quot;SELECT * FROM user&quot;;
$test = mysql_query($query);

while($row = mysql_fetch_array($test, MYSQL_ASSOC))
{
    printf(&quot;ID: %s  Name: %s Password %s&quot;, $row[&quot;user_id&quot;], $row[&quot;user_name&quot;], $row[&quot;password&quot;] . &quot;&lt;br /&gt;&quot;);
}

mysql_free_result($test);

mysql_close();
?&gt;
</pre>
<p>SQL statement for INNER JOIN two tables</p>
<pre class="brush: php">
&lt;?php

$sqlUsrName = &quot;iw3htp4&quot;;
$sqlPwd = &quot;iw3htp4&quot;;
$database = &quot;bookmarks&quot;;

mysql_connect(localhost,$sqlUsrName,$sqlPwd);
@mysql_select_db($database) or die( &quot;Unable to select database&quot;);

$query = &quot;SELECT * FROM bmark
            INNER JOIN user
            ON bmark.user_id = user.user_id
            WHERE bmark.user_id =&#039;1&#039;&quot;;
$test = mysql_query($query);

while($row = mysql_fetch_array($test, MYSQL_ASSOC))
{
    printf(&quot;ID: %s Name: %s  Title: %s URL %s&quot;, $row[&quot;user_id&quot;], $row[&quot;user_name&quot;], $row[&quot;page_title&quot;], $row[&quot;url&quot;] . &quot;&lt;br /&gt;&quot;);
}

mysql_free_result($test);

mysql_close();
?&gt;
</pre>
<p>for inner join 3 tables</p>
<pre class="brush: php">
&lt;?php

$sqlUsrName = &quot;iw3htp4&quot;;
$sqlPwd = &quot;iw3htp4&quot;;
$database = &quot;bookmarks&quot;;

mysql_connect(localhost,$sqlUsrName,$sqlPwd);
@mysql_select_db($database) or die( &quot;Unable to select database&quot;);

$query = &quot;SELECT * FROM bmark, category, user
            WHERE bmark.user_id = user.user_id
            AND bmark.category_id = category.category_id
            AND bmark.user_id=&#039;1&#039;&quot;;
$test = mysql_query($query);

while($row = mysql_fetch_array($test, MYSQL_ASSOC))
{
    printf(&quot;ID: %s Name: %s  Title: %s URL %s CAT %s&quot;, $row[&quot;user_id&quot;], $row[&quot;user_name&quot;], $row[&quot;page_title&quot;], $row[&quot;url&quot;], $row[&quot;category_name&quot;]. &quot;&lt;br /&gt;&quot;);
}

mysql_free_result($test);

mysql_close();
?&gt;
</pre>
<p>A better habit and better way to organize codes is....<br />
To put the actual functional codes into separate pages...<br />
For example, you would actually split header, content(body) and footer into different pages and put the SQL connection page in a other file. Well, let's take a look...</p>
<p>For a Index page, you only have things that are necessary</p>
<pre class="brush: php">
&lt;?php

$title =&quot;Index Page&quot;;

include &#039;includes/header.php&#039;;
include &#039;includes/sqlconn.php&#039;;

$query = &quot;SELECT * FROM bmark, category, user
            WHERE bmark.user_id = user.user_id
            AND bmark.category_id = category.category_id
            AND bmark.user_id=&#039;1&#039;&quot;;

$test = sqlConnection($query);

while($row = mysql_fetch_array($test, MYSQL_ASSOC))
{
    printf(&quot;ID: %s Name: %s  Title: %s URL %s CAT %s&quot;, $row[&quot;user_id&quot;], $row[&quot;user_name&quot;], $row[&quot;page_title&quot;], $row[&quot;url&quot;], $row[&quot;category_name&quot;]. &quot;&lt;br /&gt;&quot;);
}

sqlConnClose($test);

include &#039;includes/footer.php&#039;;
?&gt;
</pre>
<p>So...what you see above are just basically includes and function calls. But in fact, you are implementing a whole page. Think about it.</p>
<p>okay, session control is not that hard at all.<br />
IF you want to start a session, basically just call to session_start(), and it will do it.</p>
<p>to log on, you first need to connect to database and check to see if user and password match the database records.</p>
<p>a password/username check can be easily done with this:</p>
<pre class="brush: php">
function dataCheck($query)
{
    $result = sqlConnection($query);
    $check = mysql_num_rows($result);
    $checkResult = $check;

    sqlConnClose($result);

    return $checkResult;
}
</pre>
<p>and...the connection function is easy too</p>
<pre class="brush: php">
function sqlConnection($query)
{
    $sqlUsrName = &quot;iw3htp4&quot;;
    $sqlPwd = &quot;iw3htp4&quot;;
    $database = &quot;bookmarks&quot;;

    mysql_connect(&#039;localhost&#039;,$sqlUsrName,$sqlPwd);
    @mysql_select_db($database) or die( &quot;Unable to select database&quot;);

    $test = mysql_query($query);

    return $test;
}

so, you only need to check the return of the value is 0 or not. If it is 0, then it means it&#039;s mismatch.
</pre>
<p>To start a check, you simply select username and password and compare them.<br />
Then, if match successful, you can start a session</p>
<p>[code lang = 'php']<br />
include 'includes/sqlconn.php';<br />
                            $query = "SELECT user_name, password FROM user<br />
                                        WHERE user_name='$usrName'<br />
                                        AND password='$usrPwd'";</p>
<p>                            $check = dataCheck($query);</p>
<p>                            //verify name and password<br />
                            if($check === 0)<br />
                            {<br />
                                print ("
<div class='warnings'>User Name and Password Mismatch!</div>
<p>");<br />
                            }</p>
<p>                            else<br />
                            {<br />
                                session_start();<br />
                                $_SESSION['username'] = $usrName;</p>
<p>                                header( 'Location: index.php' ) ;<br />
                            }<br />
[/code]</p>
<p>well, not you have a session!<br />
the following code is to check the existence of session and return a logout function</p>
<pre class="brush: php">
&lt;?php

//check session existance and output links
function sessionCheck()
{
    session_start();
    if(isset ($_SESSION[&#039;username&#039;]))
    {

        $result = &#039;&lt;a href=&quot;manage.php&quot; title=&quot;Click Here To Manage Your Personal Bookmarks and Account&quot;&gt;Logged In as: &#039; . $_SESSION[&#039;username&#039;] . &#039;&lt;/a&gt;
                    &#039; . &#039;&amp;amp;nbsp;&#039; .&#039;&lt;a href = &quot;?action=logout&quot;&gt;[Logout]&lt;/a&gt;&#039;;
        if(isset($_GET[&#039;action&#039;]))
        {
            $action = $_GET[&#039;action&#039;];
            if ($action == &quot;logout&quot;)
            {
                session_destroy();
                header( &#039;Location: index.php&#039; ) ;
            }
        }
    }

    else
    {
        $result = &#039;&lt;a href=&quot;login.php&quot; title=&quot;Click Here To Register Or Login&quot;&gt;Login | Register &lt;/a&gt;&#039;;
    }

    return $result;
}

//check session existance
function sessionExists()
{
    if(isset ($_SESSION[&#039;username&#039;]))
    {
        $result = true;

    }

    else
    {
        $result = false;
    }

    return $result;

}

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=120</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web App Dev. HW #5 Source Codes</title>
		<link>http://shibingsprojects.net/blog/?p=117</link>
		<comments>http://shibingsprojects.net/blog/?p=117#comments</comments>
		<pubDate>Fri, 16 Apr 2010 02:31:06 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.shibingsprojects.com/?p=117</guid>
		<description><![CDATA[processSurvey.php &#60;?php print(&#039;&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;&#039;); ?&#62; &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#34;&#62; &#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34; xml:lang=&#34;en&#34; lang=&#34;en&#34;&#62; &#60;head&#62; &#60;title&#62;Thank you! &#124; Your Result Page&#60;/title&#62; &#60;style type=&#34;text/css&#34;&#62; body { background-color:#FFF8DC; font-family: Arial, Tahoma, Geneva, Verdana, sans-serif } h2 { text-align: center; background-color: #FFE4E1; margin-left: auto; margin-right: auto; margin-bottom: 2%; width: 60%; color: #4682B4; border-style: solid; [...]]]></description>
			<content:encoded><![CDATA[<p>processSurvey.php</p>
<p><span id="more-117"></span></p>
<pre class="brush: php">

&lt;?php print(&#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#039;); ?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;title&gt;Thank you! | Your Result Page&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
body    { background-color:#FFF8DC;
font-family: Arial, Tahoma, Geneva, Verdana, sans-serif }

h2
{
text-align: center;
background-color: #FFE4E1;
margin-left: auto;
margin-right: auto;
margin-bottom: 2%;
width: 60%;
color: #4682B4;
border-style: solid;
border-color: black;
border-width: 4px;
padding-top: 1%;
padding-bottom: 1%;
padding-left: 5%;
padding-right: 5% }

.content
{
text-align: center;
width: 50%;
margin-left: auto;
margin-right: auto;
margin-bottom: 2%;
border-style: dashed;
border-color: black;
border-width: 2px;
padding-bottom: 1%;
padding-left: 1%;
padding-right: 1%;
font-size: 130%
}

.warnings
{
background-color:#FF1493;
font-size: 150%;
width: 50%;
margin-left: auto;
margin-right: auto;
border-style: dashed;
border-color: black;
}

.buttons
{
margin: 2%;
text-align: center;
margin-left: auto;
margin-right: auto;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Hello &lt;?php print($_POST[&quot;customerName&quot;]); ?&gt;, Your Result is showed below:&lt;/h2&gt;

&lt;?php
//Populates received POST variables
$custName = $_POST[&quot;customerName&quot;];
$purchDate = $_POST[&quot;purchaseDate&quot;];
$purchNum = $_POST[&quot;purchaseNumber&quot;];
$selectionRate = $_POST[&quot;productSelection&quot;];
$priceRate = $_POST[&quot;prices&quot;];
$deliveryRate = $_POST[&quot;deliveryService&quot;];
$emailAdd = $_POST[&quot;email&quot;];

//populates file handling variables
$fileName = &quot;results.txt&quot;;
$fileHandle;
define(&quot;LOCK&quot;, 2);
define(&quot;UNLOCK&quot;, 3);
$writeString;

//populates other necessary variables
$emailAddExists;
$emailAddValid;
$emailAddEmpty;
$resultString;
$infoValid;
$warnMsg;

//check to see if email address exists
$emailAddExists;

//if customer name is empty, add some error message
if ($custName === &quot;&quot;)
{
$warnMsg = &quot;Please Provide Your Name. &lt;br /&gt;&quot;;
$infoValid = false;
}

//if name okay, info is valid
else
{
$infoValid = true;
}

//if purchased date is blank, add error message
if($purchDate === &quot;&quot;)
{
$warnMsg = $warnMsg . &quot;Please Provide Your Purchase Date!&quot;;
$infoValid = false;
}

//else, check name first, then decide
else
{
if ($infoValid === false)
{
$infoValid = false;
}

else
{
$infoValid = true;
}
}

//if name and date are all okay
if ($infoValid)
{
//if email address empty, skip email address duplication check
if ($emailAdd === &quot;&quot;)
{
$emailAddExists = false;
$emailAddValid = true;
$emailAddEmpty = true;
}

//if email address provided, check email format and duplication
else
{
$emailAddEmpty = false;

if(eregi(&quot;^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$&quot;, $emailAdd))
{
//Email Address Valid
$emailAddValid = true;

//Check file existance
if (file_exists($fileName))
{
$fileHandle = fopen($fileName, &quot;r&quot;) or die (&quot;Error - Cannot Open $fileName for reading&quot;);
//file lock
flock($fileHandle, LOCK);
$file_String = fread($fileHandle, filesize($fileName));
if (stristr($file_String, $emailAdd) === FALSE)
{
$emailAddExists = false;
}
else
{
$emailAddExists = true;
}
//file unlock and close
flock($fileHandle, UNLOCK);
fclose($fileHandle);
}

//if file not exist, creat one
else
{
$fileHandle = fopen($fileName, &quot;w&quot;) or die (&quot;Error - Cannot Open $fileName for writing&quot;);
fclose($fileHandle);
}
}

//output error message if email address invalid
else
{
print(&quot;&lt;div class=&#039;content&#039;&gt; Sorry, $custName. &lt;br /&gt; The email address you supplied: &lt;br /&gt; $emailAdd is invalid. &lt;br /&gt;&quot;);
$emailAddValid = false;
}
}

//if email address valid
if ($emailAddValid === true)
{
//if email address duplicates, warn user
if ($emailAddExists === true)
{
print (&quot;&lt;div class=&#039;content&#039;&gt; Sorry, $custName! &lt;br /&gt;You have already submitted your email before.&lt;br /&gt;
Please do not try to get more than one coupon.&lt;/div&gt;&quot;);
}

//else, proceed write, email sending (if email not provided, write , but not email)
else
{
//Pre-read into Write String
$fileHandle = fopen($fileName, &quot;r&quot;) or die (&quot;Error - Cannot Open $fileName for reading&quot;);
//file lock
flock($fileHandle, LOCK);
$writeString = fread($fileHandle, filesize($fileName));
//file unlock and close
flock($fileHandle, UNLOCK);
fclose($fileHandle);

//Start Process text file writing
$fileHandle = fopen($fileName, &quot;w&quot;) or die(&quot;Error - Cannot Open $fileName for writing&quot;);

if (is_writeable($fileName))
{
//mail stuff
$randNum = rand(268435456, 4294967295);
$couponCode = &quot;1FAA - 5\$OFF - BULBS - &quot; . dechex($randNum);
$mailContent = &quot;Hello $custName, &lt;br /&gt;&lt;br /&gt; The coupon you requested has been generated. &lt;br /&gt;&quot;.
&quot;Please use the follow code next time you check out! Thank you for shoping with us! &lt;br /&gt;&lt;br /&gt;&quot;.
&quot;Your coupon code is: &lt;br /&gt;&quot;. &quot;&lt;b&gt;&quot;.strtoupper($couponCode).&quot;&lt;/b&gt;&quot;;
$headers  = &#039;MIME-Version: 1.0&#039; . &quot;\r\n&quot;;
$headers .= &#039;Content-type: text/html; charset=iso-8859-1&#039; . &quot;\r\n&quot;;
$headers .= &#039;From: webmaster@billsbulb.com&#039; . &quot;\r\n&quot; .
&#039;Reply-To: webmaster@billsbulb.com&#039; . &quot;\r\n&quot; .
&#039;X-Mailer: PHP/&#039; . phpversion();

//lock file
flock($fileHandle, LOCK);

//if email not provided, no mail!
if($emailAddEmpty === true)
{
$writeString = $writeString . ($custName . &quot;;&quot; . $purchDate . &quot;;&quot; . $purchNum
. &quot;;&quot; . $selectionRate . &quot;;&quot; .  $priceRate . &quot;;&quot; .
$deliveryRate . &quot;\n&quot;);
$resultString = &quot;&lt;div class=&#039;content&#039;&gt;Thank you! $custName! &lt;br /&gt; Your survey has been submitted. &lt;/div&gt;&quot;;
}

//if mail provided, check mail status and tells the user!
else
{
$mailStatus = mail ($emailAdd, &#039;Coupon Code&#039;, $mailContent, $headers);
$writeString = $writeString . ($custName . &quot;;&quot; . $purchDate . &quot;;&quot; . $purchNum
. &quot;;&quot; . $selectionRate . &quot;;&quot; .  $priceRate . &quot;;&quot; .
$deliveryRate . &quot;;&quot; . $emailAdd . &quot;\n&quot;);
$resultString = &quot;&lt;div class=&#039;content&#039;&gt;Thank you! $custName! &lt;br /&gt; Your survey has been submitted.
&lt;br /&gt;You should receive your coupon shortly in &lt;br /&gt;$emailAdd. &lt;/div&gt;&quot;;

//check mail status
$emailStatusCheck;

if ($mailStatus === true)
{
$emailStatusCheck = &quot;Yes!&quot;;
}

else
{
$emailStatusCheck = &quot;Nope, Internal Error!&quot;;
}

print (&quot;&lt;div class=&#039;content&#039;&gt;Mail Sent? $emailStatusCheck&lt;/div&gt;&quot;);
}

fwrite($fileHandle, $writeString);

//file unlock and close
flock($fileHandle, UNLOCK);
fclose($fileHandle);

print ($resultString);

}

else
{
print (&quot;Error - No Write Access to $fileName&quot;);
}
}
}

else
{
print(&quot;Please hit \&quot;Go Back\&quot; and Re-Enter a valid email address. &lt;br /&gt;Thank you! &lt;/div&gt;&quot;);
}
}

else
{
print (&quot;&lt;div class=&#039;warnings&#039;&gt; $warnMsg&lt;br /&gt; Please hit \&quot;Go Back\&quot; and Re-Enter your valid Information.&lt;/div&gt;&quot;);
}

?&gt;
&lt;div class=&quot;buttons&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;Go Back&quot; onclick=&quot;history.go(-1)&quot;/&gt;
&lt;input type=&quot;button&quot; value=&quot;Exit&quot; onClick=&quot;window.close()&quot; /&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>showResults.php</p>
<pre class="brush: php">
&lt;?php print(&#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#039;); ?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;title&gt;Authorized User | Administration Operations&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body
{   background-color:#3D3D3D;
font-family: Arial, Tahoma, Geneva, Verdana, sans-serif }

h2
{
text-align: center;
background-color: #FFE4E1;
margin-left: auto;
margin-right: auto;
margin-bottom: 2%;
width: 80%;
color: #4682B4;
border-style: solid;
border-color: black;
border-width: 4px;
padding-top: 1%;
padding-bottom: 1%;
padding-left: 5%;
padding-right: 5% }

.loginwindow
{
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
box-shadow: 2px 2px 15px #000;
-webkit-box-shadow: 2px 2px 15px black;
-moz-border-shadow: 2px 2px 15px black;
padding: 5px 5px 5px 15px;
margin-top: 15%;
margin-bottom: auto;
margin-left: auto;
margin-right: auto;
background-color: white;
width: 20em;
overflow: hidden;
text-align: center;
}

.content
{
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
box-shadow: 2px 2px 15px #000;
-webkit-box-shadow: 2px 2px 15px black;
-moz-border-shadow: 2px 2px 15px black;
padding: 5px 5px 5px 15px;
margin-bottom: auto;
margin-left: auto;
margin-right: auto;
background-color: white;
overflow: hidden;
text-align: center;
width: 90%;
}

.content table
{
border-style: solid;
border-spacing: 25px;
}

.warnings
{
text-align: center;
color: red;
}

.editBttns
{
text-align: center;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
//if nothing posted, show login
if (count($_POST) == 0)
{
echo (&#039;&lt;form class=&quot;loginwindow&quot; action=&quot;&#039; . $_SERVER[&#039;PHP_SELF&#039;] . &#039;&quot; method=&quot;post&quot;&gt;&#039;);
echo (&#039;    &lt;img src=&quot;http://z.about.com/d/homerenovations/1/0/a/E/-/-/LightBulbDrawing.png&quot; width=&quot;100px&quot; height=&quot;100px&quot; /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Hello! This page is for authorized user to operate system records.&lt;br /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Autohrized user: Please login.&lt;br /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Login: &lt;br /&gt;&#039;);
echo (&#039;    &lt;input type=&quot;text&quot; name=&quot;loginName&quot; value=&quot;Bill&quot; readonly=&quot;readonly&quot; /&gt; &lt;br /&gt;&#039;);
echo (&#039;    Password: &lt;br /&gt;&#039;);
echo (&#039;    &lt;input type=&quot;password&quot; name=&quot;loginPwd&quot; maxlength=&quot;10&quot; /&gt;&lt;br &gt;&#039;);
echo (&#039;    &lt;input type=&quot;submit&quot; name=&quot;submitBttn&quot; value=&quot;Login!&quot;/&gt;&#039;);
echo (&#039;    &lt;input type=&quot;reset&quot; name=&quot;clear&quot; value=&quot;Retry&quot; /&gt;&#039;);
echo (&#039;&lt;/form&gt;&#039;);

}

//if login information provided, check!
if(isset($_POST[&#039;loginPwd&#039;]))
{
$loginPwd = $_POST[&quot;loginPwd&quot;];

//if login info okay
if ($loginPwd === &quot;bulb&quot;)
{
//populates file handling variables
$fileName = &quot;results.txt&quot;;
$fileHandle;
define(&quot;LOCK&quot;, 2);
define(&quot;UNLOCK&quot;, 3);
$writeString;

//Pre-read into Write String
$fileHandle = fopen($fileName, &quot;r&quot;) or die (&quot;&lt;div class=&#039;warnings&#039;&gt;Error - Cannot Open $fileName for reading.
&lt;br /&gt;Possibily nobody has left anything yet.&lt;br /&gt;
&lt;input type=&#039;button&#039; value=&#039;Go Back&#039; onclick=&#039;history.go(-1)&#039; /&gt;&lt;/div&gt;&quot;);
//file lock
flock($fileHandle, LOCK);
$writeString = fread($fileHandle, filesize($fileName));
//file unlock and close
flock($fileHandle, UNLOCK);
fclose($fileHandle);

$tblContent = preg_split (&quot;/\n/&quot;, $writeString);

//content, table, etc.
echo (&#039;&lt;h2&gt;Hello Authorized User, The detailed record is listed below!&lt;/h2&gt;&#039;);
echo (&#039;&lt;div class=&quot;content&quot;&gt;&#039;);

print (&#039;&lt;table border=&quot;1px&quot; summery=&quot;Here is the reference to the survey.&quot;&gt;&#039;);
print (&#039;&lt;tr&gt;&lt;th&gt;Customer Name&lt;/th&gt;&lt;th&gt;Purchase Date&lt;/th&gt;&#039;);
print (&#039;&lt;th&gt;# Of Purchase&lt;/th&gt;&lt;th&gt;Selection&lt;/th&gt;&#039;);
print (&#039;&lt;th&gt;Prices&lt;/th&gt;&lt;th&gt;Delivery&lt;/th&gt;&#039;);
print (&#039;&lt;th&gt;E-Mail Address&lt;/th&gt;&lt;/tr&gt;&#039;);

for ($i=0; $i &lt; count($tblContent); $i++)
{
$subContent = preg_split (&quot;/[;]/&quot;, $tblContent[$i]);
print (&quot;&lt;tr&gt;\n&quot;);
for ($p=0; $p &lt; count($subContent); $p++)
{
print(&quot;&lt;td&gt;\n&quot;);
print($subContent[$p]. &quot;\n&quot;);
print(&quot;&lt;/td&gt;\n&quot;);
}
print (&quot;&lt;/tr&gt;\n&quot;);
}

print(&#039;&lt;/table&gt;&#039;);

echo (&#039;&lt;/div&gt;&#039;);

//delete button
echo (&#039;&lt;form class=&quot;editBttns&quot; action=&quot;&#039; . $_SERVER[&#039;PHP_SELF&#039;] . &#039;&quot; method=&quot;post&quot;&gt;&#039;);
echo (&#039;&lt;input type=&quot;submit&quot; name=&quot;clearData&quot; value=&quot;Click To Erase List&quot; /&gt;&#039;);
echo (&#039;&lt;/form&gt;&#039;);

}

//if login info not correct, show error!
else
{
echo (&#039;&lt;form class=&quot;loginwindow&quot; id=&quot;loginWindow&quot; action=&quot;&#039; . $_SERVER[&#039;PHP_SELF&#039;] . &#039;&quot; method=&quot;post&quot;&gt;&#039;);
echo (&#039;    &lt;img src=&quot;http://z.about.com/d/homerenovations/1/0/a/E/-/-/LightBulbDrawing.png&quot; width=&quot;100px&quot; height=&quot;100px&quot; /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Hello! This page is for authorized user to operate system records.&lt;br /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Autohrized user: Please login.&lt;br /&gt;&lt;br /&gt;&#039;);
echo (&#039;    Login: &lt;br /&gt;&#039;);
echo (&#039;    &lt;input type=&quot;text&quot; name=&quot;loginName&quot; value=&quot;Bill&quot; readonly=&quot;readonly&quot; /&gt; &lt;br /&gt;&#039;);
echo (&#039;    Password: &lt;br /&gt;&#039;);
echo (&#039;    &lt;input type=&quot;password&quot; name=&quot;loginPwd&quot; maxlength=&quot;10&quot; /&gt;&lt;br &gt;&#039;);
echo (&#039;    &lt;p class=&quot;warnings&quot;&gt;Invalid Login Information! Please Try Again!&lt;/p&gt;&#039;);
echo (&#039;    &lt;input type=&quot;submit&quot; name=&quot;submitBttn&quot; value=&quot;Login!&quot;/&gt;&#039;);
echo (&#039;    &lt;input type=&quot;reset&quot; name=&quot;clear&quot; value=&quot;Retry&quot; /&gt;&#039;);
echo (&#039;&lt;/form&gt;&#039;);
}

}

//Call to clear Data function
if (isset($_POST[&#039;clearData&#039;]))
{
//call_uers_func(&#039;eraseData&#039;);
eraseData();
}

//function to delete data
function eraseData()
{
$fileName = &quot;results.txt&quot;;

if (file_exists($fileName))
{
//drop file
unlink ($fileName) or die (&quot;Error - No Permission!&quot;);

//tells user okay!
echo (&quot;&lt;div class=&#039;warnings&#039;&gt;File Has Been Removed!&lt;br /&gt;
&lt;input type=&#039;button&#039; value=&#039;Go Back&#039; onclick=&#039;history.go(-1)&#039; /&gt;&lt;/div&gt;&quot;);

}

else
{
//if file not exist, warn user
echo (&#039;&lt;script type=&quot;text/javascript&quot;&gt;&#039;);
echo (&#039;window.alert(&quot;The File Does Not Exist!&quot;)&#039;);
echo (&#039;&lt;/script&gt;&#039;);
}
}

?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=117</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>其實我也不知道該怎麼說</title>
		<link>http://shibingsprojects.net/blog/?p=115</link>
		<comments>http://shibingsprojects.net/blog/?p=115#comments</comments>
		<pubDate>Sun, 30 Aug 2009 22:36:15 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.shibingsprojects.com/?p=115</guid>
		<description><![CDATA[有個blog已經很久了，從來不維護，也從不更新～～ 於是，這裡就看著辦吧～～～該怎麼樣就怎麼樣]]></description>
			<content:encoded><![CDATA[<p>有個blog已經很久了，從來不維護，也從不更新～～</p>
<p>於是，這裡就看著辦吧～～～該怎麼樣就怎麼樣</p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPS 311 &#8211; April 1st  Lecture</title>
		<link>http://shibingsprojects.net/blog/?p=113</link>
		<comments>http://shibingsprojects.net/blog/?p=113#comments</comments>
		<pubDate>Thu, 02 Apr 2009 02:52:01 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.shibingsprojects.com/?p=113</guid>
		<description><![CDATA[Lists • Unsorted list – A list in which elements are placed in no particular order;  the only relationship between data elements is the list  predecessor and successor relationships  • Sorted list Sorted list – A list that is sorted by some property of its elements; there  is an ordered relationship among the elements in the list,  reflected by their relative positions • Indexed list  – A list in which each element has an index value associated  with it     Sample of a Indexed List       Double Linked Lists         1. Double Linked List extends LLObject Node     Page. 467           2.Add Operation [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:16pt"><strong>Lists<br />
</strong></span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">• <strong>Unsorted list</strong><br />
		</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">– A list in which elements are placed in no particular order; <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">the only relationship between data elements is the list <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">predecessor and successor relationships <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">• <strong>Sorted list Sorted list</strong><br />
		</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">– A list that is sorted by some property of its elements; there <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">is an ordered relationship among the elements in the list, <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">reflected by their relative positions<br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">• <strong>Indexed list </strong><br />
		</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">– A list in which each element has an index value associated <br />
</span></p>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt">with it<br />
</span></p>
<p style="margin-left: 14pt"> <br />
 </p>
<p><span id="more-113"></span>
<p style="margin-left: 14pt"><span style="font-family:Verdana; font-size:10pt"><br />
			<strong>Sample of a Indexed List</strong><br />
		</span></p>
<p>
 </p>
<p><img src="http://shibingsprojects.net/blog/wp-content/uploads/2009/04/040209-0252-cps311apri1.gif" alt=""/><span style="font-family:Verdana; font-size:10pt"><br />
		</span></p>
<p> <br />
 </p>
<p style="margin-left: 1pt"><span style="font-family:Verdana; font-size:16pt"><strong>Double Linked Lists<br />
</strong></span></p>
<p style="margin-left: 1pt"> <br />
 </p>
<p style="margin-left: 1pt"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2009/04/040209-0252-cps311apri2.png" alt=""/><span style="font-family:宋体; font-size:12pt"><br />
		</span></p>
<p> <br />
 </p>
<p style="margin-left: 2pt"><span style="font-family:Verdana"><span style="font-size:14pt"><strong>1. Double Linked List extends LLObject Node</strong></span><br />
		</span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"><span style="font-family:Verdana"><br />
			<span style="color:#3366ff">Page. 467</span><br />
		</span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2009/04/040209-0252-cps311apri3.png" alt=""/><span style="font-family:宋体"><br />
		</span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt">
 </p>
<p style="margin-left: 2pt"><span style="font-family:Verdana"><span style="font-size:14pt"><strong>2.Add Operation</strong></span><span style="font-size:12pt"><br />
			</span></span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"><span style="font-family:Verdana">* Careful w/ orders<span style="font-size:12pt"><br />
			</span></span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2009/04/040209-0252-cps311apri4.png" alt=""/><span style="font-family:宋体"><br />
		</span></p>
<p style="margin-left: 2pt"><span style="font-family:Verdana"><span style="font-size:10pt"><br />
			</span><span style="color:#3366ff">page. 469-470</span><span style="font-size:10pt"><br />
			</span></span></p>
<p style="margin-left: 2pt"> <br />
 </p>
<p style="margin-left: 2pt"><span style="font-family:Verdana"><span style="font-size:14pt"><strong>3.the Remove Operation</strong></span><span style="font-size:10pt"><br />
			</span></span></p>
<p>
 </p>
<p><img src="http://shibingsprojects.net/blog/wp-content/uploads/2009/04/040209-0252-cps311apri5.png" alt=""/>
	</p>
<p><span style="font-family:Verdana"><span style="color:#3366ff">page. 470</span><br />
		</span></p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=113</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Assignment 7 NamesGUI</title>
		<link>http://shibingsprojects.net/blog/?p=87</link>
		<comments>http://shibingsprojects.net/blog/?p=87#comments</comments>
		<pubDate>Fri, 21 Nov 2008 00:04:12 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Java Projects]]></category>

		<guid isPermaLink="false">http://personalprojects.us/blog/?p=87</guid>
		<description><![CDATA[PA7 is just basically GUI version of PA6. It's pretty easy to convert. The source code are available. filename: Main.java package PA7NamesGuiMain; /** * * @author Shibing Huang * Heidelberg College * Class: CPS 202 PA7 * Update: Nov. 16, 2008 * * Usage: Main Class */ public class Main { /** * @param args [...]]]></description>
			<content:encoded><![CDATA[<p>PA7 is just basically GUI version of PA6.<br />
It's pretty easy to convert. The source code are available.</p>
<p>filename: <strong>Main.java</strong></p>
<pre class="brush: java">
package PA7NamesGuiMain;

/**
 *
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA7
* Update: Nov. 16, 2008
*
* Usage:  Main Class
 */
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        BabyNamesViewGui baby = new BabyNamesViewGui();
        baby.mySetVisible(true);
    }

}
</pre>
<p><span id="more-87"></span></p>
<p>filename: <strong>BabyNamesModel.java</strong></p>
<pre class="brush: java">
package PA7NamesGuiMain;

import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA7
* Update: Nov. 16, 2008
*
* Usage:  Data Modeller
*/

public class BabyNamesModel
{
    ////////////// Fields /////////////////////////
    private String[] tempString;
    private int[] tempInt;
    private Scanner inputStream;
    private PrintWriter outputStream;
    private ArrayList&lt;boys&gt; boys;
    private ArrayList&lt;girls&gt; girls;
    private String fileLocationField;
    private String errorMsg;
    public final String CMD;

    /////////////// Constructors /////////////////
    public BabyNamesModel()
    {
        //No Arg
        tempString = new String[1000];
        tempInt = new int[1000];
        inputStream = null;
        outputStream = null;
        fileLocationField = &quot;&quot;;
        boys = new ArrayList&lt;boys&gt; ();
        girls = new ArrayList&lt;girls&gt; ();
        errorMsg = null;
        CMD = &quot;Command: &quot;;
    }

    /////////////// Methods ///////////////////////

    //--------------------------
    //Command Entry
    //--------------------------
    public String cmdEntry()
    {
        String input = null;

        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        try
        {
            input = br.readLine();
        }
        catch (IOException ioe)
        {
            errorMsg = &quot;I/O Error, please try again!&quot; + &quot;\r\n&quot;+ ioe;
        }

        return input;
    }

    //----------------------------
    // File Reader
    //----------------------------
    public void readAFile(String input)
    {
        fileLocationField = input;

        try
        {
            inputStream = new Scanner(new FileInputStream(&quot;TextFiles//&quot; + fileLocationField));
            outputStream = new PrintWriter(new FileOutputStream(&quot;TextFiles//test.txt&quot;));
        }

        catch(FileNotFoundException e)
        {
            errorMsg = &quot;Internal Error, detailed error message is listed below.&quot; + &quot;\r\n&quot; + e;
        }

        String line = &quot;&quot;;
        int nameCounter = 0;
        int i = 0;
        int intt = 0;

        while (inputStream.hasNextLine())
        {
            line = inputStream.next();
            nameCounter = inputStream.nextInt();
            tempString[i] = line;
            i++;
            tempInt[intt] = nameCounter;
            intt++;
            outputStream.println(line);
        }

        inputStream.close();
        outputStream.close();

    }

    //-----------------------------
    //Create array for Boys
    //-----------------------------
    public void creatBoysArray(String input)
    {
        readAFile(input);

        for (int i = 0; i &lt; tempString.length; i++ )
        {
            Boys newBoy = new Boys(tempString[i], tempInt[i]);
            boys.add(i , newBoy);

        }
    }

    //----------------------------
    //Create Array for Girls
    //----------------------------
    public void creatGirlsArray(String input)
    {
        readAFile(input);

        for (int ii = 0; ii &lt; tempString.length; ii++ )
        {
            Girls newGirl = new Girls(tempString[ii], tempInt[ii]);
            girls.add(ii, newGirl);
        }
    }

    //----------------------------------
    // Returns Boys Array
    //----------------------------------
    public ArrayList returnBoys()
    {
        return boys;
    }

    //----------------------------------
    // Returns Girls Array
    //----------------------------------
    public ArrayList returnGirls()
    {
        return girls;
    }

    //----------------------------------
    // Search Array (Boys)
    //----------------------------------
    public int searchBoysInArray(String input)
    {
        String searchForABoy = input;
        int currentIndex = 0;
        Boolean foundBoy = false;

         for (int i = 0; i &lt; boys.size(); i++)
        {
            if (searchForABoy.equalsIgnoreCase(boys.get(i).getBoysName()))
            {
                foundBoy = true;
                currentIndex = i;
            }
        }

        if (foundBoy == false)
        {
            currentIndex = -1;
        }

        return currentIndex;

    }

    //--------------------------------------------
    // Search Array (Girls)
    //--------------------------------------------
    public int searchGirlsInArray(String input)
    {
        String searchForAGirl = input;
        Boolean foundGirl = false;
        int currentIndex = 0;

        for (int i = 0; i &lt; girls.size(); i++)
        {
            if (searchForAGirl.equalsIgnoreCase(girls.get(i).getGirlsName()))
            {
                foundGirl = true;
                currentIndex = i;
            }
        }

        if (foundGirl == false)
        {
            currentIndex = -1;
        }

        return currentIndex;
    }

}
</pre>
<p>filename:<strong> BabyNamesViewGUI</strong></p>
<pre class="brush: java">
package PA7NamesGuiMain;

import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA7
* Update: Nov. 16 , 2008
*
* Usage:  View Class
*/

public class BabyNamesViewGui extends JFrame implements ActionListener
{
    /////////////////// Fields /////////////////////////
    private BabyNamesModel newType = new BabyNamesModel();

    private ArrayList&lt;boys&gt; boys;
    private ArrayList&lt;girls&gt; girls;
    private JButton submitButton;
    private JTextField myTextField;
    private JTextArea myTextArea;
    private JFrame myFrame;
    private JPanel northPanel;
    private JPanel southPanel;
    private JPanel centerPanel;
    private static final int MYHEIGHT = 380;
    private static final int MYWIDTH = 450;
    private boolean frameVisible;

    //////////////// Constructors //////////////////////
    public BabyNamesViewGui()
    {
        //Declare the valuables
        boys =new ArrayList&lt;boys&gt;();
        girls = new ArrayList&lt;girls&gt;();
        submitButton = new JButton(&quot;Make a Search!&quot;);
        submitButton.addActionListener(this);
        myTextField = new JTextField(20);
        myTextField.addActionListener(this);
        myTextArea = new JTextArea(10, 25);
        frameVisible = true;

        //Read the TXT file
        fileLocations();

        //Call to JFrame
        jFrameConstruction();

    }

    ///////////////// Methods //////////////////////////

    //-----------------------------------
    // JFrame configuration
    //-----------------------------------
    public void jFrameConstruction()
    {
        //Form the Frame
        myFrame = new JFrame(&quot;Name Rank Searcher&quot;);
        myFrame.setSize(MYWIDTH,MYHEIGHT);
        myFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        myFrame.setLayout (new BorderLayout());
        //Get The Screen size
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();

        //center the dialog box
        int x = (screenSize.width - myFrame.getWidth()) / 2;
        int y = (screenSize.height - myFrame.getHeight()) / 2;
        myFrame.setLocation(x, y);

        //create panels
        northPanel = new JPanel();
        myFrame.add (northPanel, BorderLayout.NORTH);
        southPanel = new JPanel();
        myFrame.add (southPanel, BorderLayout.SOUTH);
        centerPanel = new JPanel();
        myFrame.add (centerPanel, BorderLayout.CENTER);
        centerPanel.setLayout(new BorderLayout());

        //button panel
        JPanel submitButtonPanel = new JPanel();
        southPanel.add (submitButtonPanel);
        submitButtonPanel.add(submitButton);

        //Info panel
        northPanel.add(new JLabel (&quot;Please enter the name, then hit Search button.&quot;));

        //Center search input
        JPanel stuffPanel = new JPanel();
        stuffPanel.setLayout(new BorderLayout());
        centerPanel.add(stuffPanel, BorderLayout.NORTH);
        stuffPanel.add(new JLabel (&quot;Name: &quot;), BorderLayout.NORTH);
        stuffPanel.add(myTextField, BorderLayout.CENTER);

        //Center output result
        JPanel resultPanel = new JPanel();
        resultPanel.setLayout(new BorderLayout());
        centerPanel.add(resultPanel, BorderLayout.SOUTH);
        resultPanel.add(new JLabel(&quot;Search Results: &quot;), BorderLayout.NORTH);
        resultPanel.add(myTextArea, BorderLayout.CENTER);

        myFrame.setVisible(frameVisible);
    }

    public void mySetVisible(boolean frameVisible)
    {
        this.frameVisible = frameVisible;
    }

    //--------------------------------
    //Route the File Location
    //--------------------------------
    public void fileLocations()
    {
        newType.creatBoysArray(&quot;boynames.txt&quot;);
        boys = newType.returnBoys();
        newType.creatGirlsArray(&quot;girlnames.txt&quot;);
        girls = newType.returnGirls();
    }

    //---------------------------------
    // Action Listener
    //---------------------------------
    public void actionPerformed(ActionEvent event)
    {
        //String actionCommand = event.getActionCommand();

        String name = myTextField.getText();
        String boysResults = &quot;&quot;;
        String girlsResults = &quot;&quot;;

        int returnedIndexBoys = 0;
        returnedIndexBoys = newType.searchBoysInArray(name);
        int boysRanking = 0;
        boysRanking = returnedIndexBoys + 1;

        if (returnedIndexBoys == -1)
        {
            boysResults = name + &quot; is not ranked among the top 1000 boy names.&quot;;
        }
        else
        {
            boysResults = name + &quot; is ranked &quot; + boysRanking  + &quot; in popularity among boys with &quot;
                + boys.get(returnedIndexBoys).getBoysNameCount() + &quot; namings.&quot;;
        }

        int returnedIndexGirls = 0;
        returnedIndexGirls = newType.searchGirlsInArray(name);
        int girlsRanking = 0;
        girlsRanking = returnedIndexGirls + 1;

        if (returnedIndexGirls == -1)
        {
            girlsResults = name + &quot; is not ranked among the top 1000 girl names.&quot;;
        }
        else
        {
            girlsResults = name + &quot; is ranked &quot; + girlsRanking  + &quot; in popularity among girls with &quot;
                + girls.get(returnedIndexGirls).getGirlsNameCount() + &quot; namings.&quot;;
        }

        myTextArea.setText(boysResults + &quot;\r\n&quot; + girlsResults);
    }

}
</pre>
<p>filename: <strong>Boys.java</strong></p>
<pre class="brush: java">
package PA7NamesGuiMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA7
* Update: Nov. 16, 2008
*
* Usage:  Boys Type
*/

public class Boys
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Boys()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Boys(String boysName, int nameCounter)
    {
        name = boysName;
        nameCount = nameCounter;
    }
    /////////////// Methods /////////////////////////
    public String getBoysName()
    {
        return name;
    }

    public int getBoysNameCount()
    {
        return nameCount;
    }
}
</pre>
<p>filename: Girls.java</p>
<pre class="brush: java">
package PA7NamesGuiMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA7
* Update: Nov. 16, 2008
*
* Usage:  Girls Type
*/

public class Girls
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Girls()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Girls(String girlsName, int nameCounter)
    {
        name = girlsName;
        nameCount = nameCounter;
    }

    /////////////// Methods /////////////////////////
    public String getGirlsName()
    {
        return name;
    }

    public int getGirlsNameCount()
    {
        return nameCount;
    }

}
</pre>
<p>The project folder is also provided just in case anyone need it.<br />
link: <a href="http://www.personalprojects.us/projects/myjava">http://www.personalprojects.us/projects/myjava</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=87</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected: 被點名了~</title>
		<link>http://shibingsprojects.net/blog/?p=85</link>
		<comments>http://shibingsprojects.net/blog/?p=85#comments</comments>
		<pubDate>Sun, 16 Nov 2008 00:06:08 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Just My Life]]></category>

		<guid isPermaLink="false">http://personalprojects.us/blog/?p=85</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://shibingsprojects.net/blog/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-85">Password:<br />
<input name="post_password" id="pwbox-85" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Assignment #6 ArrayList version of PA6Names</title>
		<link>http://shibingsprojects.net/blog/?p=83</link>
		<comments>http://shibingsprojects.net/blog/?p=83#comments</comments>
		<pubDate>Fri, 07 Nov 2008 00:48:15 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Java Projects]]></category>

		<guid isPermaLink="false">http://personalprojects.us/blog/?p=83</guid>
		<description><![CDATA[Well, because of one of the dumb decision I made, it took me around 3 hours to debug this program. So I cleared it out and made it working alright. So just take a look at it. I'll catch with you guys later. Main.java package PA6NamesMain; /** * * @author Shibing Huang * Heidelberg College [...]]]></description>
			<content:encoded><![CDATA[<p>Well, because of one of the dumb decision I made, it took me around 3 hours to debug this program. So I cleared it out and made it working alright.<br />
So just take a look at it. I'll catch with you guys later.</p>
<p>Main.java</p>
<pre class="brush: java">
package PA6NamesMain;

/**
 *
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Nov. 06, 2008
*
* Usage:  Main Class
 */
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        BabyNamesView baby = new BabyNamesView();

        baby.usrComm();
        System.exit (0);
    }

}
</pre>
<p><span id="more-83"></span></p>
<p>BabyNamesView.java</p>
<pre class="brush: java">
package PA6NamesMain;

import java.io.*;
import java.util.ArrayList;
/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Nov. 06 , 2008
*
* Usage:  Control Class
*/

public class BabyNamesView
{
    /////////////////// Fields /////////////////////////
    private BabyNamesModel newType = new BabyNamesModel();
    private String boysName;
    private String girlsName;
    private ArrayList&lt;boys&gt; boys;
    private ArrayList&lt;girls&gt; girls;

    //////////////// Constructors //////////////////////
    public BabyNamesView()
    {
        boysName = &quot;&quot;;
        girlsName = &quot;&quot;;
        boys =new ArrayList&lt;boys&gt;();
        girls = new ArrayList&lt;girls&gt;();
    }

    ///////////////// Methods //////////////////////////

    //--------------------------------
    //Route the File Location
    //--------------------------------
    public void fileLocations()
    {
        System.out.println (&quot;Please enter the related file location of \&quot;boynames.txt\&quot;.&quot;);
        newType.creatBoysArray();
        boys = newType.returnBoys();
        System.out.println (&quot;Please enter the related file location of \&quot;girlnames.txt\&quot;.&quot;);
        newType.creatGirlsArray();
        girls = newType.returnGirls();
    }

    //---------------------------------
    // User Interface
    //---------------------------------
    public void usrComm()
    {
        fileLocations();
        int againOrNot = 0;

        do
        {
            System.out.println (&quot;You may input \&quot;Search\&quot; to continue the program and \&quot;Exit\&quot; to exit the program.&quot;);
            String cmd = newType.cmdEntry();

            if (cmd.equalsIgnoreCase(&quot;Search&quot;))
            {
                System.out.println(&quot;Please enter the name you want to search for.&quot;);
                String name = newType.cmdEntry();
                int returnedIndexBoys = newType.searchBoysInArray(name);
                int boysRanking = returnedIndexBoys + 1;

                if (returnedIndexBoys == -1)
                {
                    System.out.println(name + &quot; is not ranked among the top 1000 boy names.&quot;);
                }
                else
                {
                    System.out.println(name + &quot; is ranked &quot; + boysRanking  + &quot; in popularity among boys with &quot;
                        + boys.get(returnedIndexBoys).getBoysNameCount() + &quot; namings.&quot;);
                }

                int returnedIndexGirls = newType.searchGirlsInArray(name);
                int girlsRanking = returnedIndexGirls + 1;

                if (returnedIndexGirls == -1)
                {
                    System.out.println(name + &quot; is not ranked among the top 1000 girl names.&quot;);
                }
                else
                {
                    System.out.println(name + &quot; is ranked &quot; + girlsRanking  + &quot; in popularity among girls with &quot;
                        + girls.get(returnedIndexGirls).getGirlsNameCount() + &quot; namings.&quot;);
                }
            }

            else if (cmd.equalsIgnoreCase(&quot;Exit&quot;))
            {
                againOrNot = 1;
            }

            else
            {
                System.out.println(&quot;Not the Correct Command, please Try Again.&quot;);
            }
        }
        while(againOrNot == 0);

    }

}
</pre>
<p>BabyNamesModel.java</p>
<pre class="brush: java">
package PA6NamesMain;

import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Nov. 06, 2008
*
* Usage:  Data Modeller
*/

public class BabyNamesModel
{
    ////////////// Fields /////////////////////////
    private String[] tempString;
    private int[] tempInt;
    private Scanner inputStream;
    private PrintWriter outputStream;
    private ArrayList&lt;boys&gt; boys;
    private ArrayList&lt;girls&gt; girls;
    private String fileLocationField;

    /////////////// Constructors /////////////////
    public BabyNamesModel()
    {
        //No Arg
        tempString = new String[1000];
        tempInt = new int[1000];
        inputStream = null;
        outputStream = null;
        fileLocationField = &quot;&quot;;
        boys = new ArrayList&lt;boys&gt; ();
        girls = new ArrayList&lt;girls&gt; ();
    }

    /////////////// Methods ///////////////////////

    //--------------------------
    //Command Entry
    //--------------------------
    public String cmdEntry()
    {
        String input = &quot;&quot;;
        System.out.print(&quot;Command: &quot;);

        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        try
        {
            input = br.readLine();
        }
        catch (IOException ioe)
        {
            System.out.println (&quot;I/O Error, please try again!&quot;);
            System.out.println(ioe);
        }

        return input;
    }

    //----------------------------
    // File Reader
    //----------------------------
    public void readAFile()
    {
        fileLocationField = cmdEntry();

        try
        {
            inputStream = new Scanner(new FileInputStream(&quot;TextFiles//&quot; + fileLocationField));
            outputStream = new PrintWriter(new FileOutputStream(&quot;TextFiles//test.txt&quot;));
        }

        catch(FileNotFoundException e)
        {
            System.out.println(&quot;Internal Error, detailed error message is listed below.&quot;);
            System.out.print(e);
        }

        String line = &quot;&quot;;
        int nameCounter = 0;
        int i = 0;
        int intt = 0;

        while (inputStream.hasNextLine())
        {
            line = inputStream.next();
            nameCounter = inputStream.nextInt();
            tempString[i] = line;
            i++;
            tempInt[intt] = nameCounter;
            intt++;
            outputStream.println(line);
        }

        inputStream.close();
        outputStream.close();

    }

    //-----------------------------
    //Create array for Boys
    //-----------------------------
    public void creatBoysArray()
    {
        readAFile();

        for (int i = 0; i &lt; tempString.length; i++ )
        {
            Boys newBoy = new Boys(tempString[i], tempInt[i]);
            boys.add(newBoy);

        }

        System.out.println(boys.size());

    }

    //----------------------------
    //Create Array for Girls
    //----------------------------
    public void creatGirlsArray()
    {
        readAFile();

        for (int ii = 0; ii &lt; tempString.length; ii++ )
        {
            Girls newGirl = new Girls(tempString[ii], tempInt[ii]);
            girls.add(ii, newGirl);
        }
    }

    //----------------------------------
    // Returns Boys Array
    //----------------------------------
    public ArrayList returnBoys()
    {
        return boys;
    }

    //----------------------------------
    // Returns Girls Array
    //----------------------------------
    public ArrayList returnGirls()
    {
        return girls;
    }

    //----------------------------------
    // Search Array (Boys)
    //----------------------------------
    public int searchBoysInArray(String input)
    {
        String searchForABoy = input;
        int currentIndex = 0;
        Boolean foundBoy = false;

         for (int i = 0; i &lt; girls.size(); i++)
        {
            if (searchForABoy.equalsIgnoreCase(boys.get(i).getBoysName()))
            {
                foundBoy = true;
                currentIndex = i;
            }
        }

        if (foundBoy == false)
        {
            currentIndex = -1;
        }

        return currentIndex;

    }

    //--------------------------------------------
    // Search Array (Girls)
    //--------------------------------------------
    public int searchGirlsInArray(String input)
    {
        String searchForAGirl = input;
        Boolean foundGirl = false;
        int currentIndex = 0;

        for (int i = 0; i &lt; boys.size(); i++)
        {
            if (searchForAGirl.equalsIgnoreCase(girls.get(i).getGirlsName()))
            {
                foundGirl = true;
                currentIndex = i;
            }
        }

        if (foundGirl == false)
        {
            currentIndex = -1;
        }

        return currentIndex;
    }

}
</pre>
<p>Girls.java</p>
<pre class="brush: java">
package PA6NamesMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA3
* Update: Oct. 24, 2008
*
* Usage:  Girls Type
*/

public class Girls
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Girls()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Girls(String girlsName, int nameCounter)
    {
        name = girlsName;
        nameCount = nameCounter;
    }

    /////////////// Methods /////////////////////////
    public String getGirlsName()
    {
        return name;
    }

    public int getGirlsNameCount()
    {
        return nameCount;
    }

}
</pre>
<p>Boys.java</p>
<pre class="brush: java">
package PA6NamesMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA3
* Update: Oct. 24, 2008
*
* Usage:  Boys Type
*/

public class Boys
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Boys()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Boys(String boysName, int nameCounter)
    {
        name = boysName;
        nameCount = nameCounter;
    }
    /////////////// Methods /////////////////////////
    public String getBoysName()
    {
        return name;
    }

    public int getBoysNameCount()
    {
        return nameCount;
    }
}
</pre>
<p>Same deal. See ya in class tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Assignment #5 Names</title>
		<link>http://shibingsprojects.net/blog/?p=77</link>
		<comments>http://shibingsprojects.net/blog/?p=77#comments</comments>
		<pubDate>Mon, 27 Oct 2008 08:13:34 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Java Projects]]></category>

		<guid isPermaLink="false">http://personalprojects.us/blog/?p=77</guid>
		<description><![CDATA[Alright, it’s kind of early for the day, but if you think it’s still night, it is very late. Well, I’m still up and writing Java. Now I seriously have no energy to write anything more. All the notes are in the comments, if you can’t understand it, check the block of comments or feed [...]]]></description>
			<content:encoded><![CDATA[<p>Alright, it’s kind of early for the day, but if you think it’s still night, it is very late.</p>
<p>Well, I’m still up and writing Java. Now I seriously have no energy to write anything more. All the notes are in the comments, if you can’t understand it, check the block of comments or feed back to me. I can help you out if I have free time.</p>
<p> </p>
<p>Alright, first of all. Main class, Main.java</p>
<pre class="brush: java"> package PA5NamesMain;

/**
 *
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Oct. 27, 2008
*
* Usage:  Main Class
 */
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        BabyNamesView baby = new BabyNamesView();
        baby.usrComm();
    }

}
 </pre>
<p> <span id="more-77"></span></p>
<p>Then, the project model, BabyNamesModel.java</p>
<pre class="brush: java"> package PA5NamesMain;

import java.util.Scanner;
import java.io.*;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Oct. 27, 2008
*
* Usage:  Data Modeller
*/

public class BabyNamesModel
{
    ////////////// Fields /////////////////////////
    private String[] tempString;
    private int[] tempInt;
    private Scanner inputStream;
    private PrintWriter outputStream;
    private Boys[] boys;
    private Girls[] girls;
    private String fileLocationField;

    /////////////// Constructors /////////////////
    public BabyNamesModel()
    {
        //No Arg
        tempString = new String[1000];
        tempInt = new int[1000];
        inputStream = null;
        outputStream = null;
        fileLocationField = &quot;&quot;;
        boys = new Boys[1000];
        girls = new Girls[1000];
    }

    /////////////// Methods ///////////////////////

    //--------------------------
    //Command Entry
    //--------------------------
    public String cmdEntry()
    {
        String input = &quot;&quot;;
        System.out.print(&quot;Command: &quot;);

        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        try
        {
            input = br.readLine();
        }
        catch (IOException ioe)
        {
            System.out.println (&quot;I/O Error, please try again!&quot;);
            System.out.println(ioe);
        }

        return input;
    }

    //----------------------------
    // File Reader
    //----------------------------
    public void readAFile()
    {
        fileLocationField = cmdEntry();

        try
        {
            inputStream = new Scanner(new FileInputStream(&quot;TextFiles//&quot; + fileLocationField));
            outputStream = new PrintWriter(new FileOutputStream(&quot;TextFiles//test.txt&quot;));
        }

        catch(FileNotFoundException e)
        {
            System.out.println(&quot;Internal Error, detailed error message is listed below.&quot;);
            System.out.print(e);
        }

        String line = &quot;&quot;;
        int nameCounter = 0;
        int i = 0;
        int intt = 0;

        while (inputStream.hasNextLine())
        {
            line = inputStream.next();
            nameCounter = inputStream.nextInt();
            tempString[i] = line;
            i++;
            tempInt[intt] = nameCounter;
            intt++;
            outputStream.println(line);
        }

        inputStream.close();
        outputStream.close();

    }

    //---------------------------------
    // Output 2 arrays(Debug Helper)
    //---------------------------------
    public void writeArrayOut()
    {
        for (int i=0; i &lt; tempString.length; i++ )
        {
            System.out.println(tempString[i]);
        }

        for (int ii = 0; ii &lt; tempInt.length; ii++)
        {
            System.out.println(tempInt[ii]);
        }
    }

    //-----------------------------------
    // Return the tempArray(Debug Helper)
    //-----------------------------------
    public String[] stringArrayReturn()
    {
        return tempString;
    }

    //-----------------------------------
    // Return the tempArray(Debug Helper)
    //-----------------------------------
    public int[] intArrayReturn()
    {
        return tempInt;
    }

    //-----------------------------
    //Create array for Boys
    //-----------------------------
    public void creatBoysArray()
    {
        readAFile();

        for (int i = 0; i &lt; boys.length; i++ )
        {
            Boys newBoy = new Boys(tempString[i], tempInt[i]);
            boys[i]= newBoy;
        }

    }

    //----------------------------
    //Create Array for Girls
    //----------------------------
    public void creatGirlsArray()
    {
        readAFile();

        for (int ii = 0; ii &lt; girls.length; ii++ )
        {
            Girls newGirl = new Girls(tempString[ii], tempInt[ii]);
            girls[ii]= newGirl;
        }
    }

    //----------------------------------
    // Returns Boys Array (Debug Helper)
    //----------------------------------
    public Boys[] returnBoys()
    {
        return boys;
    }

    //----------------------------------
    // Returns Girls Array (Debug Helper)
    //----------------------------------
    public Girls[] returnGirls()
    {
        return girls;
    }

    //----------------------------------
    // Search Array (Boys)
    //----------------------------------
    public int searchBoysInArray(String input)
    {
        String searchForABoy = input;
        int currentIndex = 0;
        Boolean foundBoy = false;

        for (int i = 0; i &lt; boys.length; i++)
        {
            if (searchForABoy.equalsIgnoreCase(boys[i].getBoysName()))
            {
                foundBoy = true;
                currentIndex = i;
            }
        }

        if (foundBoy == false)
        {
            currentIndex = -1;
        }

        return currentIndex;

    }

    //--------------------------------------------
    // Search Array (Girls)
    //--------------------------------------------
    public int searchGirlsInArray(String input)
    {
        String searchForAGirl = input;
        Boolean foundGirl = false;
        int currentIndex = 0;

        for (int i = 0; i &lt; boys.length; i++)
        {
            if (searchForAGirl.equalsIgnoreCase(girls[i].getGirlsName()))
            {
                foundGirl = true;
                currentIndex = i;
            }
        }

        if (foundGirl == false)
        {
            currentIndex = -1;
        }

        return currentIndex;
    }

}
</pre>
<p>The Controlling Class, BabyNamesView.java</p>
<pre class="brush: java">
package PA5NamesMain;

import java.io.*;
/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA5
* Update: Oct. 27, 2008
*
* Usage:  Control Class
*/

public class BabyNamesView
{
    /////////////////// Fields /////////////////////////
    private BabyNamesModel newType = new BabyNamesModel();
    private String boysName;
    private String girlsName;
    private Boys[] boys;
    private Girls[] girls;

    //////////////// Constructors //////////////////////
    public BabyNamesView()
    {
        boysName = &quot;&quot;;
        girlsName = &quot;&quot;;
        boys =new Boys[1000];
        girls = new Girls[1000];
    }

    ///////////////// Methods //////////////////////////

    //--------------------------------
    //Route the File Location
    //--------------------------------
    public void fileLocations()
    {
        System.out.println (&quot;Please enter the related file location of \&quot;boynames.txt\&quot;.&quot;);
        newType.creatBoysArray();
        boys = newType.returnBoys();
        System.out.println (&quot;Please enter the related file location of \&quot;girlnames.txt\&quot;.&quot;);
        newType.creatGirlsArray();
        girls = newType.returnGirls();
    }

    //---------------------------------
    // User Interface
    //---------------------------------
    public void usrComm()
    {
        fileLocations();
        int againOrNot = 0;

        do
        {
            System.out.println (&quot;You may input \&quot;Search\&quot; to continue the program and \&quot;Exit\&quot; to exit the program.&quot;);
            String cmd = newType.cmdEntry();

            if (cmd.equalsIgnoreCase(&quot;Search&quot;))
            {
                System.out.println(&quot;Please enter the name you want to search for.&quot;);
                String name = newType.cmdEntry();
                int returnedIndexBoys = newType.searchBoysInArray(name);
                int boysRanking = returnedIndexBoys + 1;

                if (returnedIndexBoys == -1)
                {
                    System.out.println(name + &quot; is not ranked among the top 1000 boy names.&quot;);
                }
                else
                {
                    System.out.println(name + &quot; is ranked &quot; + boysRanking  + &quot; in popularity among boys with &quot;
                        + boys[returnedIndexBoys].getBoysNameCount() + &quot; namings.&quot;);
                }

                int returnedIndexGirls = newType.searchGirlsInArray(name);
                int girlsRanking = returnedIndexGirls + 1;

                if (returnedIndexGirls == -1)
                {
                    System.out.println(name + &quot; is not ranked among the top 1000 girl names.&quot;);
                }
                else
                {
                    System.out.println(name + &quot; is ranked &quot; + girlsRanking  + &quot; in popularity among girls with &quot;
                        + girls[returnedIndexGirls].getGirlsNameCount() + &quot; namings.&quot;);
                }
            }

            else if (cmd.equalsIgnoreCase(&quot;Exit&quot;))
            {
                againOrNot = 1;
            }

            else
            {
                System.out.println(&quot;Not the Correct Command, please Try Again.&quot;);
            }
        }
        while(againOrNot == 0);

    }

}
</pre>
<p>The two Object Types, Boys.java and Girls.java</p>
<pre class="brush: java">
package PA5NamesMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA3
* Update: Oct. 24, 2008
*
* Usage:  Boys Type
*/

public class Boys
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Boys()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Boys(String boysName, int nameCounter)
    {
        name = boysName;
        nameCount = nameCounter;
    }
    /////////////// Methods /////////////////////////
    public String getBoysName()
    {
        return name;
    }

    public int getBoysNameCount()
    {
        return nameCount;
    }
}
</pre>
<pre class="brush: java">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PA5NamesMain;

/**
*
* @author  Shibing Huang
* Heidelberg College
* Class: CPS 202 PA3
* Update: Oct. 24, 2008
*
* Usage:  Girls Type
*/

public class Girls
{
    /////////////// Fields //////////////////////////
    private String name;
    private int nameCount;

    ///////////// Constructors //////////////////////
    public Girls()
    {
        //No Arg
        name =  &quot;&quot;;
        nameCount = 0;
    }

    public Girls(String girlsName, int nameCounter)
    {
        name = girlsName;
        nameCount = nameCounter;
    }

    /////////////// Methods /////////////////////////
    public String getGirlsName()
    {
        return name;
    }

    public int getGirlsNameCount()
    {
        return nameCount;
    }

}
</pre>
<p>That's it for today, CPS 202 folks, same deal, no cheating.<br />
Later.<br />
Shibing</p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=77</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Map Test using Windows Live Writer</title>
		<link>http://shibingsprojects.net/blog/?p=76</link>
		<comments>http://shibingsprojects.net/blog/?p=76#comments</comments>
		<pubDate>Thu, 09 Oct 2008 20:32:54 +0000</pubDate>
		<dc:creator>shibing</dc:creator>
				<category><![CDATA[Geeky Profile]]></category>

		<guid isPermaLink="false">http://personalprojects.us/blog/?p=76</guid>
		<description><![CDATA[Just figged out that this Windows Live writer can insert a map for you. Let’s see how it goes. Well, this is the city I live. Well, and this is how it look like. &#160; Let’s see if it can zoom in for a little bit. Well, it didn’t have the actual pointing service, so [...]]]></description>
			<content:encoded><![CDATA[<p>Just figged out that this Windows Live writer can insert a map for you. Let’s see how it goes.</p>
<p>
<div class="wlWriterEditableSmartContent" id="scid:84E294D0-71C9-4bd0-A0FE-95764E0368D9:37b91345-17fb-4c8e-a157-491aa33f56d8" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://maps.live.com/default.aspx?v=2&amp;cp=41.11399~-83.18288&amp;lvl=12&amp;style=r&amp;mkt=en-us&amp;FORM=LLWR" id="map-6521c3be-eb5e-413c-b04c-5bce7dad8634" alt="单击可在 Live.com 上查看此地图" title="单击可在 Live.com 上查看此地图"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2008/10/mapa350e8e09ec2.jpg" width="320" height="240" alt="地图图片"></a></div>
</p>
<p>Well, this is the city I live.</p>
<p> <span id="more-76"></span>
<div class="wlWriterEditableSmartContent" id="scid:84E294D0-71C9-4bd0-A0FE-95764E0368D9:0aa09b1e-edaa-4c83-9d6a-1c996b69ca3c" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://maps.live.com/default.aspx?v=2&amp;cp=41.11522~-83.17667&amp;lvl=12&amp;style=a&amp;mkt=en-us&amp;FORM=LLWR" id="map-19281310-adbd-4448-bbc2-31fcc3bbc801" alt="单击可在 Live.com 上查看此地图" title="单击可在 Live.com 上查看此地图"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2008/10/mapa3c4cd4d67c4.jpg" width="320" height="240" alt="地图图片"></a></div>
</p>
<p>Well, and this is how it look like.</p>
<p>&#160;</p>
<p>Let’s see if it can zoom in for a little bit.</p>
<p>
<div class="wlWriterEditableSmartContent" id="scid:84E294D0-71C9-4bd0-A0FE-95764E0368D9:421cf056-ee15-4547-b221-81da803ac623" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://maps.live.com/default.aspx?v=2&amp;cp=41.11381~-83.18356&amp;lvl=17&amp;style=r&amp;sp=aN.41.11416_-83.18327_This%2520is%2520where%2520I%2520live_78%2520W.%2520Market%2520St.%250d%250aTiffin%252c%2520OH&amp;mkt=en-us&amp;FORM=LLWR" id="map-653b5980-8530-468a-8cb3-35ac3c0d1965" alt="单击可在 Live.com 上查看此地图" title="单击可在 Live.com 上查看此地图"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2008/10/map33119c88ff46.jpg" width="320" height="240" alt="地图图片"></a></div>
</p>
<p>Well, it didn’t have the actual pointing service, so I’ll have to find my own. Shame shame!!</p>
<p>Let’s test the actual image</p>
<div class="wlWriterEditableSmartContent" id="scid:84E294D0-71C9-4bd0-A0FE-95764E0368D9:4d230955-4f0f-4724-9549-8fddfb7ac3e9" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://maps.live.com/default.aspx?v=2&amp;cp=41.11414~-83.18294&amp;lvl=17&amp;style=a&amp;sp=aN.41.11441_-83.18312_This%2520is%2520the%2520place_%253a)%2520as%2520you%2520can%2520see&amp;mkt=en-us&amp;FORM=LLWR" id="map-dbf5f6ac-701a-4fff-8f38-e066577e6aa2" alt="单击可在 Live.com 上查看此地图" title="单击可在 Live.com 上查看此地图"><img src="http://shibingsprojects.net/blog/wp-content/uploads/2008/10/map41bff1c4ed2f.jpg" width="320" height="240" alt="地图图片"></a></div>
<p>Well, that’s the closest I can go. Not very clear, but goo enough.</p>
<p>&#160;</p>
<p>It’s a pretty interesting test. I’m looking forward for the improvements from Microsoft or the Windows Live team.</p>
<p>&#160;</p>
<p>Shibing</p>
]]></content:encoded>
			<wfw:commentRss>http://shibingsprojects.net/blog/?feed=rss2&#038;p=76</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

