Question

In: Computer Science

You recently started working in at a University in the Math department as a software programmer....

You recently started working in at a University in the Math department as a software programmer. You need to build an app that can calculate the mod of two numbers. Users need to enter num1 and num2. The app should perform the calculation and display the output as num1 mod nub2 operation.

For example, 25 mod 5=0

24 mod 5 = 4

Once you implement the mod operations, then you need to add following buttons.

  • Addition
  • Subtraction
  • Division
  • Power

Follow these steps to complete the lab.

  1. Create the android studio project
  2. Use Android studio layout editor
  3. Add textboxes and labels according to the UI
  4. Add Button in the UI
  5. Review the XML code of the design
  6. Declare the variable before the oncreate function
  7. Read the value from textboxes and assign it to the variable
  8. Add the click event for the button
  9. Display the output
  10. Declare the variable before the oncreate function

Solutions

Expert Solution

I am adding the XML and java code files below:

Say your project name in Android Studio that you've created be "MyApplication" and package name given be "com.pac":

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <EditText android:id="@+id/etNum1" android:layout_width="152dp" android:layout_height="78dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:ems="10" android:hint="number 1" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.106" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.062" /> <EditText android:id="@+id/etResult" android:layout_width="152dp" android:layout_height="78dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:ems="10" android:hint="Result" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.875" /> <Button android:id="@+id/btnMod" android:layout_width="154dp" android:layout_height="58dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="MOD" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.531" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.302" /> <Button android:id="@+id/btnPow" android:layout_width="154dp" android:layout_height="58dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="POWER" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.887" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.654" /> <Button android:id="@+id/btnDiv" android:layout_width="154dp" android:layout_height="58dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="DIVIDE" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.099" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.654" /> <Button android:id="@+id/btnSub" android:layout_width="154dp" android:layout_height="58dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="SUB" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.887" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.499" /> <EditText android:id="@+id/etNum2" android:layout_width="152dp" android:layout_height="78dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:ems="10" android:hint="number 2" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.88" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.062" /> <Button android:id="@+id/btnAdd" android:layout_width="154dp" android:layout_height="58dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="ADD" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.107" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.499" /> <TextView android:id="@+id/textView4" android:layout_width="217dp" android:layout_height="24dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="Calculation options:" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.707" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.218" /> </android.support.constraint.ConstraintLayout>
MainActivity.java

package com.pac; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity { EditText etNum1, etNum2, etResult; Button btnMod, btnAdd, btnSub, btnDiv, btnPow; int num1, num2; double result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chatbot); etNum1=findViewById(R.id.etNum1); etNum2=findViewById(R.id.etNum2); etResult=findViewById(R.id.etResult); btnAdd=findViewById(R.id.btnAdd); btnMod=findViewById(R.id.btnMod); btnSub=findViewById(R.id.btnSub); btnDiv=findViewById(R.id.btnDiv); btnPow=findViewById(R.id.btnPow); btnMod.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1=Integer.parseInt(etNum1.getText().toString()); num2=Integer.parseInt(etNum2.getText().toString()); etResult.setText(String.valueOf(num1%num2)); } }); btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1=Integer.parseInt(etNum1.getText().toString()); num2=Integer.parseInt(etNum2.getText().toString()); etResult.setText(String.valueOf(num1+num2)); } }); btnPow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1=Integer.parseInt(etNum1.getText().toString()); num2=Integer.parseInt(etNum2.getText().toString()); etResult.setText(String.valueOf(Math.pow(num1,num2))); } }); btnSub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1=Integer.parseInt(etNum1.getText().toString()); num2=Integer.parseInt(etNum2.getText().toString()); etResult.setText(String.valueOf(num1-num2)); } }); btnDiv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1=Integer.parseInt(etNum1.getText().toString()); num2=Integer.parseInt(etNum2.getText().toString()); etResult.setText(String.valueOf(num1/num2)); } }); } }


Related Solutions

Maurice has recently graduated from University and started working for a small public accounting firm who...
Maurice has recently graduated from University and started working for a small public accounting firm who specialise in providing taxation services to a range of clients. He has just returned from a review interview with one of the partners and is upset because the partner was not happy with the quality of the work papers he has prepared to support the income tax return for a client. Explain to Maurice the reasons why quality work papers are important, what should...
You recently started working in a large retail store as a management trainee.You are asked to...
You recently started working in a large retail store as a management trainee.You are asked to develop a series of actions to improve employee engagement. What might you consider and why?
You have recently started working as a product analyst at a company that manufactures and sells...
You have recently started working as a product analyst at a company that manufactures and sells a variety of soft drink products. One of your first jobs is to categorize each of the firm's new products for the upcoming year into the appropriate new product category for a presentation you are putting together for your manager. A new product is one that is new to a company in any way. If a product is functionally different from existing products in...
A) Assume you have just started working in the marketing department for a large firm that...
A) Assume you have just started working in the marketing department for a large firm that sells major consumer products such as toothpaste or sodas or athletic shoes. You are in a meeting with some of the other workers in other departments - accounting, human resources, finance, and manufacturing. These people are saying that the company should get rid of the marketing to save millions of dollars. What would you say to persuade them that the marketing department is vital...
You have recently graduated from your university and started work with an accounting firm. You meet...
You have recently graduated from your university and started work with an accounting firm. You meet an old school friend, Kim, for dinner—you haven’t seen each other for several years. Kim is surprised that you are now working as an auditor because your childhood dream was to be a ballet dancer. Unfortunately, your knees were damaged in a fall and you can no longer dance. The conversation turns to your work and Kim wants to know how you do your...
Being an auditor You have recently graduated from your university and started work with an accounting...
Being an auditor You have recently graduated from your university and started work with an accounting firm. You meet an old school friend, Kim, for dinner—you haven’t seen each other for several years. Kim is surprised that you are now working as an auditor because your childhood dream was to be a ballet dancer. Unfortunately, your knees were damaged in a fall and you can no longer dance. The conversation turns to your work and Kim wants to know how...
You recently started working as a data analyst for the retail industry. Your company would like...
You recently started working as a data analyst for the retail industry. Your company would like to invest more money into a machine learning project. You need to write at least 3-5 page executive summary that describes the benefit of using machine learning. It should include following: Identify at least two business use cases for a retail industry that will benefit from Machine learning. Describe the importance of input data quality for machine learning. Describe a type of Python libraries...
You recently started working as a nurse manager at a larger local urgent care facility. Because...
You recently started working as a nurse manager at a larger local urgent care facility. Because the center is so new (and a bit fancier than most) many patients come here expecting a bit of a wait before they can be seen. Out of curiosity, on a particularly busy day you write down how many minutes a random sample of patients has to wait before being seen by one of the medical staff. Using a significance level of 20%, test...
Solve this word problem using step by step procedure: The math department at a local university...
Solve this word problem using step by step procedure: The math department at a local university has customarily advised students to purchase Calculator A. The manufacturer has recently released a new model, Calculator B, which is reputed to be more user-friendly. The faculty decided to determine if there is a difference in the time required to perform a certain common statistical calculation. Twelve students chosen at random are given drills with both calculators so that they are familiar with the...
Steve Rogers recently started a job as an administrative assistant in the cost accounting department of...
Steve Rogers recently started a job as an administrative assistant in the cost accounting department of Mickey Manufacturing . New to the area of cost accounting , Steve is puzzled by the fact that one of Mickey ' s manufactured products , R2D2 , seems to have a different cost , depending on who asks for it . When the marketing department requested the cost of R2D2 in order to determine pricing for the new catalog , Steve was told...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT