How does the 'amount' parameter in the recordPurchase method work?

  • Context: Java 
  • Thread starter Thread starter whitehorsey
  • Start date Start date
  • Tags Tags
    Java Parameters
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
whitehorsey
Messages
188
Reaction score
0
I'm having trouble with understanding how methods that have a parameter work.
For example,
public class Register
{
private double purchase;
private double payment;
public static final double QUARTER_VALUE = 0.25;
public static final double DIME_VALUE = 0.1;
public static final double NICKEL_VALUE = 0.05;
public static final double PENNY_VALUE = 0.01;


public Register()
{
purchase = 0;
payment = 0;
}

public void recordPurchase(double amount)
{
double newTotal = purchase + amount;
purchase = newTotal;
}

What does the value amount in the parameters equal? Is it 0?
 
Physics news on Phys.org
The amount parameter is a placeholder for whatever value is used as the actual parameter when the method is called.

What you have is merely the definition of the recordPurchase method. It would be called like this.
Code:
Register reg = new Register(); // Create a Register object.
reg.recordPurchase(25.0);
Inside the method the first time it is called, newTotal would be set to 25.0 + 0.0, and purchase would be set to 25.0.