-
-
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 what I used:
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
String priceMessage = "Hi Mac! \nYour total for \n" + quantity + " cup of java is $" + calculatePrice() + "\n Thank you!";
priceTextView.setText(priceMessage);
}
/**
* Calculates the price of the order.
*
* @return total price
*/
private int calculatePrice() {
int price = quantity * 5;
return price;
}
Thanks.
Thanks :)
Many Thanks
package com.example.kisho.viewbutton;
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;
@OverRideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}public void increment(View view) {
quantity = quantity + 1; displayQuantity(quantity);
}
/**- This method decrement displays the increase int on the screen.
/
public void decrement(View view) {
quantity = quantity - 1;
displayQuantity (quantity);
}
/* - This method is called when the order button is clicked.
- here displayMessage is the verbal
*/
public void submitOrder(View view) {
String price = "Total: $" + calculatePrice(quantity);
displayMessage(price + "\n Thank You!");calculatePrice(quantity);
}
private int calculatePrice(int quantity) {
return quantity * 5;
}
/**- This method displays the given quantity value on the screen.
/
private void displayQuantity(int number) {
TextView quantityTextView = (TextView)
findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/* - This method displays the given price on the screen.
*/
/**
- This method increment displays the increase int on the screen.
*/
private void displayMessage(String message){
TextView PriceTextView = (TextView)
findViewById(R.id.price_text_view);
PriceTextView.setText(message);
- This method decrement displays the increase int on the screen.
}
@PrincePascal a shortest version would be
/**
* Calculates the price of the order.
*
* @param quantity is the number of cups of coffee ordered
*/
private int calculatePrice(int quantity) {
return quantity * 5;
}
DONE
Done too
Done
Done
done
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);
}
public void calculatePrice(int noOfCaffe) {
displayPrice(noOfCoffees* Q);
}