1446t - Tp1 - r0 - Imam Prawiranagara
-
Upload
imam-prawiranagara -
Category
Documents
-
view
6 -
download
0
description
Transcript of 1446t - Tp1 - r0 - Imam Prawiranagara
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 1/16
Tugas Personal ke-1
Minggu 2
Review Questions:1. What is the Java source filename extension, and what is the Java bytecode filename
extension?
2. Is Java case sensitive? Give an example to prove your answer.
. !re they any performance differences between the followin" two import statements?
a. Import #ava.util.$canner%
b. Import #ava.util.&%
'. (sin" the Pseudo-code and flowchart, create)
a. an al"orithm to calculate a trian"le area*
b. an al"orithm to chan"e second into hour and minute unit*
c. an al"orithm to accept three numbers and find max, min, and avera"e number*
+. escribe and "ive example for each method of $trin"
a. contains
b. concat
c. compare-o
d. format
e. char!t
f. replace
". substrin"
h. trim
i. tohar!rray
#. split
/. to0owerase
l. to(pperase
Programming Exercise:
uatlah sebuah pro"ram untu/ mempela#ari tipe data dalam pemro"raman Java,
den"an men""una/an beberapa /etentuan seperti ini)
1. ada awal pro"ram, user a/an diminta untu/)
3emasu//an tipe data oolean, user diminta untu/ memasu//an 4true5 atau
4false5
3emasu//an tipe data int, user diminta untu/ memasu//an bilan"an bulat
3emasu//an tipe data ouble, user diminta untu/ memasu//an bilan"an decimal
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 2/16
3emasu//an tipe data $trin", user diminta untu/ memasu//an /ata atau /alimat
2. 6emudian semua hasil yan" dimasu//an user, a/an ditampil/an pada a/hir pro"ram.
ilakan !alankan E"E file untuk melihat sam#le #rogram$
Print creen dari Program ketika Meminta %n#utan dengan Ti#e &ata 'oolean
Print creen dari Program ketika Meminta %n#utan dengan Ti#e &ata %nt
Print creen dari Program ketika Meminta %n#utan dengan Ti#e &ata &ou(le
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 3/16
Print creen dari Program ketika Meminta %n#utan dengan Ti#e &ata tring
Print creen dari )asil
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 4/16
Jawaban
1. Java source files extension dia/hiri den"an .java . $edan"/an #ava bytecode dia/hiri
den"an .class.
2. Import #ava.util.$canner% adalah perintah dari user /e pro"ram Java untu/ men"ambil
atau men"import (tility lass pada scanner sa#a sedan"/an import #ava.util.&% adalah
perintah user /e pro"ram #ava untu/ men"import semua class yan" ada dalam class
utility.
. !. 0uas $e"iti"a)
PE*&+,+&E:
ro"ram men"hitun" luas se"iti"a77input ) alas, tin""i, bilan"an bulat
77output) luas, bilan"an decimal
.M*:
!las) Inte"er
-in""i) Inte"er
0uas ) double
./0+R%TM.:
$-!8-89!:4tin""i5;
89!:4alas5;
0(!$ $9GI-IG! <=== :alas&tin""i; 7 2%W8I-9 :4luas se"iti"a adalah) 5;9>
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 5/16
/+,).RT:
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 6/16
. 6onversi eti/ /e Jam, 3enit
PE*&+,+&E
ro"ram men"ubah deti/ men#adi #am, menit, deti/.77input ) inputan, bilan"an bulat non ne"atif
77output ) #am, menit, deti/ bilan"an bulat non ne"ative
.M*
Inputan ) inte"er
Jam ) byte3enit ) byte
eti/ ) byte
./0+R%TM.
$-!8-
89! :inputan;
Jam <=== inputan I @AA
3enit <=== :inputan B :#am & @AA;; I@Aeti/ <=== :inputan = :#am &@AA;; 3C @A
W8I-9 <=== :#am, menit, deti/;9>
/+,).RT
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 7/16
. mencari max, min, dan avera"e dari nilai inputan
PE*&+,+&E
ro"ram mencari max, min dan avera"e dari nilai inputan
77input) bil1, bil2, bil, bilan"an bulat
77output) min, max, bilan"an bulat% avera"e, bilan"an decimal
.M*
bil1, bil2, bil ) Inte"er min,max ) Inte"er
!vera"e )double
./0+R%TM.
$-!8-
89! :bil1,bil2,bil;
ID bil1Ebil2, bil1Ebil -F9>
W8I-9:bil 1 3!;90$9 ID bil2Ebil1, bil2Ebil -F9>
W8I-9:bil2 3!;90$9
W8I-9 :bil 3!;
9>ID!vera"e <=== :bil1Hbil2Hbil; 7
W8I-9 :!vera"e;
9>
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 8/16
/+,).RT
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 9/16
a. contains )It chec/s whether the strin" contains the specified seuence of char
values. If yes then it returns true else false. It throws >ullointer9xception of sK is null.
b. concat ) oncatenates the specified strin" 4str5 at the end of the strin".
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 10/16
c. compare-o ) -his method compares the two strin"s based on the (nicode value of
each character in the strin"s.
d. format ) method allows you to create a formatted strin" that you can reuse, as
opposed to a one=time print statement
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 11/16
e. char!t ) 8eturns the character at the specified index.
f. replace ) 8eturns a new strin" resultin" from replacin" all occurrences of
oldhar in this strin" with newhar.
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 12/16
". substrin" ) 8eturns a new strin" that is a substrin" of this strin".
h. trim ) 8eturns a copy of the strin", with leadin" and trailin" whitespace
omitted.
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 13/16
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 14/16
/. to0owerase ) onverts all of the characters in this $trin" to lower case usin" the rules
of the default locale.
l. to(pperase ) onverts all of the characters in this $trin" to upper case usin" the rules
of the default locale.
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 15/16
PR+0R.MM%30 E"ER,%E E,T%+3:
,+&E:
import java.util.Scanner;
public class LearnDataType
{ static boolean bool;static int bilanganBulat;static double bilanganDecimal;static String kalimat;static Scanner L;
public static void main(String[ args!{L " ne# Scanner(System.in!;
System.out.println($Learn Data Type$!;System.out.println($Let%s Learn Data Type$!;System.out.println($in %java% t&ere are some primitive data types '$!;System.out.println($boolean byte c&ar s&ort int long )loat double$!;System.out.println($and t&ere is an abstract data type String$!;
System.out.println($no# #e #ill learn boolean int double and string datatypes$!;
System.out.println($*. Boolean data types &ave + values #&ic& is true,)alse$!;System.out.print($-o# try to entering a boolea data type e/ample true,)alse0"$!;bool " L.ne/tBoolean(!;System.out.println($+. 1nt data type &as a value o) integer #it& range
2+*34356735 to 8+*34356734$!;System.out.print($-o# try to entering a int data type don%t use decimal e/ample
*990 " $!;bilanganBulat " L.ne/t1nt(!;System.out.println($6. Double data type &as a value o) decimal #it& range *.4e2695
to *.3e8965$!;System.out.print($-o# try to entering a double data type decimal number e/ample
*9.30 " $!;bilanganDecimal " L.ne/tDouble(!;,,some problem )i/ t&at i cant e/plain #&y it skipped a)ter entering int or double
values,,need some e/planation #it& ms.cuk t&o in class )orum t&enL.ne/tLine(!;System.out.println($3. String data type &as a value in t&e )orm o) a combination
o) c&aracters$!;System.out.print($-o# try to entering a String data type a #ord,sentence space
allo#ed00 " $!;kalimat " L.ne/tLine(!;
System.out.println($T&en Let%s try to print t&e result$!;System.out.println($*. Boolean data type t&at you entered " $8bool!;System.out.println($+. 1nt data type t&at you entered " $8bilanganBulat!;
System.out.println($6. Double data type t&at you entered " $8bilanganDecimal!;System.out.println($3. String data type t&at you entered " $8kalimat!;
:
:
7/21/2019 1446t - Tp1 - r0 - Imam Prawiranagara
http://slidepdf.com/reader/full/1446t-tp1-r0-imam-prawiranagara 16/16