Skip to content

Instantly share code, notes, and snippets.

@ssindher11
Created December 16, 2017 13:26
Show Gist options
  • Save ssindher11/d0fcbc38c7d08e7c24ac8c8d2b20f4ea to your computer and use it in GitHub Desktop.
Save ssindher11/d0fcbc38c7d08e7c24ac8c8d2b20f4ea to your computer and use it in GitHub Desktop.
Just Java
/**
* IMPORTANT: Make sure you are using the correct package name.
* This example uses the package name:
* package com.example.android.justjava
* If you get an error when copying this code into Android studio, update it to match teh package name found
* in the project's AndroidManifest.xml file.
**/
package com.example.android.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.text.NumberFormat;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int quantity = 0;
//ORDER button
public void submitOrder(View view) {
String priceMessage = "Amount Due = $ ";
displayMessage(priceMessage + (quantity * 15) + "\nThank You :)");
}
public void increment(View view)
{
quantity++;
display(quantity);
}
public void decrement(View view)
{
quantity--;
display(quantity);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
/**
* 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment