Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the java code for android tip calculator. All the numbers should only be set to TWO decimal places -3 tips, 3 total ,

This is the java code for android tip calculator. All the numbers should only be set to TWO decimal places -3 tips, 3 total , one custom tips, and one overall total, in total 8 numbers. all these numbers should only be set to two decimal places. Right now, the totals, custom tip and total price doesn't round to 2 decimal place.Please edit/fix my code to output all the numbers to two decimal places. Please be specific about which one is changed. Thank you !

image text in transcribed

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import android.widget.SeekBar; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private EditText bill; private TextView tv_tip1, tv_tip2, tv_tip3, tv_tipx, tv_total1, tv_total2, tv_total3, tv_totalx, seekVal; private SeekBar seekBar; private double bill_amount, tip1, tip2, tip3, tipx, total1, total2, total3, totalx, tipxper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tipxper = 18; bill = findViewById(R.id.bill); tv_tip1 = findViewById(R.id.tip1); tv_tip2 = findViewById(R.id.tip2); tv_tip3 = findViewById(R.id.tip3); tv_tipx = findViewById(R.id.tipx); tv_total1 = findViewById(R.id.total1); tv_total2 = findViewById(R.id.total2); tv_total3 = findViewById(R.id.total3); tv_totalx = findViewById(R.id.totalx); seekBar = findViewById(R.id.seekBar); seekVal = findViewById(R.id.seekval); bill.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { bill_amount = Double.parseDouble(bill.getText().toString()); updateUI(); } }); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tipxper = progress; updateSeekUI(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } private void updateUI() { tip1 = Math.round(10 * bill_amount) / 100.0; tip2 = Math.round(15 * bill_amount) / 100.0; tip3 = Math.round(20 * bill_amount) / 100.0; tipx = Math.round(tipxper * bill_amount) / 100.0; tv_tip1.setText(tip1+""); tv_tip2.setText(tip2+""); tv_tip3.setText(tip3+""); tv_tipx.setText(tipx+""); total1 = bill_amount + tip1; total2 = bill_amount + tip2; total3 = bill_amount + tip3; totalx = bill_amount + tipx; tv_total1.setText(total1+""); tv_total2.setText(total2+""); tv_total3.setText(total3+""); tv_totalx.setText(totalx+""); } private void updateSeekUI() { seekVal.setText(tipxper + "%"); tipx = bill_amount * tipxper /100.0; totalx = bill_amount + tipx; tv_tipx.setText(tipx+""); tv_totalx.setText(totalx+""); } 

}

row 0 Bill total 0.00 row | 10% 15% 20% row 2 Tip 0.00 0.00 0.00 row 3 Total 0.00 0.00 0.00 row 4 Custom 18% row 5 0.00 Total 0.00 row 0 Bill total 0.00 row | 10% 15% 20% row 2 Tip 0.00 0.00 0.00 row 3 Total 0.00 0.00 0.00 row 4 Custom 18% row 5 0.00 Total 0.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions