primitivedata and operation

Page 1

Primitive Data & Operation

-

1

Variable Identifier Naming Convention Constant Primitive Data Arithmetic Expression Type Conversion String Scanner class Library & Package in Java

Watcharin Puangplia : 16/ 16/11/ 11/53


$%&'() (Variable) ďœ‹ ďœ‹ ďœŠ ďœŠ ! "#$% & ďœŠ ďœŠ ' ďœ‹ (ďœ‹ ) '

" ďœ‹*' %! *ďœ‹ " ! &" + (Declared) 5( " &$6 *' %! % & ( ďœ‹ 7 *ďœ‹ " ďœ‹ int total = 200; //Declaring & Initializing int total; //Declaring total = 200; //Initializing Initializing " ! &" +*' %! E *' !ďœ’ ( ďœ‹ 7 ( "' (ďœ‹(ďœ‹ " ! &" + ďœŠ "' int a = 10, b = 20, c = 30,‌, z = 100; int a, b, c,‌,z; a = 10, b = 20, c = 30,‌, z = 100;

2


$%&'() (Variable) *' %! java %$ďœŠ " !ďœ’ 3 " UďœŠ Instance Variable (Non-Static Field) !ďœ’ *' %! 7" ďœ‹ " Class Variable (Static Field) !ďœ’ *' %! 7"" ( ďœ‹ ) !ďœ’ ďœŠ ! &" $ R *' %! Instance & ! ďœ‹ (ďœ‹ Local Variable !ďœ’ *' %! ' ! # 7ďœŠ (W (*ďœŠ E

*6 & ' "* ďœŠ Class Variable & ďœŠ static ďœ‹

3

! &" +*' %! ďœŠ *' %! Instance Variable & ďœŠ ďœŠ static ďœ‹ *' %! ! &" +*' %!


*' %! carModel % & color ( Class Variable : !ďœ’ *' %! MyCar)

$%&*+ďœŠ-. : $%&'() (Variable) public class MyCar { Static String carModel = “Jazzâ€?; String color = “Blackâ€?;

W ( main ďœ‹ *' %! door (Local Variable : *' %! 7ďœŠ) W ()

public static void main(String[] args) { int door = 3; ďœ‹ *' %! Honda " Mycar MyCar Honda = new Mycar(); Honda.color = “Whiteâ€?;

4

}

}

(Instance Variable : *' %! 7" ďœ‹ " class)

System.out.print (“Color of my new car is� + Honda.color); System.out.print(“, it has� + door + “ doors.�);


/-)()0/-1$%&'() (Variable Declaration) < ( ďœ‹ 7 > < *' %! > = < ďœŠ *' %! > ; $%&*+ďœŠ-.

5

Position= ďœ‹ ďœ‹ $ " 7" ďœ‹

Hobby= (7 ' , tďœ? , ďœŠ " *ďœ‹ 7 = 170 R . '"= 65 "".

public class VarDeclare { public static void main(String[] args) { String position, hobby; int height = 170, weight = 65; position = “ ďœ‹ ďœ‹ $ " 7" ďœ‹ â€?; hobby = “(7 ' , tďœ? , ďœŠ " * ďœŽâ€?; System.out.println(“Position= â€? + position); System.out.println(“Hobby= â€? + hobby); System.out.println(“ 7 = â€? + height + “ R .â€?); System.out.println(“ '"= â€? + weight + “ "".â€?); } }


Identifiers w7ďœ‹ 5! %" *' ďœ‹ 5! %" ďœŠ Class, *' %! , Method !ďœ’ *ďœ‹ *' ďœŠ Identifier int total; double salary; Variable Name char grade; String personName; public void setName (String name) Method Name Public String getName ()

6


/-)34ďœ‹ Identifier 36 Java

7

Identifier E ! &" $ (ďœ‹ *' '"x *' $ (Dollar-sign) _ (Underscore) ďœ‹ *ďœ‹ (ďœ‹ *' 'U '"x|ďœŽ ( ďœ‹ Reserved words ďœ‹ ďœ‹ ďœ‹ ďœŠ true true, false false, null ďœ‹ ďœ‹ ďœŠ ďœŠ | Case sensitive (*' ďœŽ #"*' ďœŽ UďœŠ %*"*ďœŠ "' ) *' (ďœ‹ ďœŠ "'(

ThisIsOk, x15, _myName, $java this-is-not-ok, 10person, a b c, my/name


$%&*+-./-)34 Identifier 36 Java indentifier

8

MyVariable _MyVariable $data Sum_Score …

indentifier

My Variable 9Pi @net System


Naming Convention

9

8ďœ‹*$/9.36/-)$%:.4;<* Class Class !ďœ’ *' % " ďœ‹ *ďœ‹ (ďœ‹ '"x *' UďœŠ " ' * (ďœ‹ '"x *' #" ďœŠ Student, Employee, Person, Sample ! &" $ " ďœ‹ ďœ‹ '"x *' UďœŠ !ďœ’ *' *ďœ‹ %*ďœŠ & ďœŠ StudentScore, PersonJob Class "'$ t ďœŽ *ďœ‹ " $' "*ďœ‹ !ďœ’ ( "'


Naming Convention

10

8ďœ‹*$/9.36/-)$%:.4;<* Variable & Instance Variable & Instance (Object) !ďœ’ *' % " ďœ‹ *ďœ‹ (ďœ‹ '"x *' #" ďœŠ student, employee, person ! &" $ " ďœ‹ ďœ‹ '"x *' UďœŠ !ďœ’ *' *ďœ‹ %*ďœŠ & ( " ďœ‹ % ") ďœŠ studentScore, personJob


Naming Convention

8ďœ‹*$/9.36/-)$%:.4;<* Method Method !ďœ’ " *' % " ďœ‹ *ďœ‹ (ďœ‹ '"x *' #" ! &" $ " ďœ‹ ďœ‹ '"x *' UďœŠ !ďœ’ *' *ďœ‹ %*ďœŠ & ( " ďœ‹ % ")

*' ďœŠ " *' Method

11

setName (), calSalary (), printList (), getName (), toString (), showDetails


=ďœŠ-=.>?< (Constant)

12

!ďœ’ Identifier ďœ‹ "'$*' %! ' E ! *ďœŠ "' * ďœŠ " ( ďœ‹ ' & !ďœ’ ďœŠ ďœŠ ! %! (ďœ‹ " 5! %" ' ďœ‹ ! %! ďœŠ & ďœŠ " Compile 5! %" & " ( Error (Compile-time error) ďœ‹ Modifier ‘final’ " ! &" + ďœ‹ ďœŠ !ďœ’ ďœŠ (Constant) ďœ‹ ďœ‹ '"x *' UďœŠ ' (% & ďœ‹ _ (Underscore) !ďœ’ *' ' & ďœŠ ďœŠ - final double START_SAL = 10000; - final int MAX_SCORE = 100;


Keyword @);* =A->?B < .&6 (Reserved Word) Keyword +x compiler ) x & ďœ‹ % & ' &*ďœ‹ ( " ' $ keyword %*ďœŠ &*'

13


B%E9%/FG'+/=A- (separator) B%E9%/FG'+/=A-

14

@6->?<

; () , .

JK;<*)0LM/-)BN:6BMO8*.=A-B%<.$-.P Q-+36Q-F-R-&-

{}

JK;<*)0LML9T*/=A-B%<.8*.Q-F-R-&- =A-B%<.$-.P R0*+U 36L9T*/ J46 =A-B%<.Q-+36 class, method @);* 4MO=A-B%<.W=).B)-.=&L=MX$-.P J46 if, while, for J(6$6

BA-@)%L$*>-+ method @);*=A-B%<.*;<6P 36Q-F-R-&BA-@)%L'+/$%&'()@);*=A-B%<.36Q-F-R-&JK;<*3436/-))0LM attribute @);* method 8*. object @);*3436/-))0LM package


4ďœŠ*.&ďœŠ-. (whitespace) 5! %" ) x & ďœŠ ďœŠ % " ! &5 ' *ďœŠ E ) 5! %" (ďœ‹ 5( ďœŠ ďœŠ & ( ďœŠ "# (ďœ‹ ' compiler ) x & ďœŠ ďœŠ ďœŠ " ďœ‹ "'$ ( 5! %" bytecode ďœŠ ďœŠ & ďœŠ ďœ‹ 7!%$$ sourcecode (7 ďœŠ 7!%$$ ďœŠ ďœŠ

