Download - Kelompok 5 Bpl
-
8/18/2019 Kelompok 5 Bpl
1/40
BAHASA PEMOGRAMANLANJUT
BY KELOMPOK 5 PTIK 02/2013
FAKULTAS TEKNIK UNIVERSITAS NEGERI MAKASSAR2015
-
8/18/2019 Kelompok 5 Bpl
2/40
KELOMPOK 5
ASRIANI 1329040007
SHERLYANI 1329042061
MUSDALIFAH 1329041012
ADHAM AHDAR 1329040041
MUHAMMAD AR!AN MASHUDI 132904200"
-
8/18/2019 Kelompok 5 Bpl
3/40
BAB " ARRAY DAN ARGUMEN BARISPERINTAH
BAB 9 KELAS DAN OB#EK
-
8/18/2019 Kelompok 5 Bpl
4/40
BAB "ARRAY DAN ARGUMEN
BARIS PERINTAH
-
8/18/2019 Kelompok 5 Bpl
5/40
M$%&'()
G$*+$'$, A''$-
M&,.&$'$($, V$'($+& A''$-
M&,(%$$, O+& A''$-
M&,$& E&*&, A''$-
M&*+&'($, N($( S$$% O+& A''$- D((%$$, M&,&%$( #*$ E&*&, A''$-
A''$- M%(.(*&,(
A'*&, B$'( P&'(,%$
-
8/18/2019 Kelompok 5 Bpl
6/40
G$*+$'$, A''$-
A''$- $.$ #$8$ $.$$ +& -$, .$$% .(,$$,% *&,-(*$, &*$ .$%$: E&*&, -$,.((*$, $.$ $''$- .$$% +&'$ %(& '(*(%
-
8/18/2019 Kelompok 5 Bpl
7/40
M&,.&$'$($, V$'($+& A''$-
P&,.&$'$($, 8$'($+& $''$- .($$, .&,$,
+&,%)
A%$
,%)
S%'(,>? %$@
I,%>? ,($(@
tipePrimitif
namaVariabelArray >?@
namaKelas
namaVariabelArray >?@
-
8/18/2019 Kelompok 5 Bpl
8/40
M&,(%$$, +& A''$-
P&,(%$$, +& $''$- .$, &,$$, +& &8$'($+& $''$- .($$, .&,$, *&,,$$, $%$,( new: B&,%,-$ &+$$( +&'(%)
,%)
Kota = new String[5];
nilai = new int[3];
namaKelas namaVariabel = new
namaKelas> jumlahElemen?;
tipePrimitif namaVariabel = new
tipePrimitif > jumlahElemen?@
-
8/18/2019 Kelompok 5 Bpl
9/40
M&,$& E&*&, A''$-
E&*&, $''$- .$$% .($& *&$( ,%$(@
S+'( +&'$ ,*' &&*&,: D$$* $ (,( &&*&,&'%$*$ *&*((( +'( +&'$ , &&*&, &.$*&*,-$( +'( 1 .$, &%&',-$:
,%) kota[0] = “Jakarta”; A$, *&*+$%&&*&, &'%$*$ +'(?
;
-
8/18/2019 Kelompok 5 Bpl
10/40
,%. P''$* +&'(% *&,,$, ,% &*+$%$, $''$-
(,$ &,$&$, $''$-:
H$(P''$
// Berkas: ContohArray.java
public classContohArray {public static voidmain(String[] args) {
String[] kota;kota = newString[5];// engisie!emen arraykota["] =#$akarta#;kota[%] =#Ban&'ng#;kota[] =#Semarang#;kota[] =#e&an#;kota[*] =#+ogya#;
// enam,i!kane!emen arraySystem.out.,rint!n(kota["]);System.out.,rint!n(kota[%]);System.out.,rint!n(kota[]);System.out.,rint!n(kota[]);System.out.,rint!n(kota[*]);
--
-
8/18/2019 Kelompok 5 Bpl
11/40
M&*+&'($, N($( S$$% O+&A''$- D((%$$,
P&*+&'($, ,($( $.$ array .$$% .($$,&$% +& array .((%$$,:
,%)
String[] kota = {$akarta0 Ban&'ng0
Semarang0 e&an0 +ogya-;1imana *$ &&*&, $''$- %(.$ &' .(&+&$'$ &((%:
-
8/18/2019 Kelompok 5 Bpl
12/40
,%. ,% P''$*
P''$*) ,%A''$-2:$8$
H$(P''$*
-
8/18/2019 Kelompok 5 Bpl
13/40
M&,&%$( #*$ E&*&, A''$- #*$ &&*&, $''$- .$$% .(&%$( .&,$,
*&,,$$, 8$'($+& (,%$, length *(( +& $''$-:
,%)
2ota.!ength
M&,$($, *$ &&*&, $''$- -$, .(' &
K%$:H$(
P''$
-
8/18/2019 Kelompok 5 Bpl
14/40
A''$- M%(.(*&,(
#$8$ *&,., $''$- *%(.(*&,( *&$(&,.&$%$, C$''$- .$'( $''$-:
S&+$$( ,%) int >? >? (& new int>5?>3?@
*&'$$, (*&*&,%$( $''$- +&'.(*&,(.$
-
8/18/2019 Kelompok 5 Bpl
15/40
,% ''$* -$, *&,,$$, $''$- +&'.(*&,( .$P''$*) A''$-D(*&,(D$:$8$
H$(P''$
-
8/18/2019 Kelompok 5 Bpl
16/40
P''$* ) ArrayTangga.java
H$(P''$*
-
8/18/2019 Kelompok 5 Bpl
17/40
A'*&, B$'( P&'(,%$
Penanganan baris perintah pada java dilakukan melargumen yang terdapat pada metode main().
M($,-$)
3'4!i stati voi& main(String[] args)
Pada contoh ini argument baris perintah dapat diamdari variabel array args. Adapun jumlah argumen da
diperoleh melalui variabel instan pada kelas String
yang bernama length.
-
8/18/2019 Kelompok 5 Bpl
18/40
,% P''$* P''$*) T$*(A':$8$
-
8/18/2019 Kelompok 5 Bpl
19/40
BAB 9
KELAS DAN OB#EK
-
8/18/2019 Kelompok 5 Bpl
20/40
MATERI)
K,& P&*'$*$, B&''(&,%$( O+& M&,,$$, O+&
M&,(%$$, K&$
M&,,$$, K&$ .$$* P''$*
K&$ .&,$, M&%.&
K$%$ K,( %(
L(, V$'($+&
P&,&,% A&) '(8$%& .$, +(
M&%.& K&$
-
8/18/2019 Kelompok 5 Bpl
21/40
KONSEP PEMOGRAMANBERORIENTASI OB#EK
Pada pemrograman berorientasi objek terdapat 2 istilah yang saterkenal yaitu kelas dan objek. Kedua istilah ini di pertukarkan.
Perbedaan kelas dan objek dapat dijelaskan melalui analogi ber
Kelas itu seperti cetakan kue
Kelas adalah cetakan untuk objek
K&$ &+$$(&%$$, % +&
-
8/18/2019 Kelompok 5 Bpl
22/40
MENGGUNAKAN OB#EK
O+& .(+$% .&,$, *$*$ *&*+$% 8$'($+&
-$, &$ *&' & +&: V$'($+& &&'%( (,(+($$ .(&+% 8$'($+& +&: S&$,%,-$ +&.((%$$, *&$( ,& .$, $(,-$ .(%$$,&8$'($+& +&:
,%)
1ate 6akt'Sekarang;
7akt'Sekarang = ne6 1ate();
A%$
1ate 6akt'Sekarang = ne6 1ate ();
-
8/18/2019 Kelompok 5 Bpl
23/40
,%.
P''$*) O+&T$,$:$8$
H$( P''$*
-
8/18/2019 Kelompok 5 Bpl
24/40
M&,(%$$, K&$
K&$ $.$ $8$ .(.&,(($, .&,$, *&,,$$,$%$ ,( cla:
,% &.&'$,$ &,(%$$, &$)
C!ass o4i! {String 6arna;
8nt tah'n3ro&'ksi;-
P$.$ ,% .( $%$ &$ -$, .(+$% +&',$*$M+(: D$$* $ (,( $',$ .$, %$,P'.(.(&+% 8$'($+& (,%$, $%$ eld.
-
8/18/2019 Kelompok 5 Bpl
25/40
M&,,$$, K&$ .$$*P''$* P''$* K&$M+(:$8$
H$P''
-
8/18/2019 Kelompok 5 Bpl
26/40
K&$ .&,$, M&%.&) S&+$ &$ **,-$ %&', $%$ 8$'($+& (,%$,
.$, *&%.& ,% +&: M&%.& $.$$ ;,(
-
8/18/2019 Kelompok 5 Bpl
27/40
,% P''$*)
P''$*) K&$M+(2:$8$
A('P''$*
-
8/18/2019 Kelompok 5 Bpl
28/40
K$%$ K,( %(
K$%$ ,( thi .(&'$$, $.$ &*+$%$, &
.$, .(,$$, ,% *&,-$%$$, +& &$'$, ,% &,.&,(($, &$ &&'%( +&'(%)
voi& isi1ata (String 6arnao4i!0 int tah'n3ro&'ksio4i!) {
6arna = 6arnao4i!;tah'n3ro&'ksi =
tah'n3ro&'ksio4i!;-
B($ .(%( *&,$.(
8(. ((D$%$
-
8/18/2019 Kelompok 5 Bpl
29/40
AP''$
-
8/18/2019 Kelompok 5 Bpl
30/40
R(, V$'($+&
,% +&'(% *&,,$, &,$*$$, 8$'($+& -$, $*$
%&%$( $.$ (, -$, +&'+&.$)
-
8/18/2019 Kelompok 5 Bpl
31/40
P&,&$$, .$'( ,%)
warna .(.&$'$($, $.$ &$ (,&+$$( 8$'($+& (,%$, *$, $.$ *&%.&infoLingup
-
8/18/2019 Kelompok 5 Bpl
32/40
,% ''$* P''$*) L(,V$'($+&:$8$
H$P'
-
8/18/2019 Kelompok 5 Bpl
33/40
P&,&,% A&) '(8$%& .$, +
D$ .($,%$'$ &,&,% $& -$, %&'&.($ $.$$!rivate .$, !"#lic:
P"#lic +&'$'%( +$$ &,$&$, $% 8$'($+&(,%$, $%$ *&%.& .$$% .($$, .$'( $' &$:
Private +&'$'%( +$$ &,$&$, $% 8$'($+&(,%$, $%$ *&%.& $,-$ .$$% .($$, .( .$$*&$@ %(.$ +($ .($& .$'( $' &$:
P''$*) P&,&,%A&:$8$
-
8/18/2019 Kelompok 5 Bpl
34/40
H$(P''$*)
-
8/18/2019 Kelompok 5 Bpl
35/40
P&'+&.$$, +( '(8$%& .$,%$,$ &,&,% $& $.$ 8$'($+&
Penentu Akses Keterangan
Tanpa penentu
akses
Variabel dapat diakses oleh kelas yang
berbeda dalam paket yang sama
public Variabel dapat diakses pada semua kelas
yang menggunakan kelas yang berisi variabetersebut
private Hanya dapat diakses oleh metode-metode
dalam kelas itu sendiri
-
8/18/2019 Kelompok 5 Bpl
36/40
P&'+&.$$, +( '(8$%& .$,%$,$ &,&,% $& $.$ *&%.&
PenentuAkses
Keterangan
Tanpa
penentu akses
etode hanya dapat diakses oleh metode dala
kelas itu sendiri ataupun metode pada kelas la
yang terletak pada paket yang sama
public etode dapat diakses oleh sebarang kelas
private Hanya dapat diakses oleh metode-metode dal
kelas yang sama
P''$*) P&,&,%M&%.&:$8$
-
8/18/2019 Kelompok 5 Bpl
37/40
B&'(;$% '(8$% *$$ $$, %&'$.(&$$$,
-
8/18/2019 Kelompok 5 Bpl
38/40
,%.A(
P''$
.
-
8/18/2019 Kelompok 5 Bpl
39/40
M&%.& K&$ K$.$,$$ .(*$( &*$,($, *&%.& *&%.& .&,$,
+&,%)
D$, +$, .$$* +&,%
P''$*) M&%.&K&$:$8$
namaKelas.nama!etode"#
namaVariabel$bje.nama!et ode"#
A('P''$*
-
8/18/2019 Kelompok 5 Bpl
40/40
P''$*) M&%.&K&$2:$8$
A(' P''$*)