Está en la página 1de 4

Strings.

xml
<resources>

<string-array name="arraydestinos">
<item>Tumbes</item>
<item>Cuzco</item>
<item>Ancash</item>
<item>Arequipa</item>
</string-array>
</resources>

Content_main.xml
<?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"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:weightSum="1">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Destino"
android:id="@+id/textView" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/arraydestinos"
android:id="@+id/spnDestino" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Linea"
android:id="@+id/textView2" />

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rdgLinea"
>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lan"
android:id="@+id/rbtLan"
android:checked="true" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avianca"
android:id="@+id/rbtAvianca"
android:checked="false" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Papagallo"
android:id="@+id/rbtTaca"
android:checked="false" />
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nombre"
android:id="@+id/textView3" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edtNombre" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dscto 10%"
android:id="@+id/chkDesc"
android:checked="false" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dscto 18%"
android:id="@+id/chkIgv"
android:checked="false" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reservar"
android:id="@+id/btnAceptar" />

</LinearLayout>

</RelativeLayout>

MainActivity.java

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn=(Button)findViewById(R.id.btnAceptar);
btn.setOnClickListener(this);
}

public void onClick(View view) {


Spinner sp=(Spinner)findViewById(R.id.spnDestino);
RadioGroup rd=(RadioGroup)findViewById(R.id.rdgLinea);
EditText edt =(EditText)findViewById(R.id.edtNombre);
CheckBox chkdes=(CheckBox)findViewById(R.id.chkDesc);
CheckBox chkigv=(CheckBox)findViewById(R.id.chkIgv);

double precio=0,incremento=0,desc=0,igv=0,total=0;
switch(sp.getSelectedItemPosition()){
case 0:precio=120;break;
case 1:precio=90;break;
case 2:precio=40;break;
case 3:precio=60;break;
}
switch(rd.getCheckedRadioButtonId()) {
case R.id.rbtLan:incremento=0;break;
case R.id.rbtAvianca:incremento=precio*0.08;break;
case R.id.rbtTaca:incremento=precio * 0.05;break;
}
precio = precio +incremento;
if(chkdes.isChecked()){
desc = precio * 0.10;
}
if(chkigv.isChecked()){
igv = precio * 0.18;
}
total = precio + igv - desc;

String res="Precio "+precio+


"\nDescuento "+desc+
"\nIGV "+igv+
"\nTotal "+total;

Toast.makeText(this,res,Toast.LENGTH_LONG).show();
}
}

También podría gustarte