Forked from udacityandroid/Code snippet from MainActivity.java
Created
February 8, 2018 05:50
-
-
Save redtripleAAA/6cfb449f9ce5c5497e0cdb7833bf017c to your computer and use it in GitHub Desktop.
Android for Beginners : Negative Number of Cups of Coffee Extra Challenge Solution
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
/** | |
* This method is called when the plus button is clicked. | |
*/ | |
public void increment(View view) { | |
if (quantity == 100) { | |
// Show an error message as a toast | |
Toast.makeText(this, "You cannot have more than 100 coffees", Toast.LENGTH_SHORT).show(); | |
// Exit this method early because there's nothing left to do | |
return; | |
} | |
quantity = quantity + 1; | |
displayQuantity(quantity); | |
} | |
/** | |
* This method is called when the minus button is clicked. | |
*/ | |
public void decrement(View view) { | |
if (quantity == 1) { | |
// Show an error message as a toast | |
Toast.makeText(this, "You cannot have less than 1 coffee", Toast.LENGTH_SHORT).show(); | |
// Exit this method early because there's nothing left to do | |
return; | |
} | |
quantity = quantity - 1; | |
displayQuantity(quantity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment