-
-
Save udacityandroid/efc863aff5c2ff5784ce to your computer and use it in GitHub Desktop.
/** | |
* 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; | |
} |
This is my code to calculate price of coffees.
int quan=2;
public void submitOrder(View view)
{
String pm="Your order is "+quan+"\n Your order is ready\n";
pm=pm + " Total is $"+ calculatePrice();
pm=pm+" \n thank you visit again ";
displayMessage(pm);
}
public void increment(View view)
{
quan=quan+1;
display(quan);
}
public void decrement(View view)
{
display(quan=quan-1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.one_text_view);
quantityTextView.setText("" + number);
}
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.dollar_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.dollar_text_view);
priceTextView.setText(message);
}
private int calculatePrice() {
int price = quan * 10;
return price;
}
Done
Done
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int price = quantity * 5;
//String priceMessage = "That would be $" + price + " please";
//String priceMessage = "You owe" +" "+ price + " bucks, dude!";
//String priceMessage = price + " dollars for " + quantity + " cups of coffee. Pay up.";
//String priceMessage = "Total: $" + price + "\n" + "Thank You!";
String priceMessage = "Total: $" + price;
//priceMessage = priceMessage + " Thank you!";
priceMessage = priceMessage + "\nThank you!";
displayMessage(priceMessage);
//calculatePrice(quantity);
// calculatePrice(quantity, 10);
calculatePrice();
}
/**
* Calculates the price of the order.
*
* @param quantity is the number of cups of coffee ordered
* @param pricePerCup is the price of one cup of coffee
*/
//private void calculatePrice(int quantity ) {
//private void calculatePrice(int quantity, int pricePerCup){
private void calculatePrice(){
int price = quantity * 5;
//int price = quantity * pricePerCup;
}
/**
* 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);
}
}
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
thanks for the tips guys
Very very simple
done
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;
}
please help me
I can not find the just java app code to solve this test
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);
}
where to find the new code of the project of this course? as submitOrder..etc?
public int displayQuantityA(int quantity,int price_of_per_coffee) {
int calculate = quantity * price_of_per_coffee;
return calculate;
}
public int displayQuantityB() {
int calculate = quantity * 5;
return calculate;
}
public int displayQuantityB() {
int calculate = quantity * 5;
return calculate;
}
public void submitOrder(View view) {
String priceMessage = "Free";
displayMessage(priceMessage);
}
done