LAMPIRAN Lampiran 1 Kode Program 1. DBhelper.java package com.example.animallesson; import java.io.File; import import import import import import import import import android.content.ContentValues; android.content.Context; android.content.ContextWrapper; android.database.Cursor; android.database.SQLException; android.database.sqlite.SQLiteDatabase; android.database.sqlite.SQLiteException; android.database.sqlite.SQLiteOpenHelper; android.util.Log; public class DBhelper public static public static public static "bahasainggris"; public static public static public static private private private static private { final String EMP_ID = "id"; final String EMP_NAMA = "nama"; final String EMP_BAHASAINGGRIS = final String EMP_PHOTO = "photo"; final String EMP_KELAS = "kelas"; final String EMP_NO = "nomor"; DatabaseHelper mDbHelper; SQLiteDatabase mDb; final String DATABASE_NAME = "Binatang.db"; static final int DATABASE_VERSION = 1; private static final String PENGENALAN_TABLE = "Pengenalan"; private static final String CREATE_PENGENALAN_TABLE = "create table " + PENGENALAN_TABLE + " (" + EMP_ID + " integer primary key autoincrement, " + EMP_NAMA + EMP_PHOTO + " text not null, " + EMP_NO + " text not null unique, " + EMP_KELAS + " text not null );"; + " text not null unique, " + EMP_BAHASAINGGRIS + " text not null unique, " + EMP_PHOTO + " text not null, " + EMP_NO + " text not null unique, " + EMP_KELAS + " text not null );"; 40 public void onCreate(SQLiteDatabase db){ db.execSQL(CREATE_PENGENALAN_TABLE); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){ d //db.execSQL("DROP TABLE IF EXISTS " + PENGENALAN_TABLE); onCreate(db); } } public void Reset(){ mDbHelper.onUpgrade(this.mDb, 1, 1); } public DBhelper(Context ctx){ mCtx = ctx; mDbHelper = new DatabaseHelper(mCtx); } public DBhelper open() throws SQLException{ mDb = mDbHelper.getWritableDatabase(); return this; } public void close(){ mDbHelper.close(); } void DeleteAll(){ SQLiteDatabase db=mDbHelper.getWritableDatabase(); db.delete(PENGENALAN_TABLE, null, null); } public void insertPengenalanDetails(Pengenalan pengenalan){ ContentValues cv = new ContentValues(); cv.put(EMP_PHOTO, pengenalan.getBitmap()); cv.put(EMP_NAMA, pengenalan.getNama()); cv.put(EMP_BAHASAINGGRIS, pengenalan.getBahasaInggris()); cv.put(EMP_NO, pengenalan.getNomor()); cv.put(EMP_KELAS, pengenalan.getKelas()); mDb.insert(PENGENALAN_TABLE, null, cv); } public Pengenalan retrivePengenalanDetails(int no, String k) throws SQLException{ Cursor cur = mDb.query(true, PENGENALAN_TABLE, new String[] { EMP_NAMA, EMP_BAHASAINGGRIS, EMP_PHOTO, EMP_NO, EMP_KELAS }, EMP_NO + "=? AND " + EMP_KELAS + "=?", new String[] {String.valueOf(no), k}, null, null, null, null); if (cur.moveToFirst()){ int foto = cur.getInt(cur.getColumnIndex(EMP_PHOTO)); String nama = cur.getString(cur.getColumnIndex(EMP_NAMA)); 41 String bahasainggris = cur.getString(cur.getColumnIndex(EMP_BAHASAINGGRIS)); String kelas = cur.getString(cur.getColumnIndex(EMP_KELAS)); String nomor = cur.getString(cur.getColumnIndex(EMP_NO)); cur.close(); return new Pengenalan(nama, bahasainggris, foto, kelas, nomor); } cur.close(); return null; } } Kode Program 2. Kuis.java package com.example.animallesson; import java.io.File; import java.util.Random; import import import import import import import import import import import import import import import import import android.app.Activity; android.app.AlertDialog; android.app.ProgressDialog; android.content.Context; android.content.DialogInterface; android.content.Intent; android.database.Cursor; android.os.AsyncTask; android.os.Bundle; android.util.Log; android.view.Menu; android.view.View; android.widget.Button; android.widget.EditText; android.widget.ImageView; android.widget.TextView; android.widget.Toast; public class Kuis extends Activity { private String _nama = ""; private String kelas = ""; private DBhelper DbHelper; public int nilai = 1; public int count = 0; private String bahasainggris = ""; private String jawaban = ""; public int score=0; 42 private EditText jawabEditText; Random r = new Random(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kuis); Intent i = this.getIntent(); _nama = i.getStringExtra("nama"); kelas = i.getStringExtra("kategori"); InsertDataIntoDatabase task = new InsertDataIntoDatabase(); Kode Program 2. Kuis.java task.applicationContext = Kuis.this; task.execute(Kuis.this); Kode Program 2. Kuis.java if (kelas.equals("Mamalia")){ int Low = 1; int High = 50; nilai = r.nextInt(High-Low) } if (kelas.equals("Burung")){ int Low = 51; int High = 72; nilai = r.nextInt(High-Low) } if (kelas.equals("Reptil")){ int Low = 73; int High = 81; nilai = r.nextInt(High-Low) } if (kelas.equals("Amfibi")){ int Low = 82; int High = 84; nilai = r.nextInt(High-Low) } if (kelas.equals("Ikan")){ int Low = 85; int High = 94; nilai = r.nextInt(High-Low) } if (kelas.equals("Serangga")){ int Low = 95; int High = 104; nilai = r.nextInt(High-Low) } + Low; + Low; + Low; + Low; + Low; + Low; } 43 Kode Program 3. KuisHasil.java package com.example.animallesson; import import import import import import android.app.Activity; android.content.Intent; android.os.Bundle; android.view.Menu; android.view.View; android.widget.TextView; public class KuisHasil extends Activity { private String _nama =""; private int _hasil = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kuishasil); Intent i = this.getIntent(); _nama = i.getStringExtra("nama"); _hasil = i.getIntExtra("hasil", 0); TextView nama; TextView hasil; try{ nama = (TextView) findViewById(R.id.NamatextView); hasil = (TextView) findViewById(R.id.HasiltextView); nama.setText("Nama : " + _nama ); hasil.setText("Score : " + _hasil ); }catch(Exception ex){ nama = (TextView) findViewById(R.id.NamatextView); nama.setText(ex.getMessage()); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } 44 public void onBackPressed(){ //doing nothing on pressing back key return; } public void Kembali(View v){ Intent i = new Intent(KuisHasil.this, MainActivity.class); startActivity(i); finish(); } } 45 Kode Program 4. KuisMenu.java package com.example.animallesson; import import import import import android.app.Activity; android.content.Intent; android.os.Bundle; android.view.Menu; android.view.View; public class KuisMenu extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kuismenu); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void MulaiKuis(View v){ Intent i = new Intent(KuisMenu.this, KuisNama.class); startActivity(i); } } 46 Kode Program 4. KuisNama.java package com.example.animallesson; import java.util.ArrayList; import java.util.List; import import import import import import import import android.app.Activity; android.content.Intent; android.os.Bundle; android.view.Menu; android.view.View; android.widget.ArrayAdapter; android.widget.EditText; android.widget.Spinner; public class KuisNama extends Activity { private Spinner kategoriSpinner; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kuisnama); addSpinnerItems(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void MulaiKuis(View v){ Intent i = new Intent(KuisNama.this, Kuis.class); EditText Namaet; Namaet = (EditText) findViewById(R.id.NamaeditText); String nama = Namaet.getText().toString(); kategoriSpinner = (Spinner) findViewById(R.id.Kategori); String kategori = kategoriSpinner.getSelectedItem().toString(); i.putExtra("nama", nama); i.putExtra("kategori", kategori); startActivity(i); } 47 public void addSpinnerItems(){ kategoriSpinner = (Spinner) findViewById(R.id.Kategori); List<String> daftar = new ArrayList<String>(); daftar.add("Mamalia"); daftar.add("Burung"); daftar.add("Reptil"); daftar.add("Ikan"); daftar.add("Serangga"); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_dropdown_item, daftar); dataAdapter.setDropDownViewResource(android.R.layout. simple_spinner_dropdown_item); kategoriSpinner.setAdapter(dataAdapter); } } Kode Program 5. MainActivity.java package com.example.animallesson; import import import import import import import import android.os.Bundle; android.app.Activity; android.view.Menu; android.app.AlertDialog; android.content.Context; android.content.DialogInterface; android.content.Intent; android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 48 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void Keluar(View v){ final Context context = this; AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); alertDialog.setTitle("Konfirmasi"); //judul alertDialog //atur pesan .setMessage("Apakah anda yakin akan keluar dari aplikasi ini ??") .setCancelable(false) .setPositiveButton("Ya", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int id) { // jika diklik activity di close MainActivity.this.finish(); } }) .setNegativeButton("Tidak", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // jika diklik, tutup dialog dialog.cancel(); } }); //buat dialognya AlertDialog alertDialogShow = alertDialog.create(); //ditampilkan alertDialog.show(); } 49 public void Pengenalan(View v){ Intent i = new Intent(MainActivity.this, PengenalanAwal.class); startActivity(i); } public void Tentang(View v){ Intent i = new Intent(MainActivity.this, tentang.class); startActivity(i); } public void KuisMenu(View v){ Intent i = new Intent(MainActivity.this, KuisNama.class); startActivity(i); } } Kode Program 6. Pengenalan.java package com.example.animallesson; public class Pengenalan { private String _nama; private String _bahasainggris; private int _bmp; private String _kelas; private String _nomor; public Pengenalan(String nama, String bahasainggris, int bmp, String kelas, String nomor){ this._nama = nama; this._bahasainggris = bahasainggris; this._bmp = bmp; this._kelas = kelas; this._nomor = nomor; } public Pengenalan(){ } public String getNama(){ return this._nama; } public String getBahasaInggris(){ return this._bahasainggris; } public int getBitmap(){ return this._bmp; } public String getKelas(){ return this._kelas; } public String getNomor(){ return this._nomor; } } 50 Kode Program 7. PengenalanActivity.java package com.example.animallesson; import java.io.File; import import import import import import import import import import import android.app.Activity; android.app.ProgressDialog; android.content.Context; android.content.Intent; android.database.Cursor; android.os.AsyncTask; android.os.Bundle; android.util.Log; android.view.MotionEvent; android.widget.ImageView; android.widget.TextView; public class PengenalanActivity extends Activity { private DBhelper DbHelper; private float x1,y1,x2,y2; public int nilai = 1; String kelas = ""; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.pengenalan); try{ Intent i = this.getIntent(); kelas = i.getStringExtra("kiriman"); if (kelas.equals("Mamalia")){ nilai = 1; } if (kelas.equals("Burung")){ nilai = 51; } if (kelas.equals("Reptil")){ nilai = 73; 51 PROGDI D3 TEKNIKINFORMATIKA Fakultas Teknologi Informasi Universitas Kristen Satya Wacana Salatiga Kartu Bimbingan Tugas Akhir Nama : Ardi Pratama Patengko NIM : 562011019 Fak/Jur : Fakultas Teknologi Informasi / D3 Teknik Informatika Judul Proyek :PERANCANGAN APLIKASI MENGENAL NAMA BINATANG DALAM Pembimbing : Felix David, S.Kom Periode : Semester 3 Tahun 2013/2014 BAHASA INGGRIS BERBASIS ANDROID No Hari/ Keterangan Paraf Tanggal 1 2 3 4 5 6 7 8 9 10 Salatiga, 18 Agustus 2014 Pembimbing (Felix David, S.Kom) 52