Two Laptop Bag
The moose likes Beginning Java and the fly likes problem with method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with method" Watch "problem with method" New topic

problem with method

Ayukawa Madoka

Joined: Feb 28, 2004
Posts: 27
Hello everyone, my name is Erik. i am new to Java. I am confused by this methods here can anyone briefly explain every steps to me except for line 1 & 2 thank you.

public class DemoRaise {
public static void main(String[] args) {
double mySalary = 200.00;
System.out.println("Demonstrating some raises");
public static void predictRaise (double moneyAmount) { // why does moneyAmount is in the paranthesis? Can i just declare the moneyAmount variable same as how i declare the newAmount?
double newAmount;
newAmount = moneyAmount * 1.10;
System.out.println("With raise salary is " + newAmount);


The result for this method:
The result for this method click here
[ February 28, 2004: Message edited by: ayukawa madoka ]

hello everyone i'm new here.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Hello Erik, Welcome to JavaRanch...
What�s happening in these two lines:

is that the program is calling the method �predictRaise� which takes a double as a parameter. This is indicated in the signature of the predictRaise() method:

The moneyAmount in the parenthesis is the variable the method uses to hold the parameter it receives.
The predictRaise() method then makes a calculation (newAmount = moneyAmount * 1.10; ) on the value it received as a parameter (�moneyAmount�) and displays the results via a call to System.out.println()
At a very high-level, that is what is happening. Anything beyond that is a bit too much to get into via a forum like this, and is the core concepts to Object Oriented Programming and the Java Language. I suggest you read through some Beginning Java tutorials such as Sun�s The Java Tutorial or the electronic book Thinking in Java. There is also the online tutorial Introduction to Computer Science using Java. You can also look at purchasing the excellent book Head First Java. Any of these resources, or the many other Intro to Java Books out there (see this recent thread for some other suggestions), will explain what methods are, what they are used for, and what their parameters are and do.
Ayukawa Madoka

Joined: Feb 28, 2004
Posts: 27
oh that means i can reuse the method over and over again with a different value passed in. Yay thanks for the brief explanation and the tutorial links everyone!
I agree. Here's the link:
subject: problem with method
It's not a secret anymore!