You are on page 1of 16

Teacher Initial:

Daffodil International University MJM


Spring 2021
Department of Computer Science and Engineering
Final Open Book Assessment Answer Script
Full Marks: 40 Allowed, Time: 5:00 hrs.
Date: Tuesday 20, April 2021

General Information (must be filled by the student)


COURSE CODE: SECTION: PROGRAM: DAY EVEN
CSE334 A

STUDENT ID: TIME STARTED: TIME ENDED:


182-15-11358 10 am 3 pm

ANSWER TO THE QUESTION NO: 1 (a)


Student ID:
Student ID:

writting down the xml code for the home user interface :
<?xml
version="1.0"
encoding="utf-
8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.csumb.cgieg.mainmenu">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.CustomerCreate"
android:label="@string/title_activity_customer_create">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.CustomerPlaceHold"
android:label="@string/title_activity_customer_place_hold">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.CustomerLogin"
android:label="@string/title_activity_customer_login">
</activity>
Student ID:

<activity

android:name="edu.csumb.cgieg.mainmenu.CustomerConfirmation"
android:label="@string/title_activity_customer_confirmation">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.CustomerCancelHold"
android:label="@string/title_activity_customer_cancel_hold">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.LibrarianLogin"
android:label="@string/title_activity_librarian_login">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.LibrarianLogs"
android:label="@string/title_activity_librarian_logs">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.LibrarianAddBook"
android:label="@string/title_activity_librarian_add_book">
</activity>

<activity
android:name="edu.csumb.cgieg.mainmenu.LibrarianConfirmation"
android:label="@string/title_activity_librarian_confirmation">
</activity>
</application>

</manifest>
Student ID:

ANSWER TO THE QUESTION NO: 1 (b)


Yes, user permission is needed here .

This application is using for sharing the books. So , it is better to share or sell it by
communicate with the customers and knowing their needs. For communication we can
directly communicate with them .so , we can say the permission shown by the system
when we call request permissions . It will say what permission my app wants but doesn’t
say why . In some cases the user may find the puzzle to solve. Its better to explain to
the user that app wants the permission before calling request .

ANSWER TO THE QUESTION NO: 2 (a)


No, Fragment classes are not needed for my application. The relationship between
Fragment and Activity are describing below –

A fragment represents a behavior or a portion of the user interface in an Activity. You


can have multiple fragments in an activity or you can reuse a fragment in multiple
activities. You can think of a fragment like a modular section of an activity. It has its own
lifecycle, receives its own input events, and you can add or remove them while the
activity is running.There are two ways for you to add a fragment into an activity. One is
by adding the fragment into the activity’s layout file. Another is by adding it into an
existing ViewGroup in your application code. When you add a fragment as part of the
activity layout, it lives in a ViewGroup inside the activity’s view hierarchy and the
fragment defines its own view layout.
An activity is a crucial component of an Android app. The way activities are launched
and put together is a fundamental part of the Android platform application model. The
Android system initiates code in an activity instance by invoking specific callback
methods that correspond to specific stages of its lifecycle. This way of initialization is
unlike other programming paradigms that launch with a main() method.
A fragment must always be hosted in an activity and a fragment’s lifecycle is directly
affected by the host activity’s lifecycle. For example, when an activity resumes so will all
of its fragments and when the activity pauses so will all of the fragments. However,
while an activity is running (resumed lifecycle state), you can freely manipulate the state
of a fragment, such as add or remove them. Another way to look at it is that when a
fragment changes state it doesn’t affect the activity, but when the activity changes state
it does affect the fragment. Activity and fragments operate under the one-to-many
relationship. That is, you can have one activity and host many fragments on top of it.
The opposite case does not hold true. In fact, a fragment can’t exist without an activity
to be the host.
Student ID:

ANSWER TO THE QUESTION NO: 2 (b)

APPLICATION DEVELOPMENT LIFECYCLE


Application Development Lifecycle describes a process of planning, creating, testing
and deploying an information system. It consists of a series of steps which system
developers use to design, build, test and deliver an information system. There are such
ADLC phases:

 Preliminary analysis. On this stage costs and benefits are described, alternative
solutions are proposed and submitted a preliminary plan.

 Systems Analysis. On this stage the functions of the application are defined.

 System Design. On this stage described the features of the application.

 Development. On this stage the developers write the code.

 Testing. On this stage the application is checked for bugs.

 Acceptance, installation, deployment. On this stage the application is put into


production.

 Maintenance. On this stage the changes are made.

 Evaluation. On this stage the developed system is evaluated.

ANSWER TO THE QUESTION NO: 3 (a)

Yes , Database Is there needed for developing the application. I used Firebase realtime
database here in my application .

Firebase Realtime Database is a cloud-hosted database that supports multiple


platforms Android, iOS and Web. All the data is stored in JSON format and any
changes in the data, reflects immediately by performing sync across all the platforms
& devices. This allows us to build more flexible realtime apps easily with minimal
effort.In simpler words, we can say that a Firebase Realtime Database is a type of
database that is cloud-hosted i.e. it runs on the cloud and it can be accessed from any
platform i.e. it can be accessed from Android, iOS and Web at the same time. So,
make the database once and use it on different platforms. The data stored in the
database is of the form of NoSQL database and is stored in JSON format. The best
part is that whenever there is a change in the database, it will be immediately reflected
all the devices connected to it.
Student ID:

Advantages of using Firebase Realtime Database :

 Realtime: The data stored in the Firebase Realtime Database will be reflected
at realtime i.e. if there is a change in the values in the database then that
change will be reflected back to all the users at that instant only and no dealy
will be there.
 Large Accessibility: The Firebase Realtime Database can be accessed from
various platforms like Android, iOS, Web. So, you need not write the same code
for different platforms a number of times.
 Offline Mode: This is the best advantage of using Firebase Realtime Database.
If you are not connected with the internet and you changed something on your
application then that change will be reflected in your application at that time
only but on the Firebase Database, the change will be updated once you are
online i.e. your device is connected to the internet. So, even if there is no
internet, the user feels like using the services the same as done when there is
the internet.
 No Application Server: There is no need for application server here because
the data is directly accessed from the mobile device.
 Control access to data: By default, no one is allowed to change the data in
the Firebase Realtime Database but you can control the access of data i.e. you can
set which user can access the data.

Describing the step by step procedure for my database connection :

Step 1: Open Android Studio and create a new project or open an existing project.

Step 2: In Android Studio, log in with email. You can find the login button at the top
right corner of the Android Studio.

Step 3: Open the Firebase Website and login into it. (use the same email id as used in
Android Studio for login)

Step 4: After login, click on the "Go To Console" button that is present of the upper
right side of the website.

Step 5: Click on "Add Project"

Step 6: Enter the required details of the project and click on submit

Step 7: After creating a project, you will see the below image of your project
dashboard.
Student ID:

Step 8: Click on "Database" and then in the Realtime Database section, click on
"Create Database".

Step 9: Since we are just using the database for our practice purpose. So, select the
"Start in test mode" option and click on enable.

Step 10: Now, come back to your Android Studio project. We have to connect our
Firebase project with the Android Studio project. So, click on Tools > Firebase >
Realtime Database > Save and retrieve data.

Step 11: After that click on "Connect to Firebase". A list of projects will be shown to
you. Select the project that you have created on the Firebase website and click on
"Connect to Firebase".

Step 12: Lastly, you have to add the dependency of Firebase Realtime Database in
your project by clicking on "Add Firebase Realtime Database to your app" button
and then "Accept changes".

ANSWER TO THE QUESTION NO: 3 (b)


MAIN MENU.Java Code:

package
edu.csumb.cgieg.mainmenu;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;

public class MainMenu extends Activity implements


OnClickListener {
private static final String TAG = "MainMenu";
// declare widget button variables
private Button SaraCreateAccountBtn;
Student ID:

private Button SaraPlaceHoldBtn;


private Button SaraCancelHoldBtn;
private Button SaraManageSystemBtn;

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);

// initialize widget button variables


SaraCreateAccountBtn =
(Button)findViewById(R.id.SaraCreateAccountBtn);
SaraPlaceHoldBtn =
(Button)findViewById(R.id.SaraPlaceHoldBtn);
SaraCancelHoldBtn =
(Button)findViewById(R.id.SaraCancelHoldBtn);
SaraManageSystemBtn =
(Button)findViewById(R.id.SaraManageSystemBtn);

// set on click listeners for widget button


variables
SaraCreateAccountBtn.setOnClickListener(this);
SaraPlaceHoldBtn.setOnClickListener(this);
SaraCancelHoldBtn.setOnClickListener(this);

SaraManageSystemBtn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.SaraCreateAccountBtn:
// redirect to customer create activity
Log.d(TAG, "Create Account clicked");
Intent CustomerCreate = new
Intent(getApplicationContext(),
CustomerCreate.class);
startActivity(customerCreate);
break;
case R.id.SaraPlaceHoldBtn:
// redirect to customer place hold activity
Student ID:

Log.d(TAG, "Place Hold clicked");


Intent CustomerPlaceHold = new
Intent(getApplicationContext(),
CustomerPlaceHold.class);
startActivity(CustomerPlaceHold);
break;
case R.id.SaraCancelHoldBtn:
// redirect to customer login activity
Log.d(TAG, "Cancel Hold clicked");
Intent CustomerLogin = new
Intent(getApplicationContext(),
CustomerLogin.class);
startActivity(CustomerLogin);
break;
case R.id.manageSystemBtn:
// redirect to librarian login activity
Log.d(TAG, "Manage System clicked");
Intent librarianLogin = new
Intent(getApplicationContext(), LibrarianLogin.class);
startActivity(librarianLogin);
break;
}
}
}

CUSTOMER LOGIN Java Code :

package
edu.csumb.cgieg.mainm
enu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
Student ID:

public class CustomerLogin extends Activity implements


OnClickListener {
private static final String TAG = "CustomerLogin";
// declare widget variables
private EditText SaraCustomerUsernameEditText;
private EditText SaraCustomerPasswordEditText;
private Button SaraCustomerLoginBtn;
private TextView
SaraCustomerLoginMessageTextView;
private Button SaraCustomerLoginOkBtn;

// declare and initialize book rental confirmation


variables
private String username = "";
private String pickupDateHour = "";
private String returnDateHour = "";
private String bookTitle = "";
private double bookFeePerHour = 0.0;

// declare and initialize attempts variable


private static int attempts = 0;

public boolean validLogin() {


boolean validLogin = false;
String username =
customerUsernameEditText.getText().toString();
String password =
customerPasswordEditText.getText().toString();
CsumbLibraryDB db = new CsumbLibraryDB(this);
ArrayList<Customer> customers =
db.checkCustomers(username, password);
if (customers.size() == 1) { // valid customer
validLogin = true;
attempts = 0;
}
return validLogin;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Student ID:

setContentView(R.layout.activity_customer_login);

// initialize widget variables


SaraCustomerUsernameEditText =
(EditText)findViewById(R.id.customerUsernameEditText
);
SaraCustomerPasswordEditText =
(EditText)findViewById(R.id.customerPasswordEditText)
;
SaraCustomerLoginBtn =
(Button)findViewById(R.id.customerLoginBtn);
SaraCustomerLoginBtn.setOnClickListener(this);
SaraCustomerLoginMessageTextView =
(TextView)findViewById(R.id.customerLoginMessageTe
xtView);
SaraCustomerLoginOkBtn =
(Button)findViewById(R.id.customerLoginOkBtn);
SaraCustomerLoginOkBtn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.SaraCustomerLoginBtn) {
Log.d(TAG, "Login clicked");
String message = "";
String prompt = "Please try again.";
if (validLogin()) { // customer login is valid
Log.d(TAG, "customer is valid");
Toast.makeText(this, "You are now logged in",
Toast.LENGTH_LONG).show(); // special toast

SaraCustomerLoginMessageTextView.setText("");
Bundle extras = getIntent().getExtras();
username =
SaraCustomerUsernameEditText.getText().toString(); //
do this before extras != null
if (extras != null) { // get confirmation variables
from SaraCustomerPlaceHold
pickupDateHour =
extras.getString("sqlPickupDateHour");
returnDateHour =
extras.getString("sqlReturnDateHour");
bookTitle = extras.getString("bookTitle");
Student ID:

bookFeePerHour =
extras.getDouble("bookFeePerHour");
}
Bundle extraInfo = new Bundle();
extraInfo.putString("username", username);
extraInfo.putString("sqlPickupDateHour",
pickupDateHour);
extraInfo.putString("sqlReturnDateHour",
returnDateHour);
extraInfo.putString("bookTitle", bookTitle);
extraInfo.putDouble("bookFeePerHour",
bookFeePerHour);
if (pickupDateHour.equals("")) { // customer is
trying to cancel holds
Log.d(TAG, "redirect to customer cancel
hold");
// redirect to customer cancel hold activity
Intent customerCancelHold = new
Intent(getApplicationContext(),
CustomerCancelHold.class);

SaraCustomerCancelHold.putExtras(extraInfo);
startActivity(customerCancelHold);
}
else {
Log.d(TAG, "redirect to customer
confirmation");
// redirect to customer confirmation activity
Intent customerConfirm = new
Intent(getApplicationContext(),
CustomerConfirmation.class);
customerConfirm.putExtras(extraInfo); //
pass confirmation variables to customerConfirm
startActivity(customerConfirm);
}
}
else {
Log.d(TAG, "customer username and/or
password is invalid");
message = "Username and/or password is
invalid";

SaraCustomerLoginMessageTextView.setText(message
+ ". " + prompt);
attempts++;
}
Student ID:

if (attempts == 2) {
attempts = 0;

SaraCustomerUsernameEditText.setFocusable(false);

SaraCustomerPasswordEditText.setFocusable(false);

SaraCustomerLoginBtn.setVisibility(View.GONE);

SaracustomerLoginMessageTextView.setText("");

SaraCustomerLoginMessageTextView.setText(message
+ " again. Click OK to go to the main menu.");

SaraCustomerLoginOkBtn.setVisibility(View.VISIBLE);
}
}
else if (v.getId() == R.id.SaraCustomerLoginOkBtn)
{ // OK clicked
Log.d(TAG, "OK clicked");
Log.d(TAG, "redirect to main menu");
Intent mainMenu = new
Intent(getApplicationContext(), MainMenu.class);
startActivity(mainMenu);
}
}
}
Student ID:
Student ID:

You might also like