Created
September 12, 2018 23:36
-
-
Save thbighead/f722d36cddf90d54ae56788e2f071e62 to your computer and use it in GitHub Desktop.
Trabalho com App de descontos da feira.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package projetodesenvolvedor.usuario.app.trabalhopratico; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.RadioButton; | |
import android.widget.RadioGroup; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void calcPrice(View view) { | |
TextView edtPeso = (TextView)findViewById(R.id.edtPeso); | |
RadioGroup rdgpFruits = (RadioGroup)findViewById(R.id.rdgpFruits); | |
RadioButton selectedRdFruit = (RadioButton)findViewById(rdgpFruits.getCheckedRadioButtonId()); | |
Toast toast; | |
double valor; | |
double peso = Double.valueOf(edtPeso.getText().toString()); | |
String selectedFruitName = selectedRdFruit.getText().toString(); | |
if (selectedFruitName.compareToIgnoreCase("morango") == 0) { | |
valor = peso * (peso > 10.0 ? 4 : 5); | |
toast = Toast.makeText(this, String.valueOf(valor), Toast.LENGTH_LONG); | |
} else if (selectedFruitName.compareToIgnoreCase("maçã") == 0) { | |
valor = peso * (peso > 10.0 ? 1 : 2); | |
toast = Toast.makeText(this, String.valueOf(valor), Toast.LENGTH_LONG); | |
} else if (selectedFruitName.compareToIgnoreCase("banana") == 0) { | |
valor = peso * (peso > 10.0 ? 1.5 : 1.8); | |
toast = Toast.makeText(this, String.valueOf(valor), Toast.LENGTH_LONG); | |
} else if(selectedFruitName.compareToIgnoreCase("abacate") == 0) { | |
valor = peso * (peso > 10.0 ? 7.5 : 8); | |
toast = Toast.makeText(this, String.valueOf(valor), Toast.LENGTH_LONG); | |
} else if(selectedFruitName.compareToIgnoreCase("laranja") == 0) { | |
valor = peso * (peso > 10.0 ? 2.5 : 3.5); | |
toast = Toast.makeText(this, String.valueOf(valor), Toast.LENGTH_LONG); | |
} else { | |
toast = Toast.makeText(this, "Escolha um fruta válida", Toast.LENGTH_LONG); | |
} | |
toast.show(); | |
} | |
public void clean(View view) { | |
TextView edtPeso = (TextView)findViewById(R.id.edtPeso); | |
RadioGroup rdgpFruits = (RadioGroup)findViewById(R.id.rdgpFruits); | |
edtPeso.setText(""); | |
rdgpFruits.clearCheck(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout 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"> | |
<TextView | |
android:id="@+id/txtDescription" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_above="@+id/edtPeso" | |
android:layout_centerHorizontal="true" | |
android:text="Informe a quantidade de quilos:" | |
android:textColor="@android:color/holo_blue_dark" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:id="@+id/txtTitle" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="62dp" | |
android:text="Descontão App" | |
android:textColor="@android:color/holo_red_dark" | |
android:textSize="24sp" | |
android:textStyle="bold" /> | |
<RadioGroup | |
android:id="@+id/rdgpFruits" | |
android:layout_width="230dp" | |
android:layout_height="179dp" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="104dp"> | |
<RadioButton | |
android:id="@+id/rdFruit1" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:text="Maçã" /> | |
<RadioButton | |
android:id="@+id/rdFruit2" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:text="Morango" /> | |
<RadioButton | |
android:id="@+id/rdFruit3" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:text="Banana" /> | |
<RadioButton | |
android:id="@+id/rdFruit4" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:text="Abacate" /> | |
<RadioButton | |
android:id="@+id/rdFruit5" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:text="Laranja" /> | |
</RadioGroup> | |
<EditText | |
android:id="@+id/edtPeso" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginBottom="143dp" | |
android:ems="10" | |
android:hint="digite aqui" | |
android:inputType="textPersonName" /> | |
<Button | |
android:id="@+id/btnClean" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignEnd="@+id/edtPeso" | |
android:layout_alignParentBottom="true" | |
android:layout_marginBottom="88dp" | |
android:onClick="clean" | |
android:text="Limpar" /> | |
<Button | |
android:id="@+id/btnCalc" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignStart="@+id/edtPeso" | |
android:layout_alignTop="@+id/btnClean" | |
android:onClick="calcPrice" | |
android:text="Calcular" /> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment