Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
@Momen-a

This comment has been minimized.

Copy link

Momen-a commented Jul 5, 2016

I wrote this method and worked too :--
/**
* This method to calculate the price
* @param numberOfCoffees
* display price
_/
public void calculatePrice(int numberOfCoffees) {
displayPrice(numberOfCoffees_10);
}

and in the submitOrder method call it with this :--
calculatePrice(quantity);

:)

@himakiran

This comment has been minimized.

Copy link

himakiran commented Jul 31, 2016

@Momen-a should have been ..

displayPrice(numberOfCoffees*10);

@PrincePascal

This comment has been minimized.

Copy link

PrincePascal commented Nov 13, 2016

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

@jvitorcarvalho

This comment has been minimized.

Copy link

jvitorcarvalho commented Dec 10, 2016

I have a global in my MainActivity

int price = 5;

/**
* And this is my method with one parameter,
This method is called to calculate the price of the order
*/
private int calculatePrice(int quantity) {
int priceTotal = quantity * price;
return priceTotal;
}

@h-stoyanov

This comment has been minimized.

Copy link

h-stoyanov commented Feb 7, 2017

I have a global in my MainActivity
int price = 5;
This is not good idea, try to make your methods more customizable

@jcunanan05

This comment has been minimized.

Copy link

jcunanan05 commented Mar 6, 2017

thanks

@dburgosp

This comment has been minimized.

Copy link

dburgosp commented Mar 13, 2017

It strikes me that when you delete a parameter, Android Studio complains if it is still referenced within comments :O For example:

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

This comment has been minimized.

Copy link

krishsam02 commented Mar 14, 2017

public int calculatePrice(int numberOfCoffees,int price)
{
return numberOfCoffees=quantity * price;
}

@maniwut

This comment has been minimized.

Copy link

maniwut commented Mar 30, 2017

Working good. It's simplifies our work

@Meg2017

This comment has been minimized.

Copy link

Meg2017 commented Apr 2, 2017

I have modified calculatePrice and it worked fine.
/**
* Calculates the price of the order.
*
* @param quantity is the number of cups of coffee ordered
* @param priceOfCoffee is the price of one coffee ordered
*/
private void calculatePrice(int quantity, int priceOfCoffee) {
int price = quantity * priceOfCoffee;
}

@christianputzu

This comment has been minimized.

Copy link

christianputzu commented Apr 9, 2017

Thx for tips guys.

@rebekaszucs

This comment has been minimized.

Copy link

rebekaszucs commented Apr 10, 2017

It became clear with the explanation, good job!:)

@Vercsi

This comment has been minimized.

Copy link

Vercsi commented Apr 10, 2017

Thank you! :) 👍

@kyriacosar

This comment has been minimized.

Copy link

kyriacosar commented Apr 12, 2017

It works great for all three options as long as the qunatity variable is global. Awesome!

@fathead7466

This comment has been minimized.

Copy link

fathead7466 commented May 11, 2017

thanks!

@tangtang08

This comment has been minimized.

Copy link

tangtang08 commented Sep 13, 2017

I wrote it before looking at the code and I did it correctly! Yae!!

@davidjuhan

This comment has been minimized.

Copy link

davidjuhan commented Dec 6, 2017

Thanks

@ghost

This comment has been minimized.

Copy link

ghost commented Dec 17, 2017

Thanks

@chily11

This comment has been minimized.

Copy link

chily11 commented Dec 18, 2017

the second task gives an error msg "int, int". thats great am please with that result.

@nkemjikaevans

This comment has been minimized.

Copy link

nkemjikaevans commented Dec 21, 2017

/**
* Calculates the price of the order.
*
*/
private int calculatePrice() {
return quantity * 5;

@tslapczynski

This comment has been minimized.

Copy link

tslapczynski commented Dec 22, 2017

public void calculatePrice(int noOfCaffe) {
displayPrice(noOfCoffees* Q);
}

@TheLegendMac

This comment has been minimized.

Copy link

TheLegendMac commented Dec 26, 2017

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;
}
@Maxwe1

This comment has been minimized.

Copy link

Maxwe1 commented Feb 4, 2018

Thanks.

@Nogaeman

This comment has been minimized.

Copy link

Nogaeman commented Feb 10, 2018

Thanks :)

@abdahma01

This comment has been minimized.

Copy link

abdahma01 commented Feb 15, 2018

Many Thanks

@mamdogogo

This comment has been minimized.

Copy link

mamdogogo commented Feb 17, 2018

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;
    @override

    protected 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);

}

@wbadry

This comment has been minimized.

Copy link

wbadry commented Feb 20, 2018

@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;
    }
@badrddinb

This comment has been minimized.

Copy link

badrddinb commented Feb 26, 2018

DONE

@Syaj89

This comment has been minimized.

Copy link

Syaj89 commented Mar 3, 2018

Done too

@louayeldin

This comment has been minimized.

Copy link

louayeldin commented Mar 18, 2018

Done

@AsmaaMghodia

This comment has been minimized.

Copy link

AsmaaMghodia commented Mar 22, 2018

Done

@anouswazzan

This comment has been minimized.

Copy link

anouswazzan commented Mar 24, 2018

done

@lakshmiprasannatirumala

This comment has been minimized.

Copy link

lakshmiprasannatirumala commented Apr 1, 2018

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;
}

@moh585

This comment has been minimized.

Copy link

moh585 commented May 9, 2018

/**

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

This comment has been minimized.

Copy link

shoooka commented May 11, 2018

Done

@bhargavkonkathi

This comment has been minimized.

Copy link

bhargavkonkathi commented May 11, 2018

Done

@SaeedAlbaradie

This comment has been minimized.

Copy link

SaeedAlbaradie commented May 20, 2018

/**
* 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);

}

}

@Eduese

This comment has been minimized.

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

This comment has been minimized.

Copy link

mahmoudkashef commented Jun 9, 2018

thanks for the tips guys

@orwa-te

This comment has been minimized.

Copy link

orwa-te commented Jun 24, 2018

Very very simple

@wildseeker

This comment has been minimized.

Copy link

wildseeker commented Jun 26, 2018

done

@HDAII

This comment has been minimized.

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

This comment has been minimized.

Copy link

djalilo24 commented Mar 25, 2019

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

This comment has been minimized.

Copy link

MinaMagdyLuis commented Apr 15, 2019

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

@bgannon29

This comment has been minimized.

Copy link

bgannon29 commented May 31, 2019

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.