Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.justjava;
- /**
- * 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.
- **/
- 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 {
- int quantity=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- /**
- * This method is called when the order button is clicked.
- */
- public void submitOrder(View view) {
- int price = calculatePrice();
- String orderSummary = createOrderSummary(price);
- // String priceMessage = "Total: $"+price;
- // priceMessage = priceMessage + "\nThank you!";
- // displayMessage (priceMessage);
- displayMessage(orderSummary);
- }
- private String createOrderSummary(int price) {
- String message= "Name: Kaptain kunal " +"\n" +"Quantity: " + quantity + "\n" + "Total: $" + price +"\n" + "Thank you!";
- return message;
- }
- /**
- * Calculates the price of the order.
- *
- * @param quantity is the number of cups of coffee ordered
- */
- private int calculatePrice() {
- int price = quantity * 5;
- return price;
- }
- private int calculatePrice(int quantity, int pricePerCoffee) {
- int price = quantity * pricePerCoffee;
- return price;
- }
- private int calculatePrice(int quantity) {
- int price = quantity * 5;
- return price;
- }
- /**
- * This method displays the given quantity value on the screen.
- * @param numberOfCups
- */
- private void displayQuantity(int numberOfCups) {
- TextView quantityTextView = findViewById(R.id.quantity_text_view);
- quantityTextView.setText("" + numberOfCups);
- }
- public void increment(View view) {
- quantity++;
- displayQuantity(quantity);
- }
- public void decrement(View view) {
- quantity--;
- displayQuantity(quantity);
- }
- /**
- * This method displays the given text on the screen.
- */
- private void displayMessage(String message) {
- TextView orderSummaryTextView = findViewById(R.id.order_summary_text_view);
- orderSummaryTextView.setText(message);
- }
- }
Add Comment
Please, Sign In to add comment