! &" $(ďœ‹ – ďœŠ ďœŠ

– % #! – " $ '( ďœŠ

15


46NO8ďœ‹*XU9K;6 : Z-6 (Primitive Data) ďœ‹ 7 ‡ ) x Java ' ( 8 ( ('

16

*# (Integer) : 4 ( byte, short, int, long + (Floating Point Number) : 2 ( float, double ďœŠ * "& (Boolean) : 1 ( true, false ďœŠ '" & ( (Character) : 1 ( char


46NO8ďœ‹*XU9K;6 : Z-6 (Primitive Data) 8 2

6 4

17

2


46NO8*XU9K;6 : Z-6 (Primitive Data)

18

46NO 8*XU9

RA-6&6LN$

=Default

byte

8

0

-27 (-128) ef. 27-1 (127)

short

16

0

-215 (-32768) ef. 215-1 (32767)

int

32

0

-231 (-2147483468) ef. 231-1 (2147483467)

long

64

0

-263 (J989LJ+*0X-/) ef. 263-1 (J98L&/J+*0X-/)

float

32

0.0

J/TLJ98>16N+X'90J98+//A-9%.

double

64

0.0

J/TLJ98>16N+X'90J98+//A-9%._O90J*?+O/&- float

boolean

2

false

char

16

\u0000

4&.8*.=->?<J/TL_O

true @);* false 34J/TL*%/8)0>?<X?)@%B$%:.'$ 0 ef. 65535


46NO8*XU9K;6 : Z-6 : Numeric

%*"* &   7 %* & ( (  7 " " (  7 * "  & "'$ 

 7 %* & (  (  7 ! int "#$  ( 7 6( = 2,147,483,647  * " "#$ $'* ! & *' ! & R 13 * % 

* "  (  7 ! long " "#$  ( 7 6( = 9,223,372,036,854,775,807  7  *# ! ( long & *' '"x l L *   3l, 089L, 0xBCL

19


46NO8ďœ‹*XU9K;6 : Z-6 : Character

!ďœ’ *' %! "#$ ďœŠ '" & " Unicode Character Set 5( '"x Unicode ' " 0 – 127 !ďœ’ '"x 6( ( "'$*' '"x ASCII char ďœŠ ďœŠ String (*' %! '"x|& !ďœ’ '" &) %*ďœŠ "' 7ďœŠ String (ďœ‹ ďœŠ char *ďœ‹ 7ďœŠ Single quotes (‘)

char a = 33 ---> ‘!’, char b = 65 ---> ‘A’ char : ‘c’ ‘a’ ‘r’ String : “carâ€? ---> ‘c’ + ‘a’ + ‘r’ int x = 1 % & char y = ‘1’ ---> x % & y ďœŠ %*"*ďœŠ "'

20


46NO8ďœ‹*XU9K;6 : Z-6 : Character Character Java ' '" &*ďœŠ E ďœŠ (ďœ‹

21


46NO8ďœ‹*XU9K;6 : Z-6 : Character ASCII Character Set !ďœ’ subset *' '"x Unicode ' " \u0000 (0) to \u007f (127)

22


46NO8ďœ‹*XU9K;6 : Z-6 : Character

23

!


46NO8ďœ‹*XU9K;6 : Z-6 : Boolean

24

Java ďœŠ ďœ‹ *# % ďœŠ boolean (%*"*ďœŠ ") x C % & C++) boolean ďœŠ (ďœ‹ 2 ďœŠ ďœŠ ' literal ( ďœ‹ % ( ďœŠ ) !ďœ’ true % & false boolean x = false; //OK boolean y = 1; //compile-time error boolean check = true;


Arithmetic Expression /-)=A-G&6>-.=GN$1-B$)ďœŽ

25

Expression ! &" $(ďœ‹ (Operator) % &*' 7"" & (Operand) (Operator) ! &" $(ďœ‹ + , - , * , / , % $ ) x ďœŠ C % & C++ ' ďœ‹ % (ďœ‹ ‘ & "'$ *# ďœŠ ' ( ďœ‹ 7 w ' WďœŽ (ďœ‹ "" | & "'$ ( ďœ‹ 7 Operand (' *# & *# Result *# + & + Result + *# & + Result +


Arithmetic Expression /-)=A-G&6>-.=GN$1-B$)ďœŽ $%&OA-J6N6/-) + * / % -++

26

=&-X@X-+ " $ " $ " " 7| " " & ‘ & +x ďœ‹ " ( ďœŠ ' & 1 " ďœŠ ' &1

$%&*+ďœŠ-. X–Y X+Y X*Y X/Y 11%3 = 3 +x 2 (' ' 2 !ďœ’ w ' WďœŽ X- - - -X "'$ X=X-1 X+ + + +X "'$ X=X+1


27

class IntAndDouble { public static void main (String args[]) { int i = 10; double x = 2.5; double k; /-)=A-G&6>-.=GN$1-B$)ďœŽ System.out.println("i is " + i); System.out.println("x 8 is " + x); k = i + x; 8.0 System.out.println("i + 15x is " + k); k = i * x; System.out.println("i *15.0 x is " + k); i is 10 k = i - x; 0 x is 2.5 System.out.println("i -0.6 x is " + k); i + x is 12.5 k = x - i; i * x is 25 System.out.println("x 0.6 - i is " + k); i - x is 7.5 k = i / x; 1 x - i is -7.5 System.out.println("i /1.5 x is " + k); i / x is 4 k = x / i; x / i is 0.25 System.out.println("x 3 / i is " + k); } }


Arithmetic Expression /-)=A-G&6>-.=GN$1-B$)ďœŽ

28

3+5 3 + 5.0 3*5 3 * 5.0 3/5 3 / 5.0 3.0 / 5 10 % 3 10.5 % 3 10 % 3.5

= = = = = = = = = =

8 8 15 15 0.6 0.6 0.6 1 1 1

1/2*3.5 = 0.00 0.0 3.5 * 1 / 2 = 1.75 1.0 /2 * 3.5 = 1.75


Shorthand Assignment Operators

Java Shortcut Assignment Operators 5 *' ‘+=’ , ‘-=’ , ‘*=’ , ‘/=’ , ‘%=’ i i i i i

29

+= 8 -= 8.0 *= 8 /= 8 %= 8

---> ---> ---> ---> --->

i i i i i

= = = = =

i i i i i

+8 - 8.0 *8 /8 %8


Increment and Decrement Operators

Java Increment and Decrement Operators 4 %$$ ‘++var’ , ‘var++’ , ‘--var’ , ‘var--’ ++var, --var / ( ďœŠ *' %! "ďœŠ " ' ďœŠ assisgn ďœŠ ďœŠ ďœŠ ďœ‹ var++, var-assign ďœŠ ďœŠ ďœŠ 6( *' %! ďœ‹"ďœŠ " '

ďœŠ / ( ďœŠ *' %!

30


Increment and Decrement Operators

int a = 0, b = 0, x = 1, y = 1;

System.out.print(a System.out.print(a System.out.print(a a = x++; System.out.print(a b = ++y; System.out.print(a

31

+ “:” + b + “:” + x++ + “:” + ++y); + “:” + b + “:” + ++x + “:” + y); + “:” + b + “:” + x + “:” + y++); + “:” + b + “:” + x + “:” + y); + “:” + b + “:” + x + “:” + y)

int i = 10; int new_i = 5 * (i++); 1. new_i = 5 * i; 2. i = i + 1;

int i = 10; int new_i = 5 * (++i) 1. i = i + 1; 2. new_i = 5 * i;


Operator Precedence 9A-O%L/-)>A-.-68*.J=);* < .@X-+$ďœŠ-.P 36 Expression 1. 2. 3. 4. 5.

() ++ , -*, /, % +, =

'$ 7ďœŠ ('$ ( "' & | " "Rďœ‹ !

32


Operator Precedence 9A-O%L/-)>A-.-68*.J=);* < .@X-+$ďœŠ-.P 36 Expression

int x = 2;

33

8

/ 2

4

* 3

x++ 1

8

+ 4

10

/ 2

2

% 3

48

/ 5

(6

* 4

(7

+ 3

(8

2

x++ ) * 1

x 3

4 2

5

(--x) 1

((x++) 1 2

5)))

8 2 18


Assignment Operator (=)

" 7ďœŠ ('$ ďœ‹ 6( $"'$ E

x

= 4

sum / 4 + min * total 1

3 =A-G&6

/A-@6O=ďœŠ-3@ďœ‹$%&'()

34

2


Type Conversion /-)/A-@6O=-)0@&-.$%&'()>?<X8 ? *XU9$-.46NO/%6

35

Automatic Type Conversions Casting


Type Conversion 1. Automatic Type Conversions double bigType; byte smallType = 120; bigType = smallType; Automatic Type Conversions Data type *' %! ' 2 &*ďœ‹ ďœ‹ "' (ďœ‹ (Compatible) 5( " 6ďœŠ ďœ‹ 7 ( ďœ‹ "' (ďœ‹ ( ďœ‹ 7 *' [byte, short, int, long, float, double] Data type *' %! ”ďœ?ďœ“ Rďœ‹ (left hand-side) &*ďœ‹ ďœŠ ( $ *) "" ďœŠ Data type *' %! ”ďœ?ďœ“

(right hand-side) " Type Conversion '"x|& ďœŠ widening conversion R & ďœŠ ďœ‹ 7 7U & ďœŠ " ! %! ďœŠ

36


Type Conversion

37

1. Automatic Type Conversions char smallType = ‘A’; int bigType; bigType = smallType; Result ---> bigType = 65 int smallType = 10000; double bigType; bigType = (double) smallType; bigType = smallType; Result ---> bigType = 10000.0

X?=-J>-/%6


Type Conversion 2. Casting

38

!ďœ’ " ! ďœŠ Data type ! !ďœ’ ďœŠ Data type * ďœ‹ " ďœŠ ďœŠ Data type ' & UďœŠ #"" ďœŠ " ďœ‹ Data type : boolean ďœŠ ! %! !ďœ’ Data type (ďœ‹ " Type Conversion '"x|& ďœŠ narrow conversion " '"x|& ďœ‹ 7 $ ďœŠ 7U & ďœŠ " ! %! ďœŠ R " ( (ďœ‹ 2 " | - ! " + !ďœ’ *# & ďœ‹ 6( + ! - ! " *# UďœŠ" ďœŠ !ďœ’ *# #"" ďœŠ & (ďœ‹w ' WďœŽ !ďœ’ ďœŠ 7" modulo (ďœ‹ ( ďœ‹ 7 '$ ďœŠ


Type Conversion 2. Casting

39

Syntax : (<type>) <term> byte smallType; int bigType = 257; smallType = bigType ; //compile-time error : Data type int U"  byte smallType = (byte) bigType ; //OK : narrow conversion Result ---> smallType = 1 ( Data type : byte 8 $ * (256  ) Result ---> 257 % 256 = 1


8ďœ‹*=&))0&%.J/?<+&/%L/-) cast 2. Casting

40

" cast ďœ‹ 7 " + !ďœ’ *# (*' ' 6( + & !) " cast ďœ‹ 7 " ďœ‹ 7 ( UďœŠ ( "#$ UďœŠ" ďœŠ ) ! !ďœ’ ďœ‹ 7 #"" ďœŠ ( "#$ #"" ďœŠ ) % ďœ‹ ďœŠ & (ďœ‹%*ďœŠ & ďœ‹w ' WďœŽ w ( !


$%&*+-. : cast

41

(int) (fX + fY) = 4 (int) fX + (int) fY = 3 (int) (b1 + b2) = 128 (b1 + b2) = -1

public class castSample{ public static void main(String[] args){ float fX = 1.3F, fY = 2.7F; 127 int iX; 1 iX = (int) (fX + fY); System.out.println(“(int) (fX + fY) = ”+iX); -1 iX = (int) fX + (int) fY; System.out.println(“(int) fX + (int) fY = ”+iX); byte b1 = 127, b2 =1; iX = (int) (b1 + b2); System.out.println(“(int) (b1 + b2) = ”+iX); b2 = (byte) (b1 + 1); System.out.println(“(b1 + b2) = ”+(b1+b2)); } }

1.3 + 2.7 1+2 127 + 1

01111111 00000001 10000000


String

42

Char type ďœ‹% *' '"x (ďœ‹ *' ( ďœŠ ' ďœŠ ‘H’ ďœ‹ *ďœ‹ " ďœ‹ '" & ďœ‹ ) x Java & ďœ‹ Data type " ďœŠ String ďœŠ String msg = “Helloâ€?; String !ďœ’ class " ( ďœ‹5( Java Library ďœŠ ( "'$ class E ďœŠ Integer, System, Random !ďœ’ *ďœ‹ String ďœŠ ďœŠ ďœ‹ 7 ( ‡ (Primitive data type) ) x Java %*ďœŠ & " ďœŠ !ďœ’ Reference type (Object) ďœ‹ & ďœ‹ !ďœ’ String *ďœ‹ 7ďœŠ Double quotes “â€? " ďœ‹ !ďœ’ String "'$ ďœ‹ 7 ( E (ďœ‹5( ďœ‹ ‘+’ ďœŠ String + String Result String String + Number Result String


String

43

System.out.println (“ABC” + “xyz”); System.out.println ("ABC" + 222); System.out.println (111 + "xyz"); System.out.println (111 + 222); System.out.println ("111" + "222"); System.out.println ("111 plus 222 is " + 111 plus 222 is 111222 System.out.println ("111 plus 222 is " + 111 plus 222 is 333

ABCxyz ABC222 111xyz 333 111222 111 + 222); (111 + 222));


Getting input from the console With Scanner class

) x Java & ďœ‹ System.out !ďœ’ Standard output ďœŠ Standard input ' & ďœ‹ System.in & ďœ‹ class Scanner ďœ‹ Object '$ ďœŠ ďœŠ input " System.in ( !ďœ’ ďœŠ * (*ďœŠ "'$w7ďœ‹ ďœ‹wďœŠ console) *' ďœŠ " ďœ‹ Object " class Scanner Scanner <reference name> = new Scanner (System.in); Scanner in = new Scanner (System.in);

44


Scanner’s method BA-@)%L*ďœŠ-6=ďœŠ-8*.8ďœ‹*XU946NO$ďœŠ-.P pďœŠ-6>-. console

45

next(), nextLine() nextByte() nextShort() nextInt() nextLong() nextFloat() nextDouble()

'$ ďœŠ '$ ďœŠ '$ ďœŠ '$ ďœŠ '$ ďœŠ '$ ďœŠ '$ ďœŠ

input input input input input input input

!ďœ’ !ďœ’ !ďœ’ !ďœ’ !ďœ’ !ďœ’ !ďœ’

String byte short int long float double


Scanner’s method $%&*+-./-)*-6=-8*.8*XU946NO String

System.out.print(“Enter your name: ”); Scanner in = new Scanner(System.in); String name = in.nextLine(); System.out.print(“Your name is : ” + name); 1

2

3

46


Class Libraries in Java

47

Class Library !ďœ’ " 6 ďœŠ Classes *ďœŠ E Java '( * ďœ‹ ďœ‹ ďœ‹ " '– 5! %" Java standard class library ďœŠ !ďœ’ ďœŠ Java development environment


Class Libraries in Java Library

Packages

Classes

48


Packages in Java *' ďœŠ Package Standard class library

java.lang java.applet java.awt

javax.swing

49

java.net java.util javax.xml.parsers

General support Creating applets for the web Graphics and graphical user interfaces Additional graphics capabilities and components Network communication Utilities XML document processing


Packages in Java The import declaration

50

Class 6" class 7ďœŠ java.lang Package 7" import ďœ‹ 5! %" 5( '*5 '* 7ďœŠ% ďœ‹ (' ' ďœŠ*ďœ‹ ! &" + " import " ďœŠ System, String " import class ďœ‹ ďœ‹ 5! %" &*ďœ‹ 7ďœŠ ' " Package ( ďœ‹ ) % & 7ďœŠ"ďœŠ ! &5 E 5! %" " ďœ‹ Comment


Packages in Java The import declaration

51

*ďœ‹ " ďœ‹ class *ďœŠ E Package (E & W " ďœ‹

2 7!%$$ (' ! &" + ďœ‹5( ďœŠ *# ďœŠ java.util.Scanner in = new java.util.Scanner(System.in); import class ďœ‹ ďœ‹ 5! %" " ' ! &" + ďœ‹5( ďœŠ ‘ & Class ďœŠ import java.util.Scanner; Scanner in = new Scanner(System.in); " import class E class Package ( "' (ďœ‹5( ďœ‹*' '"x wildcard (*) ďœŠ import java.util.*;


Lab Assignment Problem 1 : PersonRecord.java 5! %" *ďœ‹ "#$% & ďœŠ ďœŠ ďœ‹ 7 *ďœŠ E (ďœ‹ (' - ďœ‹ - - "6 ' "5! %" # *ďœ‹ % ( & ( ďœ‹ 7 (ďœ‹ 1.

User "#$

Title name First name Last name

: Mr. : Chavanit : Wongjunya

Person name

: Mr.Chavanit Wongjunya


Lab Assignment Problem 2 : CircleCal.java 5! %" *ďœ‹ | % & ďœ‹ $ " (ďœ‹ 5( | " ďœŠ '+ (Radius) " w7ďœ‹ ďœ‹" ( 2. ' "5! %" | # *ďœ‹ % ( w ' WďœŽ

% & ďœ‹ $ | (ďœ‹ 4. Âś = 3.14 ďœ‹ ďœŠ " Class Math (ďœ‹(' Math.PI 5. 7* " | = Âś r2 6. 7* " | ďœ‹ $ = 2 Âś r * r '+ " 1.


Lab Assignment CircleCal.java : Ex User "#$

Radius : 54 Area of circle with radius 54 : 9160.88 Perimeter of circle with radius 54 : 339.29


Lab Assignment Problem 3 : SpeedCar.java 5! %" *ďœ‹ | # *ďœŽ (ďœ‹ 5( | " & & % & w 7ďœ‹ ďœ‹" ( 5( - & & ďœŠ !ďœ’ " . - ďœŠ !ďœ’ 3. ' "5! %" | # *ďœ‹ % ( w # | (ďœ‹ 5( # (' " ďœŠ ďœŠ !ďœ’ " ./ . 1.

4.

# (" ./ .) = & & (" .) ( .)


Lab Assignment SpeedCar.java : Ex User "#$

Distance (Km.) : 24 Time (Minutes) : 20 Speed of car with distance 24 Km and time 20 minutes : 72 Km./Hour


Lab Assignment Problem 4 : SalaryPlan.java 5! %" *ďœ‹ | ( ' " '" ďœŠ *ďœŠ E * w7ďœ‹ ďœ‹" ( (ďœ‹ 5( - ( ďœŠ !ďœ’ $ / ( - '( ďœŠ ďœŠ !ďœ’ ďœ‹ & (%) ( 2. ďœŠ *ďœŠ E '" (' - ! &"' ' : 7% ( - $" 6 : 5% ( - ' ďœŽ : 20% ( ' "5! %" | # *ďœ‹ % ( & ( ( % & '"%*ďœŠ &! & ) (ďœ‹ 1.


Lab Assignment SalaryPlan.java : Ex User "#$

Salary (Baht) Social security (%) Providence fund (%) Saving rate (%)

: : : :

10000 7 5 40

Total salary Total of expenses Social security 7% Providence fund 5% Saving 40% Balance of salary

: : : : : :

10000 Baht 5200 Baht 700 Baht 500 Baht 4000 Baht 4800 Baht


Lab Assignment Problem 5 : Cashier.java 5! %" *ďœ‹ % " ďœŠ " w7ďœ‹ ďœ‹ " ( 5( % " " !ďœ’ - W $'* 1000 $ , 500 $ , 100 $ , 50 $ , 20 $ - U 10 $ , 5 $ , 1 $ 1.

' "5! %" | # *ďœ‹ % ( & ( W $'* / U (ďœ‹ "" % " ďœŠ (ďœ‹


Lab Assignment Cashier.java : Ex User "#$

Cash (Baht)

: 4887

Total cash Bank 1000 Bank 500 Bank 100 Bank 50 Bank 20 Coin 10 Coin 5 Coin 1

: : : : : : : : :

4887 4 Unit 1 Unit 3 Unit 1 Unit 1 Unit 1 Unit 1 Unit 2 Unit


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.