Android Studioda arifmetik (+,-,*, /, ) amallarni bajaruvchi oddiy kalkulator yaratish


Download 322.85 Kb.
Sana19.06.2023
Hajmi322.85 Kb.
#1606603
Bog'liq
Android Studioda arifmetik , , , , amallarni bajaruvchi odd 1


O’zbekiston Respublikasi Axborot Texnologiyalari va kommunikatsiyalarni rivojlantirish Vazirligi

Muhammad Al-Xorazmiy nomidagi


Toshkent Axborot Texnologiyalari Universiteti.
Mobil ilovalarni ishlab chiqish

Labaratoriya ishi 2


Mavzu: Android Studioda arifmetik (+,-,*, /, ^) amallarni bajaruvchi oddiy kalkulator yaratish.
Bajardi: Elmurodov Eldor

Toshkent 2023




Code:
package com.example.kalkulator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements Contract.View {


TextView textView;
TextView editText;
TextView natija;
String number="";
Contract.Presenter presenter;

@Override


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.textView);
editText=findViewById(R.id.editText);
natija=findViewById(R.id.natija1);

presenter = new Presenter(this);


}

@Override


public void showNatija(String natija1) {
natija.setText(natija1);

}

@Override


public void editText(String text) {
editText.setText(text);
}

@Override


public void showPut(String string) {
textView.setText(string);

}

public void plusBtnClick(View view){



Button buttonPlus = (Button) view;
presenter.onclickPlus(number);

textView.setText(textView.getText() + number + " + ");


number = "";
editText.setText("");

}

public void btnTeng(View view){


presenter.onclickTeng(editText.getText().toString());
textView.setText("");
editText.setText("");
number = "";
}

public void buttonClikc(View view) {


Button view1= (Button) view;
if (number.length() <= 8) {
number = number.concat(view1.getText().toString());
editText.setText(number);
}
}
public String getNumber(){
return this.number;
}
}

package com.example.kalkulator;

public class Presenter implements Contract.Presenter {
Contract.View view;
int sum = 0;
public Presenter(Contract.View view) {
this.view = view;
}

@Override


public void onclick() {
view.getNumber();

}

@Override


public void onclickPlus(String number) {
sum += Integer.parseInt(number);
}

@Override


public void onclickTeng(String number) {
if (number.length() != 0) {
sum += Integer.parseInt(number);
view.showNatija("Natija: " + sum + "");
sum = 0;
}
}
}

package com.example.kalkulator;

public interface Contract {
interface View{
void showNatija(String natija);
void editText(String text);
void showPut(String string);
String getNumber();

}
interface Presenter{


void onclick();
void onclickPlus(String number1);
void onclickTeng(String number);
}
}



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:padding="20dp"
android:background="#E6D4D4">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center|right|top"
android:orientation="vertical"
android:padding="30dp">
android:id="@+id/textView"
android:hint="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_margin="10dp"/>
android:id="@+id/editText"
android:hint="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_margin="10dp"
/>
android:id="@+id/natija1"
android:hint="natija"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="30dp"
/>



android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3.2"
android:gravity="center"
android:background="#2B1C1C">

Download 322.85 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling