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

Linked list, i want code for to print prime numbers in the linked list queu...

i want code for to print prime numbers in the linked list queue and stack and array in java programming

Multiple choices output and codes, codes and output on how to make multiple...

codes and output on how to make multiple choices quiz

Rmi-iiop support dynamic downloading of classes, Does RMI-IIOP support dyna...

Does RMI-IIOP support dynamic downloading of classes? Ans) No, RMI-IIOP doesn't support dynamic downloading of the classes as it is complete with CORBA in DII (Dynamic Interface

For in statement, It is a distinct type of loop, used to iterate through th...

It is a distinct type of loop, used to iterate through the properties of an object or the elements of an array. For instance assume the following statement that loops through th

Neatbeens and glass fish, Assignment 3 Project Proposal Documentation Descr...

Assignment 3 Project Proposal Documentation Description Marks out of Wtg(%) Due date Assignment 3 100 35% 15/09/14 In the assignment we will start analysing and designing the

What does the abstract keyword mean in front of a method, What does the " a...

What does the " abstract " keyword mean in front of a method and a class ?

Java Login/Register Web CMS, I need help setting up and fleshing out a basi...

I need help setting up and fleshing out a basic outline/structure for a basic Java web app using an MVC pattern

What is switchaction, The SwitchAction class gives a means to switch from a...

The SwitchAction class gives a means to switch from a resource in one module to another resource in a dissimilar module. SwitchAction is useful only if you have multiple modules in

I want hall rental website, I want Hall Rental Website Project Descripti...

I want Hall Rental Website Project Description: I want to prepare website for my party venue where i will post the photos and detail of place along with availability calendar

How we declaring arrays in java language, How we Declaring Arrays in java l...

How we Declaring Arrays in java language? Like all other variables in Java, an array must have a exact type such as byte, int, String or double. Just variables of the appropria

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