How to returning multiple values from methods, JAVA Programming

Assignment Help:

How to Returning Multiple Values From Methods ?

It is not probable to return more than one value from techniques. You cannot, for example, return the licensePlate, speed and maxSpeed fields from a single technique. You could merge them within an object of a few type and return the object. Thus this would be poor object oriented design.

The right way to solve this problem is to describe three separate methods, getSpeed(), getMaxSpeed(), and getLicensePlate(), each of that returns its respective value. For example,
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

// getter (accessor) methods
String getLicensePlate() {
return this.licensePlate;
}

double getMaxSpeed() {
return this.maxSpeed;
}

double getSpeed() {
return this.speed;
}

// setter method for the license plate property
void setLicensePlate(String licensePlate) {
this.licensePlate = licensePlate;
}

// setter method for the maxSpeed property
void setMaximumSpeed(double maxSpeed) {
if (maxSpeed > 0) this.maxSpeed = maxSpeed;
else this.maxSpeed = 0.0;
}

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


Related Discussions:- How to returning multiple values from methods

Catch clause should be used to handle the exception, How does a try statem...

How does a try statement determine which catch clause should be used to handle the exception?

I need 3d globe application, I need 3D Globe (Android) application Proje...

I need 3D Globe (Android) application Project Description: Seeking a talented android programmer to prepare a simple app for Android tablet display which can feature a 3D glo

Data Structures Projects, I have three data structures projects that I need...

I have three data structures projects that I need help with.

Describe the relational operators in java, Describe the relational operator...

Describe the relational operators in java? Java has six relational operators which compare two numbers and return a boolean value. The relational operators are , > , , >=

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.

What is an intelligent system, What is an intelligent system? Intellige...

What is an intelligent system? Intelligent system is a SW programs or SW and HW systems designed to perform complex tasks employing strategies in which mimic some aspect of hum

Task priority and uses in scheduling, What do you mean by a task's priorit...

What do you mean by a task's priority and how can we use it in scheduling ?

Explanation of EM algorithm, try { pa="weblog"; pa...

try { pa="weblog"; pas="weblog"; Connection c; Statement st;

Spring application support, JAVA, JSF(primefaces), SPRING Application Suppo...

JAVA, JSF(primefaces), SPRING Application Support Project Description: We require some one to be part of our team's new development , it's small application but in future, ch

Retrieving file records randomly, how to retrieve multiple records randomly...

how to retrieve multiple records randomly from a file and store it in another file

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