Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, Android App: Modify this app. Allow user to input the number of guests and calculate the tip and total per guest. 1 package com.jblearning.tipcalculatorvo;

Java, Android App: Modify this app. Allow user to input the number of guests and calculate the tip and total per guest. image text in transcribed
image text in transcribed
image text in transcribed
1 package com.jblearning.tipcalculatorvo; 3 public class TipCalculatorf private float tip; private float bi11; 6 7 public Tipcalculator( float newTip, float newBi11) ( setTip( newTip) setBill ( newBi11); 10 12 public float getTip() f 13 14 15 16 17 18 19 20 21 return tip public float getBill return bill; public void setTip( float newTip) ( if newTip > 0) tip newTip; 23 24 25 26 27 28 29 public void setBill( float newBill) ( if (newBill 0) bill - newBill; 30 public float tipAmount () f 31 3 2 return bill tip; public float totalAmount ( 3 4 35 36 37 return bill+tipAmount() 1 package com.jblearning.tipcalculatorv4 import android.os. Bundle 4 import android. support.v7.app. AppCompatActivity 5 import android.text.Editable: 6 import android.text.Textwatcher 7 import android.widget.EditText; 8 import android.widget.TextView; 9 import java.text. NumberFormat; 10 11 public class MainAactivity extends AppCompatActivity ( 13 public Number Format money NumberFormat.getCurrencyInstance 12 private TipCalculator tipCalc private EditText billEditText private EditText tipEditTexti 14 15 16 17 18 19 20 21 eoverride protected void oncreate( Bundle savedinstancestate) ( super.onCreate( savedInstanceState) tipCalc- new TipCalculator ( 0.17E, 100.0E setContentView( R.layout.activity main) billEditText ( EditText ) findviewById( R.d.an ountbill ); tipEditText = ( EditText ) findviemById( R.id.amount-tip-percent ) ; 23 24 25 26 27 28 29 30 31 public void calculate 32 - TextChangeHandler tch = new TextChangeHandler ( ); billEditText.addTextChangedListener( tch ) tipEditText.addTextChangedListener( tch) String billString billEditText.getText (.tostring String tipString tipEditText.getText ().tostring) 34 35 36 37 3 8 39 40 TextView tipTextView = TextView) findviewByid( R.id. amount tip TextView totalTextView = (TextView) findViewById( R.id.amount_total) try // convert billstring and tipstring to floats float billAmount Float.parseFloat ( billstring; int tipPercent Integer.parseint( tipstring; // update the Model tipCalc.setBill ( billAmount): tipCalc.setTip( .01f tipPercent // ask Model to calculate tip and total amounts 42 43 4 6 47 4 8 49 50 51 52 53 54 float tip tipcalc.tipAmount ) float total tipCalc.totalAmount ( // update the View with formatted tip and total amounts tipTextView.setText( money.format ( tip totalTextView.setText( money.format ( total ) ) ) catch( NumberFormatException nfe ) ( // pop up an alert view here 56 57 58 59 60 61 62 63 64 65 private class TextChangeHandler implements TextWatcher ( public void afterTextChanged( Editable e calculate) public void beforeTextChanged( Charsequence s, int start, int count, int after public void onTextChanged Charsequence s, int start, 67 68 69 70 int before, int after ( 1 package com.jblearning.tipcalculatorvo; 3 public class TipCalculatorf private float tip; private float bi11; 6 7 public Tipcalculator( float newTip, float newBi11) ( setTip( newTip) setBill ( newBi11); 10 12 public float getTip() f 13 14 15 16 17 18 19 20 21 return tip public float getBill return bill; public void setTip( float newTip) ( if newTip > 0) tip newTip; 23 24 25 26 27 28 29 public void setBill( float newBill) ( if (newBill 0) bill - newBill; 30 public float tipAmount () f 31 3 2 return bill tip; public float totalAmount ( 3 4 35 36 37 return bill+tipAmount() 1 package com.jblearning.tipcalculatorv4 import android.os. Bundle 4 import android. support.v7.app. AppCompatActivity 5 import android.text.Editable: 6 import android.text.Textwatcher 7 import android.widget.EditText; 8 import android.widget.TextView; 9 import java.text. NumberFormat; 10 11 public class MainAactivity extends AppCompatActivity ( 13 public Number Format money NumberFormat.getCurrencyInstance 12 private TipCalculator tipCalc private EditText billEditText private EditText tipEditTexti 14 15 16 17 18 19 20 21 eoverride protected void oncreate( Bundle savedinstancestate) ( super.onCreate( savedInstanceState) tipCalc- new TipCalculator ( 0.17E, 100.0E setContentView( R.layout.activity main) billEditText ( EditText ) findviewById( R.d.an ountbill ); tipEditText = ( EditText ) findviemById( R.id.amount-tip-percent ) ; 23 24 25 26 27 28 29 30 31 public void calculate 32 - TextChangeHandler tch = new TextChangeHandler ( ); billEditText.addTextChangedListener( tch ) tipEditText.addTextChangedListener( tch) String billString billEditText.getText (.tostring String tipString tipEditText.getText ().tostring) 34 35 36 37 3 8 39 40 TextView tipTextView = TextView) findviewByid( R.id. amount tip TextView totalTextView = (TextView) findViewById( R.id.amount_total) try // convert billstring and tipstring to floats float billAmount Float.parseFloat ( billstring; int tipPercent Integer.parseint( tipstring; // update the Model tipCalc.setBill ( billAmount): tipCalc.setTip( .01f tipPercent // ask Model to calculate tip and total amounts 42 43 4 6 47 4 8 49 50 51 52 53 54 float tip tipcalc.tipAmount ) float total tipCalc.totalAmount ( // update the View with formatted tip and total amounts tipTextView.setText( money.format ( tip totalTextView.setText( money.format ( total ) ) ) catch( NumberFormatException nfe ) ( // pop up an alert view here 56 57 58 59 60 61 62 63 64 65 private class TextChangeHandler implements TextWatcher ( public void afterTextChanged( Editable e calculate) public void beforeTextChanged( Charsequence s, int start, int count, int after public void onTextChanged Charsequence s, int start, 67 68 69 70 int before, int after (

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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago