0
Good night
I am creating an application using 5 "boxes" (EditText
) where he could multiply the boxes he wanted.
Example: value1 * value2= resu.... value1*value2*value3=resu.... value1*value2*va loodd3*value4=res u.... value1*value odd2*valoodd3*value4*value5=resu
As in the following image:
Code:
public void somar (View v){
EditText odd1 = (EditText) findViewById(R.id.editText7);
String stringodd1 = odd1.getText().toString();
EditText odd2 = (EditText) findViewById(R.id.editText8);
String stringodd2 = odd2.getText().toString();
EditText montante = (EditText) findViewById(R.id.editText12);
String stringmontante = montante.getText().toString();
NumberFormat formatter = new DecimalFormat("#0.00");
if (stringodd1.trim().isEmpty() || stringodd2.trim().isEmpty()|| stringmontante.trim().isEmpty() )
{
Toast.makeText(getApplicationContext(), "Campos em branco",
Toast.LENGTH_LONG).show();
}
else
{
double valorodd1 = Double.parseDouble(stringodd1);
double valorodd2 = Double.parseDouble(stringodd2);
double valormontante = Double.parseDouble(stringmontante);
double resu = valorodd1 * valorodd2 * valormontante;
TextView resultado = (TextView) findViewById(R.id.textView15);
resultado.setText (formatter.format(resu) + "€" );
What question do you have or difficulty finding? Take advantage of and add the code you are using in the application that focuses on your doubt/difficulty.
– Isac
I have this code with a simple sum in box 1 and 2. My goal is to be able to calculate the box 1 x 2 = total, or box 1 x 2 x 3 = total or box 1 x 6 = total. Thank you
– S0nkit3
Do you have any button that when you click it does the operations ?
– Dev
Do N successive multiplications ? And would be put where ? There are N
TextViews
for these results ?– Isac
Yes, as shown in my code above I have the button to calculate the multiplications. The error in my code is that I have 6 Edittext to enter 1 number and 1 textview to display the result, when I want to multiply 2 numbers does not give, because I am obliged to fill the remaining "boxes" with numbers to do the multiplication and I want to be able to use the "boxes" as you like. If I want to multiply 2 number I put a number in one box and another number in the other box, if I want to multiply 3 step by the same 1 number in each box and multiply. I hope you understand. Thank you
– S0nkit3