When I run my code I get an alert that the program stopped. The code is about a motorcycle rental app. That I have to calculate the rental price per day:
public class MainActivity extends Activity {
private RadioButton radio0,radio1,radio2,radio3,radio4;
private CheckBox CheckBox1,CheckBox2;
private TextView tv4;
private EditText et2;
private double precioinicial;
private double preciofinal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radio0=(RadioButton)findViewById(R.id.radio0);
radio1=(RadioButton)findViewById(R.id.radio1);
radio2=(RadioButton)findViewById(R.id.radio2);
radio3=(RadioButton)findViewById(R.id.radio3);
radio4=(RadioButton)findViewById(R.id.radio4);
CheckBox1=(CheckBox)findViewById(R.id.CheckBox1);
CheckBox2=(CheckBox)findViewById(R.id.CheckBox2);
et2=(EditText)findViewById(R.id.et2); //CANTIDAD DIAS DE ALQUILAR
tv4=(TextView)findViewById(R.id.tv4);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void importe (View v){
String CantidadDias= et2.getText().toString();
int cd=Integer.parseInt(CantidadDias); // CANTIDAD DE DIAS EN VARIABLE TIPO INT
precioinicial=0;
preciofinal=0;
if (radio0.isChecked()) { //custom
precioinicial=20;
}
else if (radio1.isChecked()) { //scooter
precioinicial=10;
}
else if (radio2.isChecked()) { //crooss
precioinicial=15;
}
/*if (CheckBox1.isChecked()==true) { //con seguro 20% mas por dia.
for (int i=0; i<cd; i++){
double por = (20*precioinicial) / 100 ;
precioinicial = precioinicial + por;
}
}
if (CheckBox2.isChecked()==true) { //con casco 1USD por dia
for (int z=0; z<cd; z++){
precioinicial = precioinicial + 1;
}
}*/
if (radio3.isChecked()) { //contado
double porcentaje= (10*precioinicial) /100;
precioinicial = precioinicial - porcentaje;
}
preciofinal=precioinicial;
tv4.setText("Importe: " + preciofinal);
}
}
I do not know where the error may be.