โปรแกรมคิดค่าไฟ
This program convert
electricity Unit to price
for thailand rate
first 10 unit 10 THB.
next 10 unit 15 THB.
and next other 20 THB.
♥0 |
Line 53 |
Modified 2013-09-11 03:56:54 |
MIT License
archived:2017-03-10 03:14:23
ActionScript3 source code
/**
* Copyright Heart.Narongrit ( http://wonderfl.net/user/Heart.Narongrit )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/meeq
*/
package {
import flash.events.Event;
import flash.text.TextFieldType;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var input:TextField;
private var output:TextField;
public function FlashTest() {
var label:TextField = new TextField();
addChild( label );
label.text = "Input Unit";
label.y = 80;
input = new TextField();
addChild( input);
input.border = true;
input.text = "0";
input.height = 30;
input.type = TextFieldType.INPUT;
input.y = 95;
input.addEventListener(Event.CHANGE , onChange );
output = new TextField();
addChild(output);
output.y = 150;
}
private function onChange(e:Event):void{
if( isNaN(Number(input.text)) ){
output.text = "not a number";
}else{
output.text = cal(Number(input.text)).toString();
}
}
private function cal( unit:uint ):Number{
var price:int = 0;
//first 10 Unit
if( unit > 10 ){
price = 10*10;
unit -= 10;
}else{
price = unit*10;
return price;
}
//20 Unit
if( unit > 10 ){
price = 15*20;
unit -= 10;
}else{
price = unit*15;
return price;
}
//More
price += unit*20;
return price;
}
}
}