Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Android Calculator App Java Code and XML Layout, Schemes and Mind Maps of Mobile Computing

The Java code and XML layout for an Android calculator app. The code sets up the user interface with buttons for numbers and mathematical operations, and handles user input to perform calculations. The XML layout defines the layout of the app's user interface, including the position and size of each button.

Typology: Schemes and Mind Maps

2019/2020

Uploaded on 11/16/2022

dna-barath
dna-barath 🇮🇳

5 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
VIT-AP UNIVERSITY, ANDHRA PRADESH
Lab Sheet 3: Calculator
Academic year: 2021-2022
Branch/Class:B.Tech
Semester: Fall
Date: 17-09-2021
Faculty Name: Dr.N.Anupama
School: SCOPE
NAME: Barath kumar v
REGNO: 20BCR7107
MainActivity CODE:
package com.example.calc; import
androidx.appcompat.app.AppCompatActiv
ity; import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button button0, button1, button2, button3, button4,
button5, button6, button7, button8, button9,
buttonAdd, buttonSub, buttonDivision, buttonMul,
button10, buttonC, buttonEqual; EditText
crunchifyEditText; float mValueOne, mValueTwo;
boolean crunchifyAddition, mSubtract, crunchifyMultiplication,
crunchifyDivision;
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Android Calculator App Java Code and XML Layout and more Schemes and Mind Maps Mobile Computing in PDF only on Docsity!

VIT-AP UNIVERSITY, ANDHRA PRADESH

Lab Sheet 3: Calculator Academic year: 2021- 2022 Branch/Class:B.Tech Semester: Fall Date: 17- 09 - 2021 Faculty Name: Dr.N.Anupama School: SCOPE NAME: Barath kumar v REGNO: 20BCR MainActivity CODE: package com.example.calc; import androidx.appcompat.app.AppCompatActiv ity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity { Button button0, button1, button2, button3, button4, button5, button6, button7, button8, button9, buttonAdd, buttonSub, buttonDivision, buttonMul, button10, buttonC, buttonEqual; EditText crunchifyEditText; float mValueOne, mValueTwo; boolean crunchifyAddition, mSubtract, crunchifyMultiplication, crunchifyDivision;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button0 = (Button) findViewById(R.id.button0); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); button4 = (Button) findViewById(R.id.button4); button5 = (Button) findViewById(R.id.button5); button6 = (Button) findViewById(R.id.button6); button7 = (Button) findViewById(R.id.button7); button8 = (Button) findViewById(R.id.button8); button9 = (Button) findViewById(R.id.button9); button10 = (Button) findViewById(R.id.button10); buttonAdd = (Button) findViewById(R.id.buttonadd); buttonSub = (Button) findViewById(R.id.buttonsub); buttonMul = (Button) findViewById(R.id.buttonmul); buttonDivision = (Button) findViewById(R.id.buttondiv); buttonC = (Button) findViewById(R.id.buttonC); buttonEqual = (Button) findViewById(R.id.buttoneql); crunchifyEditText = (EditText) findViewById(R.id.edt1);

crunchifyEditText.setText(crunchifyEditText.getText() + "4"); } }); button5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "5"); } }); button6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "6"); } }); button7.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "7"); } }); button8.setOnClickListener(new View.OnClickListener() {

@Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "8"); } }); button9.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "9"); } }); button0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(cru nchifyEditText.getText() + "0"); } }); buttonAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (crunchifyEditText == null) { crunchifyEditText.setText(""); } else {

public void onClick(View v) { mValueOne = Float.parseFloat(crunchifyEditText.getText() + ""); crunchifyDivision = true; crunchifyEditText.setText(null); } }); buttonEqual.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mValueTwo = Float.parseFloat(crunchifyEditText.getText() + ""); if (crunchifyAddition == true) { crunchifyEditText.setText(mValueOne + mValueTwo + ""); crunchifyAddition = false; } if (mSubtract == true) { crunchifyEditText.setText(mValueOne - mValueTwo + ""); mSubtract = false; } if (crunchifyMultiplication == true) { crunchifyEditText.setText(mValueOne * mValueTwo + ""); crunchifyMultiplication = false; } if (crunchifyDivision == true) { crunchifyEditText.setText(mValueOne / mValueTwo + ""); crunchifyDivision = false; }

buttonC.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(""); } }); button10.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { crunchifyEditText.setText(crunchifyEditText.getText() + "."); } }); } }

Xml CODE:

android:layout_width="wrap_cont ent" android:layout_height="wrap_co ntent" android:layout_alignTop="@+id/ button1" android:layout_toStartOf="@+id/ button3" android:layout_toLeftOf="@+id/b utton3" android:backgroundTint="#8F0E 0E" android:text="2" />