Link to exercice: https://www.codecademy.com/courses/learn-java/projects/build-a-droid
I don’t understand why a return statment isn’t needed for int transferAmount
in the "// method in question"
. Thank you for your help.
public class Droid{
String name;
int batteryLevel = 100;
// Constractor method
public Droid(String droidName){
name = droidName;
}
//method in question
public void energyTransfer(Droid Droid1, int transfer, Droid Droid2){
// Why isnt a return needed for int transferAmount? This is the thing I dont understand.
int transferAmount = transfer + 10;
System.out.println(transferAmount);
// Why isnt a return needed for int transferAmount?
// ignore this, just putting the whole method
Droid1.batteryLevel = Droid1.batteryLevel - transfer;
Droid2.batteryLevel = Droid2.batteryLevel + transfer;
System.out.println("Alex's energy is now: " +Droid1.batteryLevel + " Codey's energy is now: " +Droid2.batteryLevel);
}
//main method
public static void main(String[] args){
Droid Codey = new Droid("Codey");
Droid Alex = new Droid("Alex");
Codey.energyTransfer(Codey, 10, Alex);