APLIKASI RESERVASI HOTEL (ANDROID)
Standar
Deskripsi dari plikasi ini berguna untuk mereservasi kamar yang akan dipesan oleh customer, sehingga memudahkan petugas.
Dan berikut adalah pembuatan aplikasi ke dalam aplikasi android dan di dalamnya terdapat 3 aktivitas, sbb :
- Login Activity (LoginActivity.class)
- Capture
-
- Java
package org.eresha.hamid_mulyadi.uts; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.app.LoaderManager.LoaderCallbacks; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.EditorInfo; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> { protected static final String[] DUMMY_CREDENTIALS = new String[]{ "admin:123", "hamid.mulyadi:12345678" }; // UI references. private AutoCompleteTextView mUsernameView; protected EditText mPasswordView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); // Set up the login form. mUsernameView = (AutoCompleteTextView) findViewById(R.id.username); populateAutoComplete(); mPasswordView = (EditText) findViewById(R.id.password); mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) { attemptLogin(); return true; } return false; } }); Button mSignInButton = (Button) findViewById(R.id.signIn_button); mSignInButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { attemptLogin(); } }); } private void populateAutoComplete() { getLoaderManager().initLoader(0, null, this); } private void attemptLogin() { // Reset errors. mUsernameView.setError(null); mPasswordView.setError(null); // Store values at the time of the login attempt. String username = mUsernameView.getText().toString(); String password = mPasswordView.getText().toString(); boolean fail = false; View focusView = null; for (int i = 0; i < DUMMY_CREDENTIALS.length; i++) { String[] pieces = DUMMY_CREDENTIALS[i].split(":"); if (pieces[0].equals(username) && !pieces[1].equals(password)) { mPasswordView.setError(getString(R.string.error_incorrect_username_password)); focusView = mPasswordView; fail = true; } } if (fail) { focusView.requestFocus(); } else { Intent intent = new Intent(this, SuccessActivity.class); intent.putExtra("displayName", username); startActivity(intent); } } @Override public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { return null; } @Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { } @Override public void onLoaderReset(Loader<Cursor> cursorLoader) { } }
- XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".LoginActivity"> <!-- Login progress --> <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:visibility="gone" /> <ScrollView android:id="@+id/login_form" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <AutoCompleteTextView android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_username" android:maxLines="1" android:singleLine="true" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_password" android:imeActionId="6" android:imeActionLabel="@string/action_sign_in" android:imeOptions="actionUnspecified" android:inputType="textPassword" android:maxLines="1" android:singleLine="true" /> </android.support.design.widget.TextInputLayout> <Button android:id="@+id/signIn_button" style="?android:textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="@string/action_sign_in" android:textStyle="bold" /> </LinearLayout> </ScrollView> </LinearLayout>
- Capture
- Dashboard Activity (SucessActivity.class)
- Capture
- Java
package org.eresha.hamid_mulyadi.uts; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; import android.content.Intent; import android.os.Build; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class SuccessActivity extends AppCompatActivity { protected TextView mUsernameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_success); mUsernameView = findViewById(R.id.username); mUsernameView.setText("Selamat datang, " + getIntent().getExtras().getString("displayName")); Button mLogoutButton = (Button) findViewById(R.id.logout_button); mLogoutButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { attemptLogout(view); } }); Button mFormReservasiButton = (Button) findViewById(R.id.button_form_reservasi); mFormReservasiButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFormReservasi(v); } }); } private void getFormReservasi(View v) { switch(v.getId()) { case R.id.button_form_reservasi: Intent intent = new Intent(this, FormReservasiActivity.class); intent.putExtra("displayName", getIntent().getExtras().getString("displayName")); startActivity(intent); } } private void attemptLogout(View v) { switch (v.getId()) { case R.id.logout_button: finish(); } } }
- XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".SuccessActivity"> <ScrollView android:id="@+id/sucess_form" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/dashboard_form" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_dashboard" android:maxLines="1" android:singleLine="true" android:textAlignment="textStart" /> </android.support.design.widget.TextInputLayout> <Button android:id="@+id/logout_button" style="?android:textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="@string/action_sign_out" android:textStyle="bold" /> <TextView android:id="@+id/textView_Petugas" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:text="Menu Petugas Hotel" android:textAlignment="center" /> <Button android:id="@+id/button_form_reservasi" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Input Form Reservasi" /> </LinearLayout> </ScrollView> </LinearLayout>
- Capture
- Input Reservasi Activity (FormReservasi.class)
- Capture
- Java
package org.eresha.hamid_mulyadi.uts; import android.annotation.SuppressLint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class FormReservasiActivity extends AppCompatActivity { private TextView staff; private EditText customer_name; private EditText customer_date; private EditText customer_phone; private RadioButton customer_standar_room; private RadioButton customer_deluxe_room; private EditText customer_staytime; private EditText customer_room_booking; private Button reset; private Button simpan; private TextView hasil_order; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form_reservasi); staff = findViewById(R.id.staff_name); staff.setText("Nama Petugas: " + getIntent().getExtras().getString("displayName")); customer_name = findViewById(R.id.customer_name); customer_date = findViewById(R.id.customer_date); customer_phone = findViewById(R.id.customer_phone); customer_standar_room = findViewById(R.id.customer_standarRoom); customer_deluxe_room = findViewById(R.id.customer_deluxeRoom); customer_staytime = findViewById(R.id.customer_staytime); customer_room_booking = findViewById(R.id.customer_roomBooking); simpan = findViewById(R.id.button_pesan); simpan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { doOrder(); } }); hasil_order = findViewById(R.id.detail_pesan); } @SuppressLint("ResourceType") private void doOrder() { String name = customer_name.getText().toString(); String data_checkin = customer_date.getText().toString(); String no_hp = customer_phone.getText().toString(); String stay_time = customer_staytime.getText().toString(); String room_booking = customer_room_booking.getText().toString(); String tipe_kamar = ""; Long harga_kamar = null; if (customer_standar_room.getId() > 0) { tipe_kamar = "Standard Room Rp 1.500.000"; harga_kamar = new Long(1500000); } else if (customer_deluxe_room.getId() > 0) { tipe_kamar = "Deluxe Room Rp 2.500.000"; harga_kamar = new Long(2500000); } Long total_harga = (harga_kamar * Long.parseLong(room_booking)) * Long.parseLong(stay_time); Long diskon = new Long(0); if (total_harga >= 5000000) { diskon = new Long (20); } Long total_semua = (total_harga * diskon) / 100; String order = "Struk Pembayaran Anda :" + "\nNama Pemesan : " + name + "\nTanggal Check-in : " + data_checkin + "\nNo Handphone : " + no_hp + "\nDurasi Menginap : " + stay_time + "\nBanyaknya Kamar : " + room_booking + "\nTipe Kamar : " + tipe_kamar + "\nTotal Harga : Rp " + total_harga + "\nDiscount (%) : " + diskon + "\n============================================" + "\nTotal Harga Keseluruhan : " + total_semua + "\n============================================"; hasil_order.setText(order); } }
- XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".FormReservasiActivity"> <ScrollView android:id="@+id/svFormReservasi" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/form_reservasi" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/staff_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_dashboard" android:maxLines="1" android:singleLine="true" android:textAlignment="textStart" /> <EditText android:id="@+id/customer_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" android:hint="Nama Pemesan" /> <EditText android:id="@+id/customer_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Tanggal Check-in" android:inputType="date" /> <EditText android:id="@+id/customer_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="No Handphone" android:inputType="phone" /> <RadioGroup android:layout_width="match_parent" android:layout_height="match_parent" > <RadioButton android:id="@+id/customer_standarRoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:hint="Standart Room" /> <RadioButton android:id="@+id/customer_deluxeRoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="Deluxe Room" /> </RadioGroup> <EditText android:id="@+id/customer_staytime" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Durasi Menginap" android:inputType="number" /> <EditText android:id="@+id/customer_roomBooking" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Jumlah Kamar Dipesan" android:inputType="number" /> <Button android:id="@+id/button_reset" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Reset" /> <Button android:id="@+id/button_pesan" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Pesan" /> <TextView android:id="@+id/detail_pesan" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Detail Pemesanan." /> </LinearLayout> </ScrollView> </LinearLayout>
- Capture


