Professional Documents
Culture Documents
1.Design and develop an Mobile App for smart phones The Easy Unit Converter using Android.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/statistics_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:dividerHeight="1.0sp"
android:scrollbars="none"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
android:layout_marginBottom="8dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<TextView
android:id="@+id/navigation_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginLeft="16dp"
android:layout_marginTop="12dp"
android:textColor="@color/primary_text"
android:layout_alignTop="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
Page 1 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
android:text="@string/hello_world"/>
</RelativeLayout>
import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.github.ivbaranov.mli.MaterialLetterIcon;
import java.util.List;
import java.util.Random;
import elearning.chidi.com.elearning.R;
public class CalculationAdapter extends BaseAdapter {
private LayoutInflater lInflater;
private List<String> listStorage;
private final TypedValue mTypedValue = new TypedValue();
private int mBackground;
private List<String> mValues;
private int[] mMaterialColors;
private int mType;
private Context context;
private static final Random RANDOM = new Random();
public CalculationAdapter(Context context, List<String> customizedListView) {
lInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
listStorage = customizedListView;
}
@Override
public int getCount() {
return listStorage.size();
}
@Override
public Object getItem(int position) {
return listStorage.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder listViewHolder;
if(convertView == null){
listViewHolder = new ViewHolder();
convertView = lInflater.inflate(R.layout.calculation_list, parent, false);
listViewHolder.calculationText = (TextView)convertView.findViewById(R.id.navigation_name);
listViewHolder.letterIcon = (MaterialLetterIcon)convertView.findViewById(R.id.imageView);
convertView.setTag(listViewHolder);
}else{
listViewHolder = (ViewHolder) convertView.getTag();
}
mMaterialColors = context.getResources().getIntArray(R.array.colors);
Page 2 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
mBackground = mTypedValue.resourceId;
mValues = this.listStorage;
listViewHolder.calculationText.setText(listStorage.get(position));
listViewHolder.letterIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]);
listViewHolder.letterIcon.setLetter(mValues.get(position));
return convertView;
}
static class ViewHolder{
TextView calculationText;
MaterialLetterIcon letterIcon;
}
}
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
import elearning.chidi.com.elearning.adapter.CalculationAdapter;
public class UnitConverterFragment extends Fragment {
public UnitConverterFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_unit_converter, container, false);
List<String> calculationSolver = calculationList();
ListView calculation = (ListView) view.findViewById(R.id.statistics_list);
CalculationAdapter tutorialAdapter = new CalculationAdapter(getActivity().getApplicationContext(),
calculationSolver);
calculation.setAdapter(tutorialAdapter);
calculation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
Intent unitIntent = new Intent(getActivity(), UnitConverterActivity.class);
startActivity(unitIntent);
break;
case 1:
Intent lengthIntent = new Intent(getActivity(), LengthConverterActivity.class);
startActivity(lengthIntent);
break;
case 2:
Intent massIntent = new Intent(getActivity(), MassConverterActivity.class);
startActivity(massIntent);
break;
case 3:
Intent pressureIntent = new Intent(getActivity(), PressureConverterActivity.class);
Page 3 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
startActivity(pressureIntent);
break;
case 4:
Intent volumeIntent = new Intent(getActivity(), VolumeConverterActivity.class);
startActivity(volumeIntent);
break;
case 5:
Intent speedIntent = new Intent(getActivity(), SpeedConverterActivity.class);
startActivity(speedIntent);
break;
case 6:
Intent temperatureIntent = new Intent(getActivity(), TemperatureConverterActivity.class);
startActivity(temperatureIntent);
break;
case 7:
Intent timeIntent = new Intent(getActivity(), TimeConverterActivity.class);
startActivity(timeIntent);
break;
case 8:
Intent energyIntent = new Intent(getActivity(), EnergyConverterActivity.class);
startActivity(energyIntent);
break;
case 9:
Intent powerIntent = new Intent(getActivity(), PowerConverterActivity.class);
startActivity(powerIntent);
break;
case 10:
Intent velocityIntent = new Intent(getActivity(), VelocityConverterActivity.class);
startActivity(velocityIntent);
break;
}
}
});
return view;
}
private List<String> calculationList() {
List<String> calculations = new ArrayList<String>();
calculations.add("Area");
calculations.add("Length");
calculations.add("Mass");
calculations.add("Pressure");
calculations.add("Volume");
calculations.add("Speed");
calculations.add("Temperature");
calculations.add("Time");
calculations.add("Energy");
calculations.add("Power");
calculations.add("Velocity");
return calculations;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Page 4 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@color/color_primary"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="@style/AppTheme.Toolbar.Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/icons">
<ScrollView
android:id="@+id/scroll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/relativeAd"
android:layout_marginBottom="8dp
android:background="#ffffff"
android:padding="16dp"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/binary_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/title_activity_length_converter"
android:textColor="@color/primary_text"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/first_binary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/binary_title"
android:layout_below="@+id/binary_title"
android:layout_marginTop="24dp"
android:text="@string/from_unit"
android:textStyle="bold"
android:textColor="@color/primary_text" />
<Spinner
Page 5 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
android:id="@+id/from_spinner"
android:layout_width="match_parent"
android:layout_alignLeft="@+id/first_binary"
android:layout_below="@+id/first_binary"
android:background="@drawable/bottom_border"
android:layout_marginTop="4dp"
android:layout_height="wrap_content">
</Spinner>
<TextView
android:id="@+id/enter_a_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/unit_value"
android:layout_below="@+id/from_spinner"
android:layout_marginTop="24dp"
android:text="@string/enter_value"
android:textStyle="bold"
android:textColor="@color/primary_text" />
<EditText
android:id="@+id/unit_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/enter_a_number"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:background="@drawable/bottom_border"
android:inputType="numberDecimal"
android:padding="8dp" />
<TextView
android:id="@+id/to_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/unit_value"
android:layout_below="@+id/unit_value"
android:layout_marginTop="24dp"
android:text="@string/to_unit"
android:textStyle="bold"
android:textColor="@color/primary_text" />
<Spinner
android:id="@+id/to_spinner"
android:layout_width="match_parent"
android:layout_alignLeft="@+id/first_binary"
android:layout_below="@+id/to_unit"
android:background="@drawable/bottom_border"
android:layout_marginTop="4dp"
android:layout_height="wrap_content">
</Spinner>
<Button
android:id="@+id/calculation_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/button_all"
Page 6 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
android:text="@string/calculation_text"
android:textAllCaps="false"
android:layout_marginTop="32dp"
android:padding="8dp"
android:layout_below="@+id/to_spinner"
android:layout_centerHorizontal="true"
android:textColor="@color/primary_text"/>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/calculation_button"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/unit_result"
android:textSize="16sp"
android:padding="16dp"
android:textColor="@color/primary_text"
android:textStyle="bold"/>
<TextView
android:id="@+id/convert_result"
android:layout_height="match_parent"
android:layout_width="0dp"
android:textColor="@color/primary_text"
android:text="@string/no_text"
android:padding="16dp"
android:layout_weight="1"
android:background="@drawable/bottom_border"/>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</LinearLayout>
String.xml
<string-array name="length_units">
<item id="l_inches">Inches</item>
<item>Feet</item>
<item>Yards</item>
<item>Miles</item>
<item>Millimeters</item>
<item>Centimeters</item>
<item>Meters</item>
<item>Kilometers</item>
</string-array>
Page 7 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- Demonstrates using a relative layout to create a form -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/one"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignParentRight="true"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/two"
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/one"
android:layout_alignTop="@id/one"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/three"
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/two"
android:layout_alignTop="@id/two"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px"
android:padding="0px"/>
<Button android:id="@+id/four"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignParentRight="true"
android:layout_marginLeft="5px"
android:layout_below="@id/one"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/five"
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/four"
android:layout_alignTop="@id/four"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/six"
Page 8 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/five"
android:layout_alignTop="@id/five"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/seven"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignParentRight="true"
android:layout_marginLeft="5px"
android:layout_below="@id/four"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/eight"
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/seven"
android:layout_alignTop="@id/seven"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<Button android:id="@+id/nine"
android:layout_width="100px"
android:layout_height="100px"
android:layout_toLeftOf="@id/eight"
android:layout_alignTop="@id/eight"
android:layout_marginLeft="5px"
android:text=" "
android:textSize="70px" />
<TextView android:id="@+id/dialogue"
android:layout_width="fill_parent"
android:layout_below="@id/nine"
android:layout_height="wrap_content"
android:text="Click a button to start"
android:gravity="center_horizontal"
android:layout_marginTop="20px"
android:textSize="20px"/>
</RelativeLayout>
Page 9 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
Output:-
Page 10 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
2. Design and develop an mobile app for smart phones currency converter.
activity_main.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:background="#ff8899"
tools:context=".MainActivity" >
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/from_currency"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="@string/from_currency" />
<Spinner
android:id="@+id/fromcurrency_spin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/to_currency"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="@string/to_currency" />
<Spinner
android:id="@+id/tocurrency_spin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Page 11 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
/>
</LinearLayout>
<EditText
android:id="@+id/txt_rate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/txt_rate"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txt_fromamount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/txt_fromamount"
android:inputType="numberDecimal" />
<Button
android:id="@+id/bt_show"
android:background="@drawable/bt_style"
android:text="@string/bt_label"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:onClick="showResult"
/>
</LinearLayout>
spinner_style.xml
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
/>
bt_style.xml
Page 12 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ffffff"
android:endColor="#992211"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
MainActivity.java
package com.example.currencyconverter;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
Page 13 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
@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;
}
}
//This method will be invoked to setup data of the spinner views
//to show lists of currency types for selection
public void setUpSpinnerData(){
Spinner spFrom=(Spinner)findViewById(R.id.fromcurrency_spin);
Spinner spTo=(Spinner)findViewById(R.id.tocurrency_spin);
String[]
currencyList={"AUD","CAD","CHF","EUR","GBP","JPY","NZD","KHR","USD","CNY","THB","IN
R"};
ArrayAdapter<String> afrom=new ArrayAdapter<String>(this,R.layout.spinner_style,currencyList);
spFrom.setAdapter(afrom);
spFrom.setOnItemSelectedListener(new ItemSelectedFrom());
ArrayAdapter<String> ato=new ArrayAdapter<String>(this,R.layout.spinner_style,currencyList);
spTo.setAdapter(ato);
spTo.setOnItemSelectedListener(new ItemSelectedTo());
}
public void onItemSelected(AdapterView<?> av, View view, int position, long id){
TextView sel=(TextView)view;
String from=sel.getText().toString();
fromCurrency=from; //capture the currency of the From side
EditText txtfrom=(EditText)findViewById(R.id.txt_fromamount);
txtfrom.setHint("Enter "+fromCurrency+" amount");
}
}
Page 14 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
}
public void onItemSelected(AdapterView<?> av, View view, int position, long id){
TextView sel=(TextView)view;
String to=sel.getText().toString();
toCurrency=to; //capture the currency of the To side
}
}
}
else{
//create intent, place data in it and start the ConversionTable activity
Intent intent=new Intent(this, ConversionTable.class);
intent.putExtra("fromCurrency", fromCurrency);
intent.putExtra("toCurrency", toCurrency);
intent.putExtra("Rate", Double.valueOf(txtRate.getText().toString()));
intent.putExtra("fromAmount", Double.valueOf(txtAmount.getText().toString()));
startActivity(intent);
}
}
activity_conversion_tabl.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
Page 15 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".ConversionTable" >
<ListView
android:id="@+id/conversion_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
listlayout.xml
<ImageView
android:id="@+id/icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:padding="5sp"
android:contentDescription="countryicon"
/>
<TextView
android:id="@+id/currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10sp"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/label_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10sp"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold" >
Page 16 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
</TextView>
</LinearLayout>
ListAdapterModel.java
package com.example.currencyconverter;
import java.text.DecimalFormat;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public ListAdapterModel(Context context, int vg,String[] clist, Double[] alist, String to){
super(context,vg, clist);
this.context=context;
groupid=vg;
this.clist=clist;
this.to=to;
this.alist=alist;
}
public View getView(int position, View convertView, ViewGroup parent) {
Page 17 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
return(imageIds[pos]);
Page 18 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
Output:-
Page 19 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
3.Design and develop an Mobile App game for smart phones The Tic Tac Toe using Android
TicTacToe.java:
package com.games.tictactoe;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
int c[][];
int i, j, k = 0;
Button b[][];
TextView textView;
AI ai;
Page 20 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
private class AI {
public void takeTurn() {
Page 21 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
if(c[1][1]==2 &&
((c[1][2]==0 && c[1][3]==0) ||
(c[2][2]==0 && c[3][3]==0) ||
(c[2][1]==0 && c[3][1]==0))) {
markSquare(1,1);
} else if (c[1][2]==2 &&
((c[2][2]==0 && c[3][2]==0) ||
(c[1][1]==0 && c[1][3]==0))) {
markSquare(1,2);
} else if(c[1][3]==2 &&
((c[1][1]==0 && c[1][2]==0) ||
(c[3][1]==0 && c[2][2]==0) ||
(c[2][3]==0 && c[3][3]==0))) {
markSquare(1,3);
} else if(c[2][1]==2 &&
((c[2][2]==0 && c[2][3]==0) ||
(c[1][1]==0 && c[3][1]==0))){
markSquare(2,1);
} else if(c[2][2]==2 &&
((c[1][1]==0 && c[3][3]==0) ||
(c[1][2]==0 && c[3][2]==0) ||
(c[3][1]==0 && c[1][3]==0) ||
(c[2][1]==0 && c[2][3]==0))) {
markSquare(2,2);
} else if(c[2][3]==2 &&
((c[2][1]==0 && c[2][2]==0) ||
(c[1][3]==0 && c[3][3]==0))) {
markSquare(2,3);
} else if(c[3][1]==2 &&
((c[1][1]==0 && c[2][1]==0) ||
(c[3][2]==0 && c[3][3]==0) ||
(c[2][2]==0 && c[1][3]==0))){
markSquare(3,1);
} else if(c[3][2]==2 &&
((c[1][2]==0 && c[2][2]==0) ||
(c[3][1]==0 && c[3][3]==0))) {
markSquare(3,2);
}else if( c[3][3]==2 &&
((c[1][1]==0 && c[2][2]==0) ||
(c[1][3]==0 && c[2][3]==0) ||
(c[3][1]==0 && c[3][2]==0))) {
markSquare(3,3);
} else {
Random rand = new Random();
int a = rand.nextInt(4);
int b = rand.nextInt(4);
while(a==0 || b==0 || c[a][b]!=2) {
a = rand.nextInt(4);
b = rand.nextInt(4);
}
markSquare(a,b);
}
}
Page 22 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
return gameOver;
}
}
Page 23 of 24
M.TECH(CSE)-II SEMESTER MOBILE APPLICATION DEVELOPMENT LAB
Output:-
Page 24 of 24