MAD - RECORD 1-12 Program

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Greatest Among Three Numbers

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Greatest Among Three"
android:gravity="center"
android:textSize="25sp"/>
<EditText
android:id="@+id/i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:layout_gravity="center"
android:inputType="number" />
<EditText
android:id="@+id/i2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:layout_gravity="center"
android:inputType="number" />
<EditText
android:id="@+id/i3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:layout_gravity="center"
android:inputType="number" />
<Button
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Max"
android:onClick="findMax"/>
<TextView
android:id="@+id/outputTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>

1
MainActivity.java :

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText i1,i2,i3;
TextView opTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
i1 = findViewById(R.id.i1);
i2 = findViewById(R.id.i2);
i3 = findViewById(R.id.i3);
opTxt = findViewById(R.id.outputTxt);
}
public void findMax(View v)
{
int x,y,z,max;
x = Integer.parseInt(i1.getText().toString());
y = Integer.parseInt(i2.getText().toString());
z = Integer.parseInt(i3.getText().toString());
max = Math.max(x,y);
max = Math.max(max,z);
opTxt.setText("Max: "+max+"");
}
}

2
Output :

3
PERSONAL DETAILS

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PERSONAL DETAILS"
android:gravity="center"
android:textSize="35sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : Steephen \nAge : 20 \nGender : Male\nMobile No. : 6382585776\nPlace : Chennai"
android:textSize="30sp"/>
</LinearLayout>

4
Output :

5
RADIO BUTTON

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RADIO BUTTON"
android:gravity="center"
android:textSize="35sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\nWhat is your gender identity ?"
android:textSize="25sp"/>
<RadioGroup
android:layout_width="match_parent"
android:id="@+id/rGroup"
android:layout_height="match_parent" >
<RadioButton
android:id="@+id/maleRadioBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/femaleRadioBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female" />
<Button
android:onClick="submitClick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SUBMIT" />
</RadioGroup>
</LinearLayout>

6
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RadioGroup rG;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rG = findViewById(R.id.rGroup);
}
public void submitClick(View v)
{
int selectedId = rG.getCheckedRadioButtonId();
RadioButton rB = findViewById(selectedId);
Toast.makeText(this,"You are a "+rB.getText().toString()+"",Toast.LENGTH_SHORT).show();
}
}

7
Output :

8
IMAGE BUTTON

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IMAGE BUTTON"
android:gravity="center"
android:textSize="35sp"/>

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/dog"
android:layout_weight="5"
android:onClick="imageClick"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Click the image above"
android:textSize="20sp"
android:layout_weight="5"
android:layout_gravity="center"/>
</LinearLayout>

9
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void imageClick(View v)
{
Toast.makeText(this,"Dog : Woof! Woof!",Toast.LENGTH_SHORT).show();
}
}

10
Output :

11
ALERT DIALOG BOX

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ALERT DIALOG BOX"
android:gravity="center"
android:textSize="35sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Dialog"
android:onClick="buttonPressed"/>
</LinearLayout>

12
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonPressed(View v)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Dialog").setMessage("This is a basic dialog box. ");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}

13
Output :

14
LAYOUT MANAGERS

activity_main.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:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LAYOUT MANAGERS"
android:gravity="center"
android:textSize="35sp"/>
</LinearLayout>

15
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayout = findViewById(R.id.linearLayout);
Button button1 = new Button(this);
button1.setText("Button 1");
Button button2 = new Button(this);
button2.setText("Button 2");
linearLayout.addView(button1);
linearLayout.addView(button2);
}
}

16
Output :

17
AUDIO MODE

AndroidManifest.xml :

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- add here-->


<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AudioModeApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

18
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"
tools:context=".MainActivity"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AUDIO MODE"
android:textSize="20sp"
android:gravity="center"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="NORMAL"
android:onClick="normalMode"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SILENT"
android:onClick="silentMode"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VIBRATE"
android:onClick="vibrateMode"/>
</LinearLayout>

19
MainActivity.java :

package com.example.audiomodeapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
AudioManager audioManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
}
public void normalMode(View view)
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Toast.makeText(this,"Normal mode activated",Toast.LENGTH_SHORT).show();
}
public void silentMode(View view)
{
// audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); Note:silent mode won't work.
Toast.makeText(this,"Silent mode activated",Toast.LENGTH_SHORT).show();}
public void vibrateMode(View view)
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Toast.makeText(this,"Vibrate mode activated",Toast.LENGTH_SHORT).show();
}
}

20
Output :

21
SMS

AndroidManifest.xml :

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!--add here -->


<uses-permission android:name="android.permission.SEND_SMS"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SmsApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

22
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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MESSAGE APP"
android:gravity="center"
android:textSize="20sp"/>

<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:hint="Phone Number"/>

<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Message" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEND"
android:onClick="sendSMS"/>
</LinearLayout>

23
MainActivity.java :

package com.example.smsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText phoneNumber,msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumber = findViewById(R.id.phoneNumber);
msg = findViewById(R.id.msg);
}

public void sendSMS(View view) {


String number = phoneNumber.getText().toString();
String message = msg.getText().toString();

SmsManager smsManager = SmsManager.getDefault();


smsManager.sendTextMessage(number, null, message, null, null);
Toast.makeText(getApplicationContext(), "Message Sent", Toast.LENGTH_LONG).show();
}

24
Output :

25
SEND EMAIL

AndroidManifest.xml :

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

26
activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEND EMAIL"
android:gravity="center"
android:textSize="35sp"/>

<EditText
android:id="@+id/emailText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="Mail to :"/>

<EditText
android:id="@+id/subjectText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Subject"/>

<EditText
android:id="@+id/bodyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:hint="Body"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEND"
android:onClick="sendMail"/>

</LinearLayout>

27
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


EditText mailToText,subjectText,bodyText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mailToText = findViewById(R.id.emailText);
subjectText = findViewById(R.id.subjectText);
bodyText = findViewById(R.id.bodyText);
}
public void sendMail(View v)
{
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{mailToText.getText().toString()});
intent.putExtra(Intent.EXTRA_SUBJECT, subjectText.getText().toString());
intent.putExtra(Intent.EXTRA_TEXT, bodyText.getText().toString());
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
}

28
Output :

29
MOBILE CALL

AndroidManifest.xml :

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!--add here-->
<uses-permission android:name="android.permission.CALL_PHONE"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

30
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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile Calls"
android:gravity="center"
android:textSize="20sp" />
<EditText
android:id="@+id/phoneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:layout_gravity="center"/>
<Button
android:id="@+id/callButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call"
android:layout_gravity="center"
android:onClick="makeCall"/>
</LinearLayout>

31
MainActivity.java :

package com.example.myapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

EditText phoneText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneText = findViewById(R.id.phoneText);
}

public void makeCall(View view)


{
String phoneNumber = phoneText.getText().toString();
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse("tel:"+phoneNumber));
startActivity(phoneIntent);
}
}

32
Output :

33
STUDENT MARK SHEET PROCESSING

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STUDENT MARK SHEET"
android:gravity="center"
android:textSize="35sp"/>
<EditText
android:id="@+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10”
android:inputType="text"
android:hint="Enter Name"/>
<EditText
android:id="@+id/madMark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberSigned"
android:hint="Mobile Development (Mark)"/>
<EditText
android:id="@+id/dmMark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberSigned"
android:hint="Data Mining (Mark)"/>
<EditText
android:id="@+id/iotMark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberSigned"
android:hint="IOT (Mark)"/>
<EditText
android:id="@+id/webMark"
android:layout_width="match_parent"
android:layout_height="wrap_content" 34
android:ems="10"
android:inputType="numberSigned"
android:hint="Web Design (Mark)"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Calculate"
android:onClick="calculate"/>
<TextView
android:id="@+id/resultText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"/>
</LinearLayout>

35
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


EditText nameTxt,sub1,sub2,sub3,sub4;
TextView resultOp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nameTxt = findViewById(R.id.nameTxt);
sub1 = findViewById(R.id.madMark);
sub2 = findViewById(R.id.dmMark);
sub3 = findViewById(R.id.iotMark);
sub4 = findViewById(R.id.webMark);
resultOp = findViewById(R.id.resultText);

}
public void calculate(View v)
{
String name = nameTxt.getText().toString();
int mark1,mark2,mark3,mark4,totalMark;
mark1 = Integer.parseInt(sub1.getText().toString());
mark2 = Integer.parseInt(sub2.getText().toString());
mark3 = Integer.parseInt(sub3.getText().toString());
mark4 = Integer.parseInt(sub4.getText().toString());
totalMark = mark1+mark2+mark3+mark4;
double percentage = (totalMark/4)*100;
resultOp.setText("\nResult :\nName : "+name+"\nTotal Marks : "+totalMark+"/400\nTotal percentage :
"+percentage+"%\n");

}
}

36
Output :

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

37
LOGIN PAGE IN DATABASE

activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN PAGE"
android:gravity="center"
android:textSize="35sp"/>

<EditText
android:id="@+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="User Name" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Password"
android:password="true"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN"
android:onClick="login"/>

</LinearLayout>

38
MainActivity.java :

package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText userNameText,passwordText;
static String crtUserName,crtPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
crtUserName = "kowshik";
crtPassword = "1122334455";
userNameText = findViewById(R.id.userName);
passwordText = findViewById(R.id.password);
}
public void login(View v)
{
String nameStr,passStr;
nameStr = userNameText.getText().toString();
passStr = passwordText.getText().toString();
if(nameStr.equals(crtUserName) && passStr.equals(crtPassword))
{
Toast.makeText(this,"Logged In",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this,"Failed",Toast.LENGTH_SHORT).show();
}
}
}

39
Output :

40

You might also like