






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Moble app development lab assginment java code in android studio java+ xml code lab 5
Typology: Assignments
1 / 10
This page cannot be seen from the preview
Don't miss anything!







<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=".MainActivity">
android:paddingBottom="15dp" android:text="FALL COURSE REGISTRATION" android:textColor="#FF0000" android:textSize="15dp" />
android:textColor="#FF0000" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
package com.example.real_calculator; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { int a= 0 ; int b= 0 ; int number_counter= 1 ; String operator=""; String input=""; int result= 0 ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout. activity_main ); TextView display=findViewById(R.id. textView ); Button one=findViewById(R.id. button14 ); Button two=findViewById(R.id. button13 ); Button three=findViewById(R.id. button12 ); Button four=findViewById(R.id. button17 ); Button five=findViewById(R.id. button16 ); Button six=findViewById(R.id. button15 ); Button seven=findViewById(R.id. button20 ); Button eight=findViewById(R.id. button19 ); Button nine=findViewById(R.id. button18 ); Button minus=findViewById(R.id. button23 ); Button zero=findViewById(R.id. button22 ); Button plus=findViewById(R.id. button21 ); Button multiply=findViewById(R.id. button24 ); Button divide=findViewById(R.id. button25 );
if(number_counter== 1 ) a =a* 10 + 5 ; else b=b* 10 + 5 ; } }); six.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"6"; display.setText(input); if(number_counter== 1 ) a =a* 10 + 6 ; else b=b* 10 + 6 ; } }); seven.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"7"; display.setText(input); if(number_counter== 1 ) a =a* 10 + 7 ; else b=b* 10 + 7 ; } }); eight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input = input + "8"; display.setText(input); if (number_counter == 1 ) a = a * 10 + 8 ; else b = b * 10 + 8 ; } }); nine.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"9"; display.setText(input); if(number_counter== 1 ) a =a* 10 + 9 ; else b=b* 10 + 9 ; } }); minus.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) { input=input+"-"; display.setText(input); operator="-"; number_counter= 2 ; } }); zero.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input = input + "0"; display.setText(input); if(number_counter== 1 ) a =a* 10 + 0 ; else b=b* 10 + 0 ; } }); plus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"+"; display.setText(input); operator="+"; number_counter= 2 ; } }); multiply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"x"; display.setText(input); operator="*"; number_counter= 2 ; } }); divide.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { input=input+"/"; display.setText(input); operator="/"; number_counter= 2 ; } }); equal.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(operator.equals("+")) {