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

Create a generic class with a type parameter, 1. The purpose of this proble...

1. The purpose of this problem is to practice using generics.  Create a generic class with a type parameter that simulates drawing an item at random out of a box. For exampl

Difference between object state and behavior, What is difference between ob...

What is difference between object state and behavior? Ans) If you change the state of an object, you ask it to perform a behavior. An object kept its states in a field e.g. vari

Information retrieval during multi-agent system, Information Retrieval duri...

Information Retrieval during Multi-Agent System with Data Mining in Cloud Computing Project Description: I have proposed one research model on "Information Retrieval during M

Create a usercontrol called loginpasswordusercontrol, (Login User Control) ...

(Login User Control) Create a UserControl called LoginPasswordUserControl that contains a Label (loginLabel) that displays string "Login:", a TextBox (loginTextBox), where the user

State the java virtual machine and runtime environment, Java Virtual Machin...

Java Virtual Machine & Runtime Environment Basic Concept When you write a program in C++ it's called source code. C++ compiler converts this source code into the machine c

Implement a driver program to test out all constructors, Implement a class ...

Implement a class  Book  (Book.java). A book will have three instance variables: a  title  (a String, for example: "Big Java" or "The Hitchhiker's Guide to the Galaxy"), an  author

Minimumshelf, Write a program that finds the minimum total number of shelve...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process

SWING, Application using Swing API

Application using Swing API

Give the javascript code output, What is output of the following JavaScript...

What is output of the following JavaScript code? Str="Virtual University of Pakistan"; document.write(str.substring(5,str.length)) ;

String, in java string is a

in java string is a

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