Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2015 00:15
Show Gist options
  • Select an option

  • Save anonymous/f5feae51009b9f8bc956 to your computer and use it in GitHub Desktop.

Select an option

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);
}
@LaszloLajosT

Copy link
Copy Markdown

Free coffee for everyone! :) I love it

@tashaf-mukhtar

Copy link
Copy Markdown

awesome!

@deepak9962

Copy link
Copy Markdown

So far, I've created this;
View after launching the app
Screenshot_20191223-162629

After clicking the + button
Screenshot_20191223-162709

After clicking the Order Button
Screenshot_20191223-162643

and so finally,
After clicking the reset button
Screenshot_20191223-162629

Codes are available at my github:
https://github.com/deepak9962/just-java

shortcut:
XML file:
https://github.com/deepak9962/just-java/blob/master/app/src/main/res/layout/activity_main.xml

mainActivity.java file:
https://github.com/deepak9962/just-java/blob/master/app/src/main/java/com/justjava/MainActivity.java

@rahulvivaramneni

Copy link
Copy Markdown

The Android Nanodegree course was awesome..! Thank You

@minamagdy268

Copy link
Copy Markdown

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
Copy Markdown

going good

@Eng-Abdulrasheed

Copy link
Copy Markdown

Thanks

@SALWA33

SALWA33 commented Jul 11, 2020

Copy link
Copy Markdown

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
Copy Markdown

Thank You!

@yaz71

yaz71 commented Sep 12, 2020

Copy link
Copy Markdown

thanks Kath !

@prateek-code-22

Copy link
Copy Markdown

coffee_app
So far so good!

@CrimsonMessup

Copy link
Copy Markdown

thanks

@asbe11

asbe11 commented May 12, 2022

Copy link
Copy Markdown

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

Marsworld9 commented Jun 19, 2022 •

Copy link
Copy Markdown

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

Samdzaka commented Jul 1, 2022

Copy link
Copy Markdown

Thank you! 😊

@hafsabelka

Copy link
Copy Markdown

ok thanks

@Reduan-coder

Copy link
Copy Markdown

Thank you

@02022310

Copy link
Copy Markdown

THANK YOU VERY MUCH

@boonicho

Copy link
Copy Markdown

Thanksgiving so much

@boonicho

Copy link
Copy Markdown

Thanks so much!!

@tule1213

Copy link
Copy Markdown

good thank you

@Anteneh-Kiyak

Copy link
Copy Markdown

"Free"

@Berhanus

Copy link
Copy Markdown

Thanks!

@Mameesys

Copy link
Copy Markdown

Very good thank you very much

@Anmut-d

Anmut-d commented Jun 26, 2025

Copy link
Copy Markdown

thank you very much!

@Anmut-d

Anmut-d commented Jun 26, 2025

Copy link
Copy Markdown

thank you very much!

@adugnawasma2009-cyber

Copy link
Copy Markdown

Thank you very much!

@kamaalyasin230-pixel

Copy link
Copy Markdown

@kamaalyasin230-pixel

Copy link
Copy Markdown

``

@teferileul39-bot

Copy link
Copy Markdown

This is what happens when clicking order
1000000500

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