
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
How would I add a TextWatcher to the following Java calculator app code:
package com.example.tipcalculatorv2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText billEditText;
private TextView totalTextView;
private EditText tipPercentEditText;
private TextView tipTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
billEditText = (EditText) findViewById(R.id.amount_bill);
totalTextView = (TextView) findViewById(R.id.amount_total);
tipPercentEditText = (EditText) findViewById(R.id.amount_tip_percent);
tipTextView = (TextView) findViewById(R.id.amount_tip);
}
public void calculate(View view) {
String billStr=billEditText.getText().toString();
totalTextView.setText(billStr);
String tipPercentStr=tipPercentEditText.getText().toString();
tipTextView.setText(billStr);
try {
float billAmount = Float.parseFloat(billStr);
float tipPercent = Float.parseFloat(tipPercentStr);
float tip = billAmount * tipPercent / 100;
tipTextView.setText(Float.toString(tip));
float total = billAmount + tip;
totalTextView.setText(Float.toString(total));
} catch (NumberFormatException e) {
Context context = getApplicationContext();
CharSequence text = "Please enter numbers for bill and tip";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
e.printStackTrace();
}
}
}
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText billEditText;
private TextView totalTextView;
private EditText tipPercentEditText;
private TextView tipTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
billEditText = (EditText) findViewById(R.id.amount_bill);
totalTextView = (TextView) findViewById(R.id.amount_total);
tipPercentEditText = (EditText) findViewById(R.id.amount_tip_percent);
tipTextView = (TextView) findViewById(R.id.amount_tip);
}
public void calculate(View view) {
String billStr=billEditText.getText().toString();
totalTextView.setText(billStr);
String tipPercentStr=tipPercentEditText.getText().toString();
tipTextView.setText(billStr);
try {
float billAmount = Float.parseFloat(billStr);
float tipPercent = Float.parseFloat(tipPercentStr);
float tip = billAmount * tipPercent / 100;
tipTextView.setText(Float.toString(tip));
float total = billAmount + tip;
totalTextView.setText(Float.toString(total));
} catch (NumberFormatException e) {
Context context = getApplicationContext();
CharSequence text = "Please enter numbers for bill and tip";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
e.printStackTrace();
}
}
}
Expert Solution

arrow_forward
Step 1: Providing Introduction
You can include a TextWatcher in your EditText fields to increase the functionality of your calculator app. As the user inputs or adjusts values in the input fields, this will enable you to update calculations in real-time.
Please refer to the following steps for the complete solution to the problem above.
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Question & instructions can be found in images please see images first Starter code import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat; public class GPACalculator extends JFrame{private JLabel gradeL, unitsL, emptyL; private JTextField gradeTF, unitsTF; private JButton addB, gpaB, resetB, exitB; private AddButtonHandler abHandler;private GPAButtonHandler cbHandler;private ResetButtonHandler rbHandler;private ExitButtonHandler ebHandler; private static final int WIDTH = 400;private static final int HEIGHT = 150; private static double totalUnits = 0.0; // total units takenprivate static double gradePoints = 0.0; // total grade points from those unitsprivate static double totalGPA = 0.0; // total GPA (gradePoints / totalUnits) //Constructorpublic GPACalculator(){//Create labelsgradeL = new JLabel("Enter your grade: ", SwingConstants.RIGHT);unitsL = new JLabel("Enter number of units: ", SwingConstants.RIGHT);emptyL = new…arrow_forwardClass HoldAt20PigPlayer java.lang.Object HoldAt20PigPlayer All Implemented Interfaces:PigPlayerpublic class HoldAt20PigPlayerextends java.lang.Objectimplements PigPlayer HoldAt20PigPlayer - a Pig player that rolls as long as the turn total is less than 20 and the player's score plus the turn total is less than the goal score PigGame.GOAL_SCORE. Constructor Summary HoldAt20PigPlayer() Method Summary boolean isRolling(int myScore, int otherScore, int turnTotal) isRolling - return whether or not the player rolls, given the current game state. Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait Constructor Detail HoldAt20PigPlayer public HoldAt20PigPlayer() Method Detail isRolling public boolean isRolling(int myScore, int otherScore, int turnTotal)isRolling - return whether or not the player rolls, given the current game state. The…arrow_forwardWhat is interesting and difficult about GUI concepts in Java? For instance event handlers, layout managers, frames, panels. polymorphism, JavaFX.arrow_forward
- In JAVAFX. Any and all help is appreciated, please also show the results with your code. Please see the attached image.arrow_forwardin an android app . this is javacode to read api from web , import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity {…arrow_forwardRecreate the following GUI in JavaFX: 2. In JavaFX, implement the functionality of making a popup appear on the screen when the 'Addworkshop' button is pressed. The popup should contain the message: 'Maximum number of workshopsreached.'arrow_forward
- Write an android project that consist of the following: One activity (java file). Two different layouts (XML files). Each layout will have the following: Textview: contains the type of the layout you choose for this layout, for example, ConstraintLayout, table-layout, or LinearLayout (vertically or horizontally)…etc Textview: contains show your full name. Textview: to show your student ID. A button: upon clicking, the button should switch the layout of the activity. For example, the button in layout 1 should change the layout to layout 2, and the button in layout 2 should change the layout to layout 1. Use your own name and ID. The nams is " Alanood " and the ID " 190139479 " .arrow_forwardCreate a class RectangleExample in eclipse. Copy the following code into the class. RectangleExample.java package mypackage; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.Rectangle; public class RectangleExample extends Application { Rectangle rect1, rect2; @Override public void start(Stage stage) { Group root = new Group(); //Drawing a Rectangle rect1 = new Rectangle(); //Setting the properties of the rectangle rect1.setX(20.0f); rect1.setY(20.0f); rect1.setWidth(300.0f); rect1.setHeight(10.0f); rect1.setFill(javafx.scene.paint.Color.RED); //Add to a Group object root.getChildren().add(rect1); //Drawing a Rectangle rect2 = new Rectangle(); //Setting the properties of the rectangle rect2.setX(20.0f); rect2.setY(40.0f); rect2.setWidth(200.0f); rect2.setHeight(10.0f); rect2.setFill(javafx.scene.paint.Color.GREEN); //Add to a Group object root.getChildren().add(rect2); //Creating a scene…arrow_forwardJavascript .1. create a new global object variable “signUp” to store the sign-up information. Add the following properties to the object: name, email, phone, address, city, state, zip, foodAllergies, frequency, size and initialize all to a blank stringarrow_forward
- its a JavaFX project Create a working order form for Orinoco as shown. Sales tax is 7%.To display the Total Due (a Label) as currency, research how to use class NumberFormat. package application;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.geometry.Insets;import javafx.stage.Stage;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.control.CheckBox;import javafx.scene.control.Label;import javafx.scene.control.RadioButton;import javafx.scene.control.TextField;import javafx.scene.control.ToggleGroup;import javafx.scene.layout.GridPane; public class Main extends Application {TextField itemField,quantityField,priceField;Label totalValue;CheckBox isTaxable;ToggleGroup shipping;@Overridepublic void start(Stage primaryStage) {primaryStage.setTitle("orinoco.com");GridPane rootNode = new GridPane();rootNode.setPadding(new Insets(25));rootNode.setHgap(10);rootNode.setVgap(10);Scene scene = new…arrow_forwardIn java pls!!!! thank you!arrow_forwarda code is like this package com.example.ett;import androidx.appcompat.app.AppCompatActivity;import android.view.LayoutInflater;import android.view.View;import java.lang.reflect.Field;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.OrientationHelper;import androidx.recyclerview.widget.RecyclerView;import androidx.recyclerview.widget.StaggeredGridLayoutManager;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;import android.os.Bundle;import.NonNull;import java.util.ArrayList;import java.util.List;public class UniversityAdapter extends RecyclerView.Adapter<UniversityAdapter.ViewHolder> {private List<University> universities;public UniversityAdapter(List<University> universities) {this.universities = universities;}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view =…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education