Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2015 00:15
Show Gist options
  • Save anonymous/f5feae51009b9f8bc956 to your computer and use it in GitHub Desktop.
Save anonymous/f5feae51009b9f8bc956 to your computer and use it in GitHub Desktop.
/**
* This method displays the given text on the screen.
*/
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(message);
}
@rahulvivaramneni
Copy link

The Android Nanodegree course was awesome..! Thank You

@minamagdy268
Copy link

how can i add 5 input values and" average" Method, calculate the average value of the 5 inputs values inside the average method and return it

@keithchad
Copy link

going good

@Eng-Abdulrasheed
Copy link

Thanks

@SALWA33
Copy link

SALWA33 commented Jul 11, 2020

public class
int input1 = 10;
int input2= 20;
int input3 = 30;
int input4 = 40;
int input5 = 50;
public float average(){
writte java code to calculate the average for all input variable
return 0;

@tarek9999
Copy link

Thank You!

@yaz71
Copy link

yaz71 commented Sep 12, 2020

thanks Kath !

@prateek-code-22
Copy link

coffee_app
So far so good!

@CrimsonMessup
Copy link

thanks

@asbe11
Copy link

asbe11 commented May 12, 2022

currently the extension to MainActivity in Android Studio is .kt so when I paste de code in Java appears a pop up window with the message to change to kotlin extension but my code is whit 8 errors, I write the right code like catherine said but It still does not work. Can anyone help me?

`package com.example.android.justjava

import android.R
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import java.text.NumberFormat

/**

  • This app displays an order form to order coffee.
    */
    class MainActivity : AppCompatActivity() {

    var quantity = 0

    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    }

    /**

    • This method is called when the increment button is clicked.
      */
      fun increment(view: View?) {
      var int = quantity
      quantity += 1
      display (quantity)

      }

    /**

    • This method is called when the decrement button is clicked.
      */
      fun decrement(view: View?) {
      var int = quantity
      quantity -= 1
      display (quantity)

    }

    /**

    • This method is called when the order button is clicked.
      */
      fun submitOrder(view: View?) {
      String priceMessage = "Free"
      displayMessage(priceMessage)

    }

    /**

    • This method displays the given quantity value on the screen.
      */
      private fun display(number: Int) {
      val quantityTextView = findViewById(R.id.quantity_text_view) as TextView
      quantityTextView.text = "" + number
      }

    /**

    • This method displays the given price on the screen.
      */
      private fun displayPrice(number: Int) {
      val priceTextView = findViewById(R.id.price_text_view) as TextView
      priceTextView.setText(NumberFormat.getCurrencyInstance().format(number))
      }

    /**

    • This method displays the given text on the screen.
      */
      private fun displayMessage(message: String) {
      val priceTextView = findViewById(R.id.price_text_view) as TextView
      priceTextView.text = message
      }
      }`

@Marsworld9
Copy link

Marsworld9 commented Jun 19, 2022

This string message will help to crash any business in few time!!

public void submit (View view){
String priceTextView = "Free";
displayMessage(priceTextView);
}

/**

  • This method displays the given text on the screen.
    */
    private void displayMessage(String message) {
    TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
    priceTextView.setText(message);
    }

@Samdzaka
Copy link

Samdzaka commented Jul 1, 2022

Thank you! 😊

@hafsabelka
Copy link

ok thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment