Skip to content

Commit 0f4bfe7

Browse files
committed
update README
Projeto desenvolvido em Java no android studio
1 parent ea993e6 commit 0f4bfe7

33 files changed

Lines changed: 1215 additions & 0 deletions

Calculadora/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx

Calculadora/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Calculadora/app/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 30
5+
buildToolsVersion "30.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.calculadora.calculadora"
9+
minSdkVersion 17
10+
targetSdkVersion 30
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: "libs", include: ["*.jar"])
27+
implementation 'androidx.appcompat:appcompat:1.1.0'
28+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
29+
testImplementation 'junit:junit:4.12'
30+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
31+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
32+
33+
}

Calculadora/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.calculadora.calculadora;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.calculadora.calculadora", appContext.getPackageName());
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.calculadora.calculadora">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
package com.calculadora.calculadora;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.TextView;
9+
import android.widget.Toast;
10+
11+
12+
public class MainActivity extends AppCompatActivity {
13+
14+
Button BtnZero, BtnUm, BtnDois, BtnTres, BtnQuatro,
15+
BtnCinco, BtnSeis, BtnSete, BtnOito, BtnNove,
16+
BtnSoma, BtnSubtracao, BtnMultiplicacao, BtnDivisao,
17+
BtnPonto, BtnIgual, BtnLimpar, BtnApagar;
18+
19+
TextView display1, display2, display3;
20+
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) { //criação da tela
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_main);
26+
27+
//declarando os botões
28+
29+
display1 = (TextView) findViewById(R.id.mainDisplay1);
30+
display2 = (TextView) findViewById(R.id.mainDisplay2);
31+
display3 = (TextView) findViewById(R.id.mainDisplay3);
32+
33+
34+
BtnZero = findViewById(R.id.mainBtnZero);
35+
BtnUm = (Button) findViewById(R.id.mainBtnUm);
36+
BtnDois = (Button) findViewById(R.id.mainBtnDois);
37+
BtnTres = (Button) findViewById(R.id.mainBtnTres);
38+
BtnQuatro = (Button) findViewById(R.id.mainBtnQuatro);
39+
BtnCinco = (Button) findViewById(R.id.mainBtnCinco);
40+
BtnSeis = (Button) findViewById(R.id.mainBtnSeis);
41+
BtnSete = (Button) findViewById(R.id.mainBtnSete);
42+
BtnOito = (Button) findViewById(R.id.mainBtnOito);
43+
BtnNove = (Button) findViewById(R.id.mainBtnNove);
44+
45+
BtnSoma = (Button) findViewById(R.id.mainBtnSoma);
46+
BtnSubtracao = (Button) findViewById(R.id.mainBtnSubtracao);
47+
BtnMultiplicacao = (Button) findViewById(R.id.mainBtnMultiplicacao);
48+
BtnDivisao = (Button) findViewById(R.id.mainBtnDivisao);
49+
50+
BtnPonto = (Button) findViewById(R.id.mainBtnPonto);
51+
BtnIgual = (Button) findViewById(R.id.mainBtnIgual);
52+
53+
BtnApagar = (Button) findViewById(R.id.mainBtnApagar);
54+
BtnLimpar = (Button) findViewById(R.id.mainBtnLimpar);
55+
}
56+
57+
/*-instanciando o click do botão, se for diferente de falso, o botão precionado irá setar o display 1 ou 2(depende de qual display ja esta setado)
58+
e será mostrado no display o numero que foi clicado nesse caso do 0 até 9 -*/
59+
60+
61+
boolean bool = false;
62+
public void BtnZero (View v){
63+
if (!bool) {
64+
String strZero = display1.getText().toString();
65+
display1.setText(strZero + "0");
66+
} else {
67+
String strZero = display2.getText().toString();
68+
display2.setText(strZero + "0");
69+
}
70+
}
71+
72+
public void BtnUm (View v){
73+
if (!bool) {
74+
String strUm = display1.getText().toString();
75+
display1.setText(strUm + "1");
76+
} else {
77+
String strUm = display2.getText().toString();
78+
display2.setText(strUm + "1");
79+
}
80+
}
81+
82+
public void BtnDois (View v){
83+
if (!bool) {
84+
String strDois = display1.getText().toString();
85+
display1.setText(strDois + "2");
86+
} else {
87+
String strDois = display2.getText().toString();
88+
display2.setText(strDois + "2");
89+
}
90+
}
91+
92+
public void BtnTres (View v){
93+
if (!bool) {
94+
String strTres = display1.getText().toString();
95+
display1.setText(strTres + "3");
96+
} else {
97+
String strTres = display2.getText().toString();
98+
display2.setText(strTres + "3");
99+
}
100+
}
101+
102+
public void BtnQuatro (View v){
103+
if (!bool) {
104+
String strQuatro = display1.getText().toString();
105+
display1.setText(strQuatro + "4");
106+
} else {
107+
String strQuatro = display2.getText().toString();
108+
display2.setText(strQuatro + "4");
109+
}
110+
}
111+
112+
public void BtnCinco (View v){
113+
if (!bool) {
114+
String strCinco = display1.getText().toString();
115+
display1.setText(strCinco + "5");
116+
} else {
117+
String strCinco = display2.getText().toString();
118+
display2.setText(strCinco + "5");
119+
}
120+
}
121+
122+
public void BtnSeis (View v){
123+
if (!bool) {
124+
String strSeis = display1.getText().toString();
125+
display1.setText(strSeis + "6");
126+
} else {
127+
String strSeis = display2.getText().toString();
128+
display2.setText(strSeis + "6");
129+
}
130+
}
131+
132+
public void BtnSete (View v){
133+
if (!bool) {
134+
String strSete = display1.getText().toString();
135+
display1.setText(strSete + "7");
136+
} else {
137+
String strSete = display2.getText().toString();
138+
display2.setText(strSete + "7");
139+
}
140+
}
141+
142+
public void BtnOito (View v){
143+
if (!bool) {
144+
String strOito = display1.getText().toString();
145+
display1.setText(strOito + "8");
146+
} else {
147+
String strOito = display2.getText().toString();
148+
display2.setText(strOito + "8");
149+
}
150+
}
151+
152+
public void BtnNove (View v){
153+
if (!bool) {
154+
String strNove = display1.getText().toString();
155+
display1.setText(strNove + "9");
156+
} else {
157+
String strNove = display2.getText().toString();
158+
display2.setText(strNove + "9");
159+
}
160+
}
161+
162+
/*-instanciando o click do botão, caso for verdadeiro o botão é chamado e exibe os operadores matematicos "+,-,*,/" no display3 -*/
163+
164+
public void BtnSoma (View v){
165+
bool = true;
166+
display3.setText("+");
167+
}
168+
169+
public void BtnSubtracao (View v){
170+
bool = true;
171+
display3.setText("-");
172+
}
173+
174+
public void BtnMultiplicacao (View v){
175+
bool = true;
176+
display3.setText("x");
177+
}
178+
179+
public void BtnDivisao (View v){
180+
bool = true;
181+
display3.setText("/");
182+
}
183+
/*-instanciando o click do botão PONTO(.) chama a aplicação no display que estiver instanciado display 1 ou 2,
184+
deixando o usuario colcar somente 1 ponto em cada display e exibe uma mensagem na tela de que o ponto ja foi adicionado-*/
185+
public void BtnPonto (View v){
186+
if (!bool) {
187+
String strPonto = display1.getText().toString();
188+
if (strPonto.contains(".")) {
189+
Toast.makeText(MainActivity.this, "Ja existe Ponto", Toast.LENGTH_LONG).show();
190+
} else {
191+
String str = display1.getText().toString();
192+
display1.setText(str + ".");
193+
}
194+
} else {
195+
String strPonto = display2.getText().toString();
196+
if (strPonto.contains(".")) {
197+
Toast.makeText(MainActivity.this, "Ja existe Ponto", Toast.LENGTH_LONG).show();
198+
} else {
199+
String str = display2.getText().toString();
200+
display2.setText(str + ".");
201+
}
202+
}
203+
}
204+
/*-faz a chamada do botão APAGAR no display que está selecionado, ele apaga a string uma a uma até mesmo o ponto adicionado,-*/
205+
public void BtnApagar (View v){
206+
if (!bool) {
207+
String str_display1 = display1.getText().toString();
208+
209+
if (str_display1.length() > 1) {
210+
String str_Apagar = str_display1.substring(0, str_display1.length() - 1);
211+
display1.setText(str_Apagar);
212+
} else {
213+
display1.setText("");
214+
}
215+
} else {
216+
String str_display2 = display2.getText().toString();
217+
if (str_display2.length() > 1) {
218+
String str_Apagar = str_display2.substring(0, str_display2.length() - 1);
219+
display2.setText(str_Apagar);
220+
} else {
221+
display2.setText("");
222+
}
223+
}
224+
}
225+
/*-chama o botão que limpa todas as telas displays 1,2 e 3-*/
226+
public void BtnLimpar (View v){
227+
bool = false;
228+
display1.setText("");
229+
display2.setText("");
230+
display3.setText("");
231+
}
232+
/*- faz a chamada do botão igual que faz o calculo, capturando as strings dos displays 1 e 2 e transformando em inteiros,
233+
o display 3 e verificado qual operador foi selecionado, por exemplo,
234+
se foi selecionado o botão de + ele irá capturar os dados em string nos displays 1 e 2
235+
e converte-los em inteiros, o resultado é exibido em forma de TOAST longo na tela -*/
236+
public void BtnIgual (View v){
237+
String str_display1 = display1.getText().toString();
238+
String str_display2 = display2.getText().toString();
239+
String str_display3 = display3.getText().toString();
240+
241+
if (display2.length() > 0) {
242+
int txt1 = Integer.parseInt(str_display1);
243+
int txt2 = Integer.parseInt(str_display2);
244+
if (str_display3.contains("+")) {
245+
int resultado = txt1 + txt2;
246+
String str = Integer.toString(resultado);
247+
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
248+
249+
} else if (str_display3.contains("-")) {
250+
int resultado = txt1 - txt2;
251+
String str = Integer.toString(resultado);
252+
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
253+
254+
} else if (str_display3.contains("x")) {
255+
int resultado = txt1 * txt2;
256+
String str = Integer.toString(resultado);
257+
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
258+
259+
} else if (str_display3.contains("/")) {
260+
int resultado = txt1 / txt2;
261+
String str = Integer.toString(resultado);
262+
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
263+
} else {
264+
Toast.makeText(MainActivity.this, "Operação invádida.", Toast.LENGTH_SHORT).show();
265+
}
266+
}
267+
}
268+
}
269+
270+

0 commit comments

Comments
 (0)