Give an example for passing arguments to methods, JAVA Programming

Assignment Help:

Give an example for Passing Arguments to Methods ?

class Car {

String licensePlate = ""; // e.g. "New York 543 A23"
double speed = 0.0; // in kilometers per hour
double maxSpeed = 123.45; // in kilometers per hour

// accelerate to maximum speed
// put the pedal to the metal
void floorIt() {
this.speed = this.maxSpeed;
}

void accelerate(double deltaV) {

this.speed = this.speed + deltaV;
if (this.speed > this.maxSpeed) {
this.speed = this.maxSpeed;
}
if (this.speed < 0.0) {
this.speed = 0.0;
}

}

}

class CarTest4 {

public static void main(String[] args) {

Car c = new Car();

c.licensePlate = "New York A45 636";
c.maxSpeed = 123.45;

System.out.println(c.licensePlate + " is moving at " + c.speed +
" kilometers per hour.");

for (int i = 0; i < 15; i++) {
c.accelerate(10.0);
System.out.println(c.licensePlate + " is moving at " + c.speed +
" kilometers per hour.");
}

}

}
Here's the output:
utopia% java CarTest4
New York A45 636 is moving at 0.0 kilometers per hour.
New York A45 636 is moving at 10.0 kilometers per hour.
New York A45 636 is moving at 20.0 kilometers per hour.
New York A45 636 is moving at 30.0 kilometers per hour.
New York A45 636 is moving at 40.0 kilometers per hour.
New York A45 636 is moving at 50.0 kilometers per hour.
New York A45 636 is moving at 60.0 kilometers per hour.
New York A45 636 is moving at 70.0 kilometers per hour.
New York A45 636 is moving at 80.0 kilometers per hour.
New York A45 636 is moving at 90.0 kilometers per hour.
New York A45 636 is moving at 100.0 kilometers per hour.
New York A45 636 is moving at 110.0 kilometers per hour.
New York A45 636 is moving at 120.0 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.


Related Discussions:- Give an example for passing arguments to methods

What is prototype, Prototype is having multiple instances or having clone.

Prototype is having multiple instances or having clone.

Describe life cycle of thread, Describe life cycle of thread. Threads f...

Describe life cycle of thread. Threads follow the single flow of control. A thread is execution in a program. The life cycles of threads are listed below: Newborn state: A

Explain what is fontmetrics in java, Explain what is FontMetrics in Java? ...

Explain what is FontMetrics in Java? No word wrapping is completed when you draw a string in an applet, even if you embed newlines in the string along with \n. If you expect th

What is the jsf, JavaServer Faces(JSF) is a framework for building web-base...

JavaServer Faces(JSF) is a framework for building web-based user interface in Java. Unlike Swing, JSF provides widgets like buttons, hyperlinks, checkboxes, etc. in dissimilar ways

Describe importing classes in java, Describe Importing Classes in java? ...

Describe Importing Classes in java? Fully qualified names such as java.net.URL are not the most convenient thing to have to type. You can use the shorter class names like URL w

Payrol, design a payrol (non GUI)

design a payrol (non GUI)

Questions pseudocodes, 1. Write the pseudocode to get the input of 10 integ...

1. Write the pseudocode to get the input of 10 integers from the user and add them up and output the total. (4 points) 2. Compute the output of following pseudocode. Assume that

Pattern printing program, Question Using 3 level of nested for loop, writ...

Question Using 3 level of nested for loop, write a program that will produce the output as below.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd