diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 681f41a..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - -
- - - - xmlns:android - - ^$ - - - -
-
- - - - xmlns:.* - - ^$ - - - BY_NAME - -
-
- - - - .*:id - - http://schemas.android.com/apk/res/android - - - -
-
- - - - .*:name - - http://schemas.android.com/apk/res/android - - - -
-
- - - - name - - ^$ - - - -
-
- - - - style - - ^$ - - - -
-
- - - - .* - - ^$ - - - BY_NAME - -
-
- - - - .* - - http://schemas.android.com/apk/res/android - - - ANDROID_ATTRIBUTE_ORDER - -
-
- - - - .* - - .* - - - BY_NAME - -
-
-
-
-
-
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 37a7509..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/exuberant/calci/HomeActivity.java b/app/src/main/java/com/exuberant/calci/HomeActivity.java index c0f9ac0..014910c 100644 --- a/app/src/main/java/com/exuberant/calci/HomeActivity.java +++ b/app/src/main/java/com/exuberant/calci/HomeActivity.java @@ -1,23 +1,29 @@ package com.exuberant.calci; import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; import android.view.View; import android.widget.TextView; -import android.widget.Toast; - import com.google.android.material.button.MaterialButton; public class HomeActivity extends AppCompatActivity implements View.OnClickListener { private String currentNumber = "", totalCalculation = ""; + private char operator ; + private double firstOperand; + private double secondOperand; private TextView totalCalculationTextView, currentAnswerTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); + + initializeViews(); + + } + + private void initializeViews() { findViewById(R.id.btn_zero).setOnClickListener(this); findViewById(R.id.btn_one).setOnClickListener(this); findViewById(R.id.btn_two).setOnClickListener(this); @@ -62,8 +68,11 @@ public void onClick(View view) { //Handle calculation case R.id.btn_equals: + firstOperand = Double.valueOf(totalCalculation.substring(0,totalCalculation.length()-1)); + secondOperand = Double.valueOf(currentNumber); + operator = totalCalculation.charAt(totalCalculation.length()-1); totalCalculation += currentNumber; - calculateAnswer(); + calculateAnswer(firstOperand, secondOperand, operator); break; //Handle other numerical button clicks @@ -93,20 +102,37 @@ private double add(double a, double b){ } private double sub(double a, double b){ - return a + b; + return a - b; } private double mul(double a, double b){ - return a + b; + return a * b; } private double div(double a, double b){ - return a + b; + return a / b; } - private void calculateAnswer(){ + private void calculateAnswer(Double firstOperand, Double secondOperand, char operator){ //Use totalCalculation string to get final answer and display it double answer = 0.0; + if(operator == '+') + { + answer = add(firstOperand, secondOperand); + } + else if(operator == '-') + { + answer = sub(firstOperand, secondOperand); + } + else if (operator == '/') + { + answer = div(firstOperand, secondOperand); + } + else + { + answer = mul(firstOperand, secondOperand); + } + currentNumber = String.valueOf(answer); updateDisplay(); } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/content_answer_view.xml b/app/src/main/res/layout/content_answer_view.xml index 970907e..cfeceec 100644 --- a/app/src/main/res/layout/content_answer_view.xml +++ b/app/src/main/res/layout/content_answer_view.xml @@ -11,7 +11,7 @@ android:layout_marginTop="16dp" android:gravity="end" android:textSize="24sp" - android:text="Total Calculation" + android:text="@string/total_calculation" android:textColor="#757575" android:layout_width="match_parent" android:layout_height="wrap_content"/> @@ -24,7 +24,7 @@ android:layout_marginEnd="16dp" android:gravity="end" android:textSize="32sp" - android:text="Current Calculation" + android:text="@string/current_calculation" android:textColor="#757575" android:layout_width="match_parent" android:layout_height="wrap_content"/> diff --git a/app/src/main/res/layout/content_number_board.xml b/app/src/main/res/layout/content_number_board.xml index d98056e..e6a81d6 100644 --- a/app/src/main/res/layout/content_number_board.xml +++ b/app/src/main/res/layout/content_number_board.xml @@ -8,7 +8,7 @@ + Calci + Celkový výpočet + Aktuální výpočet + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml new file mode 100644 index 0000000..062ae54 --- /dev/null +++ b/app/src/main/res/values-de/strings.xml @@ -0,0 +1,24 @@ + + Calci + Gesamtberechnung + Aktuelle Berechnung + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml new file mode 100644 index 0000000..0cfdcc8 --- /dev/null +++ b/app/src/main/res/values-es/strings.xml @@ -0,0 +1,24 @@ + + Calci + Cálculo total + Cálculo actual + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml new file mode 100644 index 0000000..e9bd5aa --- /dev/null +++ b/app/src/main/res/values-fr/strings.xml @@ -0,0 +1,24 @@ + + Calci + Calcul total + Calcul du courant + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml new file mode 100644 index 0000000..8342c86 --- /dev/null +++ b/app/src/main/res/values-id/strings.xml @@ -0,0 +1,24 @@ + + Calci + Total Hitung + Hitungan Saat Ini + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml new file mode 100644 index 0000000..b682571 --- /dev/null +++ b/app/src/main/res/values-it/strings.xml @@ -0,0 +1,6 @@ + + + Calci + Calcolo corrente + Risultato + \ No newline at end of file diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml new file mode 100644 index 0000000..0edc421 --- /dev/null +++ b/app/src/main/res/values-ja/strings.xml @@ -0,0 +1,24 @@ + + Calci + 合計計算 + 現在の計算 + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml new file mode 100644 index 0000000..22eab14 --- /dev/null +++ b/app/src/main/res/values-nl/strings.xml @@ -0,0 +1,24 @@ + + Calci + Totale berekening + Huidige berekening + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml new file mode 100644 index 0000000..dce1940 --- /dev/null +++ b/app/src/main/res/values-pl/strings.xml @@ -0,0 +1,24 @@ + + Calci + Łączna kalkulacja + Obecne obliczenia + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml new file mode 100644 index 0000000..4fcddfb --- /dev/null +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -0,0 +1,24 @@ + + Calci + Calcular Total + Cálculo atual + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml new file mode 100644 index 0000000..f8b70e8 --- /dev/null +++ b/app/src/main/res/values-ru/strings.xml @@ -0,0 +1,24 @@ + + Calci + Общий расчет + Текущий расчет + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml new file mode 100644 index 0000000..1808af5 --- /dev/null +++ b/app/src/main/res/values-sk/strings.xml @@ -0,0 +1,24 @@ + + Calci + Celkový výpočet + Aktuálny výpočet + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml new file mode 100644 index 0000000..2337065 --- /dev/null +++ b/app/src/main/res/values-sv/strings.xml @@ -0,0 +1,24 @@ + + Calci + Total beräkning + Aktuell beräkning + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml new file mode 100644 index 0000000..7855608 --- /dev/null +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -0,0 +1,24 @@ + + Calci + 总计计算 + 当前计算 + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c3a285..a77dcef 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,24 @@ Calci + Total calculation + Current calculation + C + ( + ) + / + 7 + 8 + 9 + X + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + =