Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created June 9, 2015 23:49
Show Gist options
  • Save udacityandroid/efc863aff5c2ff5784ce to your computer and use it in GitHub Desktop.
Save udacityandroid/efc863aff5c2ff5784ce to your computer and use it in GitHub Desktop.
Add to MainActivity.java
/**
* Calculates the price of the order.
*
* @param quantity is the number of cups of coffee ordered
*/
private void calculatePrice(int quantity) {
int price = quantity * 5;
}
@Eduese
Copy link

Eduese commented May 21, 2018

private void calculatePrice(int quantity) {
int price = quantity * 5;
}

I experimented with private int method_name() but without an argument, and with a return type, tho

Got the same answer

@mahmoudkashef
Copy link

thanks for the tips guys

@orwa-te
Copy link

orwa-te commented Jun 24, 2018

Very very simple

@Younes666
Copy link

done

@HDAII
Copy link

HDAII commented Jun 30, 2018

untitled

Can someone help me please i have a problem when i press run the program give me error select android SDK !!!!

@djalilo24
Copy link

answer 1
int numberOfCoffees =0;int price=0;
public void submitOrder(View view) {
calculatePrice(numberOfCoffees);
String PriceMessge="Total: $"+price+ " \nThank You!";
displayMessage(PriceMessge);
}

/**
 * Calculates the price of the order.
 *
 * @param quantity is the number of cups of coffee ordered
 */
private int calculatePrice(int quantity) {
     price = quantity * 5;
    return price;
}

===============================================================
answer 2
int numberOfCoffees =0;int price=0;
public void submitOrder(View view) {
calculatePrice(numberOfCoffees,10);
String PriceMessge="Total: $"+price+ " \nThank You!";
displayMessage(PriceMessge);
}

/**
 * Calculates the price of the order.
 *
 * @param quantity is the number of cups of coffee ordered
 */
private int calculatePrice(int quantity,int prix) {
     price = quantity * prix;
    return price;
}

===========================================
answer 3
int numberOfCoffees =0;int price=0;
public void submitOrder(View view) {
calculatePrice();
String PriceMessge="Total: $"+price+ " \nThank You!";
displayMessage(PriceMessge);
}

/**
 * Calculates the price of the order.
 *
 * @param price is the number of cups of coffee ordered
 */
private int calculatePrice() {
     price = numberOfCoffees * 5;
    return price;
}

@MinaMagdyLuis
Copy link

please help me
I can not find the just java app code to solve this test

@bgannon29
Copy link

I declared quantity as a global variable that is updated with increment and decrement buttons......

public void submitOrder(View view) {
    displayMessage(calculatePrice(quantity));
}

@org.jetbrains.annotations.NotNull
private String calculatePrice(int quantity){
    return priceMessage + "\n" + NumberFormat.getCurrencyInstance().format(quantity * pricePerCup);
}

@nagaawy
Copy link

nagaawy commented Dec 31, 2019

where to find the new code of the project of this course? as submitOrder..etc?

@pro-coder-fast
Copy link

public int displayQuantityA(int quantity,int price_of_per_coffee) {
int calculate = quantity * price_of_per_coffee;
return calculate;
}

@pro-coder-fast
Copy link

public int displayQuantityB() {
int calculate = quantity * 5;
return calculate;
}

@abhi0320
Copy link

abhi0320 commented Jun 3, 2021

public int displayQuantityB() {
int calculate = quantity * 5;
return calculate;
}

@ahmednajatusman
Copy link

public void submitOrder(View view) {
String priceMessage = "Free";
displayMessage(priceMessage);
}

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