Saturday, May 30, 2009

Javascript Library

I have been looking around on many websites to make my website assigement look cool and there are few that websites which could give a tutorial for plain javascript code but I found out 2 weeks ago that there are a Javascript framework which can help you reduce your time in coding and designing it give a lots of function which most people use on their website at the moment.The following is some of the Javascript framwork which i found on websites.








I'm going to review JQuery for the moment because it is the most popular for web designer because its function really help them accomplish their goal and there are a lots of tutorial on internet to learn from.



JQuery is the javascript framwork which reduce many lines of plain Javascript to just a few lines.By the basic you just link with this code

 The file jquery.js you can download from this link.

Sunday, May 24, 2009

Shanti C# - Card Class - Homework Part 1

The Card class question, as a continuation from Misa's previous post (well, it's more like the prequel, cos this is part 1 :) ).

namespace SimpleCard
{
public class SimpleCard
{
//fields
private int cardValue; //instance variable

public const int ACE = 1;
public const int TWO = 2;
public const int THREE = 3;
public const int FOUR = 4;
public const int FIVE = 5;
public const int SIX = 6;
public const int SEVEN = 7;
public const int EIGHT = 8;
public const int NINE = 9;
public const int TEN = 10;
public const int JACK = 11;
public const int QUEEN = 12;
public const int KING = 13;

public static int CardInASet = 13;

//properties
//cardValue
public int CardValue
{
get { return cardValue; }
set { cardValue = value; }
}

//constructors
public SimpleCard() //null constructor
{
cardValue = 1;
}

public SimpleCard(int _cardValue)
{
cardValue = _cardValue;
}

public SimpleCard(string _cardValueName)
{
switch (_cardValueName)
{
case "ACE":
cardValue = 1;
break;
case "TWO":
cardValue = 2;
break;
case "THREE":
cardValue = 3;
break;
case "FOUR":
cardValue = 4;
break;
case "FIVE":
cardValue = 5;
break;
case "SIX":
cardValue = 6;
break;
case "SEVEN":
cardValue = 7;
break;
case "EIGHT":
cardValue = 8;
break;
case "NINE":
cardValue = 9;
break;
case "TEN":
cardValue = 10;
break;
case "JACK":
cardValue = 11;
break;
case "QUEEN":
cardValue = 12;
break;
case "KING":
cardValue = 13;
break;
}
}

//methods
//instance method
public string getCardName()
{
string cardName = "";
switch (cardValue)
{
case 1:
cardName = "ACE";
break;
case 2:
cardName = "TWO";
break;
case 3:
cardName = "THREE";
break;
case 4:
cardName = "FOUR";
break;
case 5:
cardName = "FIVE";
break;
case 6:
cardName = "SIX";
break;
case 7:
cardName = "SEVEN";
break;
case 8:
cardName = "EIGHT";
break;
case 9:
cardName = "NINE";
break;
case 10:
cardName = "TEN";
break;
case 11:
cardName = "JACK";
break;
case 12:
cardName = "QUEEN";
break;
case 13:
cardName = "KING";
break;
}//end switch

return cardName;
}

public string getInfo()
{
string cardInfo = "";
switch (cardValue)
{
case 1:
cardInfo = "ACE " + cardValue.ToString();
break;
case 2:
cardInfo = "TWO " + cardValue.ToString();
break;
case 3:
cardInfo = "THREE " + cardValue.ToString();
break;
case 4:
cardInfo = "FOUR " + cardValue.ToString();
break;
case 5:
cardInfo = "FIVE " + cardValue.ToString();
break;
case 6:
cardInfo = "SIX " + cardValue.ToString();
break;
case 7:
cardInfo = "SEVEN " + cardValue.ToString();
break;
case 8:
cardInfo = "EIGHT " + cardValue.ToString();
break;
case 9:
cardInfo = "NINE " + cardValue.ToString();
break;
case 10:
cardInfo = "TEN " + cardValue.ToString();
break;
case 11:
cardInfo = "JACK " + cardValue.ToString();
break;
case 12:
cardInfo = "QUEEN " + cardValue.ToString();
break;
case 13:
cardInfo = "KING " + cardValue.ToString();
break;
}//end switch

return cardInfo;
}
}
}


This part is the form implementation:
namespace SimpleCard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (txtCard.Text != "")
{
try //for integer
{
int iCardVal = int.Parse(txtCard.Text.ToString().Trim());

if (iCardVal > 0 && iCardVal <= 13)
{
SimpleCard myCard = new SimpleCard(iCardVal);
MessageBox.Show("Card is " + myCard.getInfo());
}
else
MessageBox.Show("Card does not exist");

}
catch //for string
{
string myCardName = txtCard.Text.ToString().Trim().ToUpper();
SimpleCard myCard = new SimpleCard(myCardName);
MessageBox.Show("Card is " + myCard.getInfo());
}

}
else
{
MessageBox.Show("Enter a value");
txtCard.Focus();
}
}

private void btnDisplayAllCards_Click(object sender, EventArgs e)
{
string myCardNames = "";
for (int i = 1; i <= 13; i++)
{
SimpleCard card = new SimpleCard(i);
myCardNames += " " + card.getCardName();
}
MessageBox.Show(myCardNames);

}
}
}

Saturday, May 23, 2009

Generating Random numbers with Javascript

A quick tutorial on how to generate Random numbers with Javascript. Let's get started:

1) Generating a random number
We make use of the Math 'class' available in Javascript
var randomvar = Math.random();
The result is a decimal number e.g. 0.43209418.


2) Generating a random number with a given range

Say for example, we want a random number to be generated from 1 - 10.
var randomvar = Math.random();
var roundedvar = Math.round(randomvar*10);

Same logic if you want a number from 1 to 1000.
var randomvar = Math.random();
var roundedvar = Math.round(randomvar*1000);


3) What if I want a value from a minimum of 5 to 10, instead of 1 to 10?
This involves a bit of logic and mathematics...
First, we need a random generated value.
Then, we multiply this random generated value with the difference of the range boundaries (e.g. randomvalue * (max - min) ).
Finally, we add the rounded value obtained in step 2 with the minimum value.

Not convinced? See code for randomNum function below and try if for yourself:
function randomNum(min,max)
{
var randomvar = Math.random() * (max - min);
var roundedvar = Math.round(randomvar) + min;
alert( roundedvar);
}

Shanti C# - OOP Exercise: (2) USING ENUMERATION

Hi All,

I searched for how to use enumeration and wrote the below code.
But I'm not sure whether this is a right way or not.
If someone find another ways or good websites, please let me know:D

Misa

Form


private void btnDisplay1_Click(object sender, EventArgs e)
{
SimpleCardEnum card = new SimpleCardEnum(int.Parse(txtCardValue.Text));
lblResult.Text = card.getInfo();
}

private void btnDisplay2_Click(object sender, EventArgs e)
{
SimpleCardEnum card = new SimpleCardEnum(txtCardName.Text.ToUpper());
lblResult.Text = card.getInfo();
}

private void btnDisplayAll_Click(object sender, EventArgs e)
{
SimpleCardEnum card = new SimpleCardEnum();
lblResult.Text = card.getAllCardName();
}


Class


public class SimpleCardEnum
{
//instance variables
private int cardValue;
//static fields
public static int CardInASet = 13;
//enumerations
public enum CardName
{
ACE = 1,
TWO = 2,
THREE = 3,
FOUR = 4,
FIVE = 5,
SIX = 6,
SEVEN = 7,
EIGTH = 8,
NINE = 9,
TEN = 10,
JACK = 11,
QUEEN = 12,
KING = 13
}
//properties
public int CardValue
{
get { return cardValue; }
set { cardValue = value; }
}
//constructors
public SimpleCardEnum()
{
cardValue = 1;
}
public SimpleCardEnum(int cv)
{
cardValue = cv;
}
public SimpleCardEnum(string cn)
{
cardValue = (int)Enum.Parse(typeof(SimpleCardEnum.CardName), cn);
}
//methods
public string getCardName()
{
return Enum.GetName(typeof(SimpleCardEnum.CardName), cardValue);
}
public string getInfo()
{
return getCardName() + " " + cardValue;
}
public string getAllCardName()
{
string names = "";
foreach (string name in Enum.GetNames(typeof(SimpleCardEnum.CardName)))
{
names += name + ", ";
}
return names;
}
}

Thursday, May 21, 2009

Car Array, Finding the cars by max and min seats available



private void FindCarButton_Click(object sender, EventArgs e)
{
//Initialise Cars
Car[] cars = rental.GetAllCars();

//Reset listbox
CarsListBox.Items.Clear();

int iMin = int.Parse(MinTextBox.Text);
int iMax = int.Parse(MaxTextBox.Text);
Car[] carsfound = rental.GetCarsByPassengers(iMax, iMin);

for (int i = 0; i < carsfound.Length; i++)
{
if (carsfound[i] != null)
CarsListBox.Items.Add(carsfound[i].Model);
}
}




//method #2 - GetCarsByMaxPassengers
public Car[] GetCarsByPassengers(int max, int min)
{
Car[] cars = new Car[15];
for (int i = 0; i < carArray.Length ; i++)
{
if ((carArray[i].NoPassengers >= min) && (carArray[i].NoPassengers + 1 <= max))
{
cars[i] = carArray[i];
}
}
return cars;
}

My Bus Buddy

Wednesday, May 20, 2009

Guess who...

:D

Get and display today's date - The Easiest way :)



<html>
<body>

<script type="text/javascript">

var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(month + "/" + day + "/" + year);

</script>

</body>
</html>

Tuesday, May 12, 2009

Operation Costs

For Upfront,


Year 0 Year 1 Year 2 Year 3 Year 4 Year 5
Costs





Development costs





Operational costs
Internet+Hardware+License (UPFRONT) Internet cost per year Internet cost per year Internet cost per year Internet cost per year


For Subscription,

Year 0 Year 1 Year 2 Year 3 Year 4 Year 5
Costs





Development costs





Operational costs
Internet+Hardware+License (Subs) Subs cost + Internet cost Subs cost + Internet cost Subs cost + Internet cost Subs cost + Internet cost

Monday, May 11, 2009

Shanti C# Homework - Time Class

For all those students who didn't attend class today :)


OOP – Creating a Class Exercise 2
Create the following class and its fields, properties, constructors, and methods. The Time class is used to
represent duration of time in hours, minutes, and seconds.
STEP 1: Create the Time class
STEP 2: Define the fields
STEP 3: Define the properties
STEP 4: Define the constructors (null and with arguments)
STEP 5: Time class should have at least the following methods:
A method to show the information in the following format: hh:mm:ss
A method to add seconds into the Time. For example: 01:02:03 plus 12 seconds is equal to
01:02:15.
A method to find the sum of two Time values. For example: 01:02:03 plus 11:22:33 is equal to
12:24:36.
A method to check if two Time values are equal. For example: 01:02:03 and 01:02:03 are equal.
STEP 6: Create the user interface (form) where a user can input the hours, minutes, and
seconds, display the information in presentable format (hh:mm:ss), find the sum of two
Time values, add seconds into the Time, and compare two Time values.

STEP 7: Consider the following scenario and modify the specification of Time class if
necessary:
Can the hours, minutes, and seconds be negative values?
Are there maximum and minimum values for hours, minutes, and seconds?
How many different ways are there to create a Time object? Can the Time object be
created by specifying only the hours and/or the minutes?
What happens when you add some seconds into a Time value and the seconds part
of the Time value exceeds 59 seconds? For example: Should the result of this
operation (01:00:59 plus 2 seconds) be 01:00:61 or 01:01:01?
What happens when you add two Time values and the minutes and seconds part of
the Time value exceeds 59? For example: Should the result of this operation
(01:50:50 plus 02:20:30) be 03:70:80 or 04:11:20?

Sunday, May 10, 2009

Shanti C# - Rectangle and Point Class - Complete

Rectangle Class



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RectangleClass
{
public class Rectangle
{
//fields
private int length = 0;
private int width = 0;
private Point corner = new Point(0,0);

//properties
public int Length
{
get { return length; }
set { length=value; }
}
public int Width
{
get { return width; }
set { width = value; }
}
public Point Corner
{
get { return corner; }
set { corner = value; }
}

//constructors
public Rectangle()
{
}
public Rectangle(int _length, int _width, Point _corner)
{
length = _length;
width = _width;
corner = _corner;
}

//methods
public int getArea()
{
return length * width;
}

public int getPerimeter()
{
return (length + width) * 2;
}

public void increaseLength(int _lengthIncrease)
{
length = length + _lengthIncrease;
}

public void increaseWidth(int _widthIncrease)
{
width = width + _widthIncrease;
}

public string getCenter()
{
corner.setPoint(length / 2, width / 2);
return corner.ToString();
}

public string getTopRight()
{
corner.setPoint(length, 0);
return corner.ToString();
}

public string getBottomLeft()
{
corner.setPoint(0, width);
return corner.ToString();
}

public string getBottomRight()
{
corner.setPoint(length, width);
return corner.ToString();
}

public string getAllPoints()
{
string sAllPoints = "";
sAllPoints = "Center = " + getCenter() + "\n" +
"Top Right = " + getTopRight() + "\n" +
"Bottom Left = " + getBottomLeft() + "\n" +
"Bottom Right = " + getBottomRight();

return sAllPoints;

}
}
}


Point Class (Used to override the ToString() function) - optional



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RectangleClass
{
public class Point
{
//fields
private int x, y;

// Default constructor:
public Point()
{
x = 0;
y = 0;
}

// A constructor with two arguments:
public Point(int x, int y)
{
this.x = x;
this.y = y;
}

// Override the ToString method:
public override string ToString()
{
return (String.Format("({0},{1})", x, y));
}

public void setPoint(int _x, int _y)
{
this.x = _x;
this.y = _y;
}
}

}





Form Coding



Rectangle myRec1 = new Rectangle(0, 0, new Point());

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void btnGetLength_Click(object sender, EventArgs e)
{
CheckFields();
MessageBox.Show("Length is " + myRec1.Length);
}

private void btnGetWidth_Click(object sender, EventArgs e)
{
CheckFields();
MessageBox.Show("Width is " + myRec1.Width);
}

private void btnArea_Click(object sender, EventArgs e)
{
CheckFields();
MessageBox.Show("Area is " + myRec1.getArea());
}

private void btnPerimeter_Click(object sender, EventArgs e)
{
CheckFields();
MessageBox.Show("Area is " + myRec1.getPerimeter());
}

private void CheckFields()
{
myRec1.Length = 0;
myRec1.Width = 0;

if (txtLengthInc.Text != "")
myRec1.increaseLength(int.Parse(txtLengthInc.Text));
if (txtWidthInc.Text != "")
myRec1.increaseWidth(int.Parse(txtWidthInc.Text));

if (txtLength.Text != "")
myRec1.Length = myRec1.Length + int.Parse(txtLength.Text);
if (txtWidth.Text != "")
myRec1.Width = myRec1.Width + int.Parse(txtWidth.Text);

}

private void btnCenter_Click(object sender, EventArgs e)
{
CheckFields();

MessageBox.Show ("Center : " + myRec1.getCenter());
}

private void btnTopRight_Click(object sender, EventArgs e)
{
CheckFields();

MessageBox.Show("Top Right : " + myRec1.getTopRight());
}

private void btnBottomLeft_Click(object sender, EventArgs e)
{
CheckFields();

MessageBox.Show("Bottom Left : " + myRec1.getBottomLeft ());
}

private void btnButtonRight_Click(object sender, EventArgs e)
{
CheckFields();

MessageBox.Show("Bottom Right : " + myRec1.getBottomRight());
}

private void btnAllPoints_Click(object sender, EventArgs e)
{
CheckFields();

MessageBox.Show(myRec1.getAllPoints());
}

Friday, May 8, 2009

Amit's Assignment Part 2 - notes

Hi All,

FYI, I'll write some notes for Amit's assignment Part2.
If you have another notes, please post a comment.

And did someone get the correct information from MS Licence Advisor?
I'm not done yet...:P I am still studying the types of licence.
It is complicated for me, don't you think...?

Misa
------------------------------------------------------------------
[MS Licence Advisor]

- Use "IE".
- Select "United States" for country.
(You need to convert the currency from US$ --> AUS$ later.)


[Assignment clarifications by Amit]

- Check this page.
http://sielearning2.tafensw.edu.au/moodle/mod/forum/discuss.php?d=840#p1601


[ROI]

Amit said 2 things in last class...
-You should calculate only last year's cells for ROI.
-You should use percentage format for ROI.
(This is not assignment sheet...)








ROI (Total)= (Cumulative benefits - Cumulative costs) / Cumulative costs
73.19% = ($827,557 -$477,823) /$477,823
ROI (Annual)=ROI (Total)/ number of years
12.20% = (73.19%) / 6
------------------------------------------------------------------

Thursday, May 7, 2009

Allan's Classwork - Employee class

Just change the following codes to the Employee class file:



//methods
public double CalcWages(double hw)
{
double wages = hw * payRate;
return CalcTaxes(wages);
}

private double CalcTaxes(double Wages)
{
return (Wages * 0.85);
}

Wednesday, May 6, 2009

Amit's Assignment Part 2 - Economic Feasibility

Hey guys

Is it a typo or just me?
In part 2 - Economic Feasibility, it says:
"the benefits per month are expected to be $50,000 ...".
First, $50K a month is a lot of money and seems very unrealistic.
Second, that would mean the company would make $120,000 a year, only by selling flowers with an Internet connection and 11 computers.

I think what he really meant was "benefit per year". That would be more plausible. Whaddya reckon?

Shanti's Web Classwork

Question 1 - Countdown


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<script type="text/javascript">

var num = prompt("Enter number > 0", "0");

while ((num <=0) || (isNaN(num)==true))
{
var num = prompt("Enter number > 0", "0");
}

for (var i=0; i<num; i++)
{
alert("Starting in " + (num-i));
}
alert ("Roll Film!");
</script>
</body>
</html>

Question 2 - Multiplication


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<script type="text/javascript">
document.write("<table><tr><td colspan=10><h1>Multiplication Table</h1></td></tr>");

for(var i = 1; i <= 10; i++)
{
document.write("<tr>");
for (var j = 1 ; j <= 10; j++)
{
document.write("<td>" + i + " * " + j + " = " + (i * j) + "</td>");
}
document.write("</tr>");
}


document.write("</table>");
</script>
</body>
</html>


Question 3 - Online Reservation



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<script type="text/javascript">
function assignSeat()
{

for (var i = 1; i <= 5; i ++)
{
if (document.getElementById(i).title == "a")
{
document.getElementById(i).src= "seat_select.png";
if (confirm("Seat " + i + " is available. Accept? "))
{
document.getElementById(i).src = "seat_unavail.png";
document.getElementById(i).title = "u";
break;
}
else
{

}
document.getElementById(i).src= "seat_avail.png";
}
}

}
</script>

<img src="seat_avail.png" alt = "1" id="1" title = "a" />
<img src="seat_avail.png" alt = "2" id="2" title = "a" />
<img src="seat_avail.png" alt = "3" id="3" title = "a" />
<img src="seat_avail.png" alt = "4" id="4" title = "a" />
<img src="seat_avail.png" alt = "5" id="5" title = "a" />
<br />
<input type="button" value="Reserve Seat" onclick="assignSeat()" />

</body>
</html>

Monday, May 4, 2009

Shanti's Classwork - Rectangle Class

Code without the implementation for the Point object.
Class Definition for Rectangle:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RectangleClass
{
class Rectangle
{
//fields
private int length = 0;
private int width = 0;

//properties
public int Length
{
get { return length; }
set { length=value; }
}
public int Width
{
get { return width; }
set { width = value; }
}

//constructors
public Rectangle()
{
}
public Rectangle(int _length, int _width)
{
length = _length;
width = _width;
}

//methods
public int getArea()
{
return length * width;
}

public int getPerimeter()
{
return (length + width) * 2;
}

public void increaseLength(int _lengthIncrease)
{
length = length + _lengthIncrease;
}

public void increaseWidth(int _widthIncrease)
{
width = width + _widthIncrease;
}
}
}


UI Form



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RectangleClass
{
public partial class Form1 : Form
{
Rectangle myRec1 = new Rectangle(0, 0);

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void btnGetLength_Click(object sender, EventArgs e)
{
CheckFields();
MessageBox.Show("Length is " + myRec1.Length);
}

private void btnGetWidth_Click(object sender, EventArgs e)
{
MessageBox.Show("Width is " + myRec1.Width);
}

private void btnArea_Click(object sender, EventArgs e)
{
MessageBox.Show("Area is " + myRec1.getArea());
}

private void btnPerimeter_Click(object sender, EventArgs e)
{
MessageBox.Show("Area is " + myRec1.getPerimeter());
}

private void CheckFields()
{

if (txtLengthInc.Text != "")
myRec1.increaseLength(int.Parse(txtLengthInc.Text));
if (txtWidthInc.Text != "")
myRec1.increaseWidth(int.Parse(txtWidthInc.Text));

if (txtLength.Text != "")
myRec1.Length = myRec1.Length + int.Parse(txtLength.Text);
if (txtWidth.Text != "")
myRec1.Width = myRec1.Width + int.Parse(txtWidth.Text);

}


}
}

Saturday, May 2, 2009

Amit's Q1.4 What other options...

Apart from Web-based and Stand-alones...

Any idea?

Assignment Cover

Hi guys

Does anyone know where I can find the cover for Amit's assignment? A link would be welcome. Please post it as a comment to this post.

Thanks!

Denis