Created
January 30, 2018 08:27
-
-
Save mezdour/b1a95a7728e8dd8f258cf00a2567fbc8 to your computer and use it in GitHub Desktop.
JustJava java code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.justjava; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import java.text.NumberFormat; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
int numberOfCoffees = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
display(numberOfCoffees); | |
} | |
public void submitOrder(View view) { | |
display(numberOfCoffees); | |
displayPrice(numberOfCoffees*3); | |
} | |
public void quantityPlus(View view) { | |
numberOfCoffees = numberOfCoffees + 1; | |
display(numberOfCoffees); | |
} | |
public void quantityMines(View view) { | |
if(numberOfCoffees != 0) | |
{ | |
numberOfCoffees = numberOfCoffees - 1; | |
} | |
display(numberOfCoffees); | |
} | |
/** | |
* 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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment