You are on page 1of 20

Name : Rania Mughal

Class : BSSE 2018

Final Lab task

Question #1

1. Upon launching, Signup Activity will be displayed that must include:

● CNIC

● First name, Last name

● Gender

● Email address

● Contact number
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"
android:padding="30dp"
tools:context=".SignUp">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Full Name"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter User Name"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Contact number"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="CNIC"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textSizes="20sp"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="20sp"
android:layout_marginLeft="10dp"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Female"
android:textSize="20sp"
/>
</RadioGroup>

<Button
android:layout_width="match_parent"
android:layout_height="67dp"
android:layout_marginTop="40dp"
android:background="@drawable/button_rounded"
android:text="Register"
android:textColor="#ffffff"
android:textSize="22sp"

app:rippleColor="@color/blue" />

</LinearLayout>

SignUp.java
package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class SignUp extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
getSupportActionBar().setTitle("Sign Up Form");
}

}
Question # 2

After signing up, the user will login the application using CNIC number
Main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Login">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:textColor="#0B8F9F"
android:textSize="28sp"
tools:layout_editor_absoluteX="152dp"
tools:layout_editor_absoluteY="190dp"
tools:text="login" />

<Button
android:id="@+id/button2"
android:layout_width="221dp"
android:layout_height="43dp"
android:layout_gravity="center"
android:background="#0B8F9F"
android:text="login"
android:textColor="#F8F8F8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="427dp" />

<EditText
android:id="@+id/editText"
android:layout_width="362dp"
android:layout_height="49dp"
android:background="#FFFFFF"
android:ems="10"
android:hint=" Confirm CNIC"
android:inputType="textcnic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="334dp" />

<EditText
android:id="@+id/editText2"
android:layout_width="365dp"
android:layout_height="50dp"
android:background="#FFFFFF"
android:ems="10"
android:hint=" Enter CNIC "
android:inputType="textCnic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.431"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="270dp" />

<FrameLayout
android:layout_width="422dp"
android:layout_height="59dp"
android:background="#0B8F9F"
tools:layout_editor_absoluteX="-1dp"
tools:layout_editor_absoluteY="671dp">

</FrameLayout>

<ImageView
android:id="@+id/imageView2"
android:layout_width="162dp"
android:layout_height="154dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.441"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="36dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

Login.Java
package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Login extends AppCompatActivity {

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

etCNIC = findViewById(R.id.et_CNIC);
etConfCNIC = findViewById(R.id.et_ConfCNIC);
btLogin = findViewById(R.id.bt_Login);

btLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etCNIC.getText().toString().equals("12345")
etConfCNIC.getText().toString().equals("12345")){

AlertDialog.Builder builder = new AlertDialog.Builder(


Login.this

);
builder.setTitle("Login Successfull!!");
}
else{
Toast.makeText(getApplicationContext();

text"Invalid CNIC" , Toast.LENGTH_SHORT).show()

}
}
});

}
}

Question # 3
After login the app, TicketBooking Activity will take the given details from the user:

● Source

● Destination

● Departure Date

● Class type (Economy, First class sleeper)

Activity_ticket_booking.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TicketBooking">

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"
android:padding="30dp"

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Source "
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Destination"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Departure Date"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Class Type"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class Type"
android:textSizes="30sp"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Economy"
android:textSize="20sp"
android:layout_marginLeft="10dp"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="62dp"
android:layout_marginLeft="10dp"
android:text="First Class Sleeper"
android:textSize="20sp" />
</RadioGroup>

<Button
android:layout_width="match_parent"
android:layout_height="67dp"
android:layout_marginTop="40dp"
android:background="@drawable/button_rounded"
android:text="Confirm Booking"
android:textColor="#ffffff"
android:textSize="22sp"

app:rippleColor="@color/blue" />

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Database
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/texttitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please enter the details below"
android:textSize="24dp"
android:layout_marginTop="20dp"
/>
<EditText
android:id="@+id/Source"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Karachi "
android:textSize="24dp"
android:layout_below="@+id/texttitle"
android:inputType="textSource"/>

<EditText
android:id="@+id/Destination "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Lahore "
android:textSize="24dp"
android:layout_below="@id/source"
android:inputType="number"/>
<EditText
android:id="@+id/DepartureDate "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Departure Date"
android:textSize="24dp"
android:layout_below="@id/Destination"
android:inputType="number"/>

<Button
android:id="@+id/classType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="Economy "
android:layout_marginTop="30dp"
android:layout_below="@id/classType"/>

<Button
android:id="@+id/classType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="First Class Sleeper "
android:layout_marginTop="30dp"
android:layout_below="@id/classType"/>

</RelativeLayout>

DBHelper.Java

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBHelper extends SQLiteOpenHelper {


public DBHelper(Context context) {
super(karachi, Lahore, 3, 1);
}

@Override
public void onCreate(SQLiteDatabase DB) {
DB.execSQL("create Table Userdetails(source TEXT primary key NOT NULL,
Destination TEXT , Departure TEXT , Class Type TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase DB, int i, int i1) {
DB.execSQL("drop Table if exists Userdetails");
}

public Boolean insertuserdata(String name, String contact, String salary)


{
SQLiteDatabase DB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("source",source);
contentValues.put("destination", destination);
contentValues.put("departure", departure);
contentValues.put("ClassType", classtype);

long result=DB.insert("source", destination, departure, classtype);


if(result==-1)
{
return false;}

else {return true;}


}

public Boolean updateuserdata(String source, String destination,varchar


departure, string classtype) {
SQLiteDatabase DB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("destination", destination);
contentValues.put("departure", departure);
Cursor cursor = DB.rawQuery("Select * from Userdetails where source = ?", new
String[]{source});
if (cursor.getCount() > 0) {
long result = DB.update("Userdetails", contentValues, "name=?", new
String[]{name});
if (result == -1) {
return false;
} else {
return true;
}
} else {
return false;
}}

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText source, destination,departure, classtype;
Button insert;
DBHelper DB;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
source = findViewById(R.id.source);
destination = findViewById(R.id.destination);
departure= findViewById(R.id.departure);
insert = findViewById(R.id.btnInsert);
DB = new DBHelper(this);
insert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String sourceTXT = source.getText().toString();
String destinationTXT = destination.getText().toString();
String departureTXT = departure.getText().toString();
String classtypeTXT = classtype.getText().toString();
if (sourceTXT.isEmpty() || destinationTXT.isEmpty()||
departureTXT.isEmpty()|| classtypeTXT.isEmpty()||)
{
Toast.makeText(MainActivity.this, "Fields are Empty",
Toast.LENGTH_SHORT).show();

else {
Boolean checkinsertdata = DB.insertuserdata(sourceTXT,
destinationTXT, departureTXT, classtypeTXT);
if (checkinsertdata == true && checkinsertdata != null) {
Toast.makeText(MainActivity.this, "New Entry Inserted",
Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, "New Entry not Inserted",
Toast.LENGTH_SHORT).show();

}
source.setText("");
destination.setText("");
departure.setText("");
classtype.setText("");
}

});

AlertDialog.Builder builder = new


AlertDialog.Builder(MainActivity.this);
builder.setCancelable(true);
builder.setTitle("User Entries");
builder.setMessage(buffer.toString());
builder.show();
} });
}}

Question # 4

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TicketBooking">

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"
android:padding="30dp"
tools:context=".SignUp">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Source "
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Karachi"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Destination"
android:ems="10"
android:inputTypes="text"
android:textSizes="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Lahore"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Departure"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="28-June-2021"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class Type"
android:textSizes="30sp"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Economy"
android:textSize="20sp"
android:layout_marginLeft="10dp"
/>
</RadioGroup>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Seat number"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="9dp"
android:textColorHint="@color/colorPrimaryDark"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="1822222"
android:inputTypes="text"
android:textSizes="22sp" />
</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

You might also like