Question

In: Computer Science

Write an Android phone program such that two instances of EditText with texts “Input a positive...

Write an Android phone program such that two instances of EditText with texts “Input a positive integer (smaller)” and “Input a positive integer (larger)”, one instances of Button with text “Click here to get outputs”, and four instances of TextView with respective texts “Decide if the larger one is a multiple of the smaller one : ”, “The GCD of two integers : ”, “The LCM of the two integers : ”,  “The permutations based on two integers : ”, “The combinations based on the two integers : “, and "The definite integral of 3*x*x of from smaller integer to larger integer : " are displayed vertically on the AVD. The users of your program will input two positive integers. After the users click the button, the information or values based on the two input integers will be displayed in the corresponding six instances of TextView.  (Hints: GCD denotes the greatest common divisor and LCM denotes the least common multiple.) 

Solutions

Expert Solution

OUTPUT

Code: MainActivity.class

package cheggans.app;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final EditText etnum1=findViewById(R.id.num1);
        final EditText etnum2=findViewById(R.id.num2);

        final TextView tvcheck=findViewById(R.id.checktv);
        final TextView tvgcd=findViewById(R.id.gcdtv);
        final TextView tvlcm=findViewById(R.id.lcmtv);
        final TextView tvperm=findViewById(R.id.permtv);
        final TextView tvcomb=findViewById(R.id.combtv);
        final TextView tvintg=findViewById(R.id.ingrltv);


        Button btn=findViewById(R.id.button);


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num1=Integer.parseInt(etnum1.getText().toString());
                int num2=Integer.parseInt(etnum2.getText().toString());


                tvcheck.setText("Decide if the larger one is a multiple of the smaller one :" + checklarger(num1,num2));
                tvgcd.setText("The GCD of two integers :"+getGcd(num1,num2));
                tvlcm.setText("The LCM of the two integers : :"+getLcm(num1,num2));
                tvperm.setText("The permutations based on two integers : "+getPerm(num1,num2));
                tvcomb.setText("The combinations based on the two integers : "+getComb(num1,num2));
                tvintg.setText("The definite integral is :"+getIntegral(num1,num2));


            }
        });


    }


    public int checklarger(int a,int b){
        int c=0;
        if(a>b){
            c=a;
        }
        else{
            c=b;
        }

        return c;
    }



    public int getGcd(int a,int b){
        int n1 = a, n2 = b, gcd = 1;
        for(int i = 1; i <= n1 && i <= n2; ++i)
        {
            // Checks if i is factor of both integers
            if(n1 % i==0 && n2 % i==0)
                gcd = i;
        }

        return gcd;
    }


    public int getLcm(int a,int b){
        int n1 = a, n2 = b, lcm;
        // maximum number between n1 and n2 is stored in lcm
        lcm = (n1 > n2) ? n1 : n2;
        // Always true
        while(true)
        {
            if( lcm % n1 == 0 && lcm % n2 == 0 )
            {
                break;
            }
            ++lcm;
        }


        return lcm;
    }


    static int fact(int n) {
        int fact = 1;
        int i = 1;
        while(i <= n) {
            fact *= i;
            i++;
        }
        return fact;
    }
    public int getPerm(int a,int b){
        return fact(a) / fact(a - b);
    }


    int getComb(int n, int r)
    {
        return fact(n) / (fact(r) *fact(n - r));
    }






    int getIntegral(int a, int b)
    {

        //integral of 3*x*x is   x^3

        int lowerBound= a*a*a;
        int upperBound= b*b*b;


        return upperBound-lowerBound;
    }



}

XML: activity_main

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="91dp"
        android:text="Click here to get outputs"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/num2" />

    <EditText
        android:id="@+id/num2"
        android:layout_width="290dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="29dp"
        android:ems="10"
        android:hint="Input a positive Integer(larger)"
        android:inputType="number"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/num1" />

    <EditText
        android:id="@+id/num1"
        android:layout_width="290dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:ems="10"
        android:hint="Input a positive Integer(smaller)"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button">

        <TextView
            android:id="@+id/checktv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />

        <TextView
            android:id="@+id/gcdtv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />

        <TextView
            android:id="@+id/lcmtv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />

        <TextView
            android:id="@+id/permtv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />

        <TextView
            android:id="@+id/combtv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />

        <TextView
            android:id="@+id/ingrltv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="" />


    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>


Related Solutions

Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a Python program which takes a set of positive numbers from the input and returns...
Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
MATLAB QUESTION Write a python program to request a positive float input from the user, x....
MATLAB QUESTION Write a python program to request a positive float input from the user, x. The program should check for the value of x. If x is larger than or equal to 1.0, the program should display the value of x in addition to the string “is larger than or equal to 1” and then terminate the program. If x is less than 1 the program should calculate y such that: y = 1-x+x^2/2-x^3/3+x^4/4-x^5/5……-x^99/99+x^100/100 The program should then display...
Samsung and Lg are the two surviving makers of phone operating with android. since they both...
Samsung and Lg are the two surviving makers of phone operating with android. since they both have the same operating system they are considered virtually identical products to the average consumer, they are marginal cost of producing a phone in MClg=$20 for LG and MCs=20 for samsung. The inverse demand thye jointly face is P=200-2Y where Yg=Ylg+Ys (Ylg are are the phones produced by LGm while Ys are the phones produced by samsung. 1.What are the reaction of functions strategies...
Write a JAVA program that compares two strings input to see if they are the same?
Write a JAVA program that compares two strings input to see if they are the same?
Write a program whose input is two integers, and whose output is the first integer and...
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. import java.util.Scanner; public class LabProgram {...
Write a program that takes two sets ’A’ and ’B’ as input read from the file...
Write a program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT