java - Missing Return Statement Error Basic Program -


im writing small program class @ school , have run "missing return statement error." ive tried googling error see if can find generic answer might me nothing ive done code has been able rid of error program can compile. reference, here assignment program trying write:

you have been commissioned navy develop system tracking amount of fuel consumed fleets of ships. each ship has name (ex: "uss montana"), fuel capacity (the maximum amount of fuel ship can carry), , amount of fuel onboard. in problem, fuel measured in "units" , capacity of each ship integer number (ex: carrier's capacity 125 fuel units). each fleet has 4 ships in it. when fleet deployed, each ship in fleet deployed. when ship deployed, consumes half of fuel has onboard. when fleet refueled, each ship in fleet refueled. when ship refueled, totally filled (its onboard amount equals capacity)

and here code:

/**  * navy ship descriptions  *   * @author elizabeth rehbein  * @version 01/28/16  */ public class ship {      // instance variables      private string name;        //ship name     private double fuelcapacity;       //ship fuel capacity     private double fuelcurrent;  //the ship's current fuel on ship after deployments     private double fuelconsumed;   //the amount of fuel ship has consumed after deployments       //constructor     public ship(string startname, double startfuelcapacity, double startfuelcurrent, double startfuelconsumed)     {         // initialise instance variables         name=startname;         fuelcapacity=startfuelcapacity;         fuelcurrent=startfuelcurrent;         fuelconsumed=startfuelconsumed;     }     //get methods     public string getname()     {         return name;    //returns name of ship being called     }      public double getfuelcapacity()     {         return fuelcapacity;    //the ship's fuel tank capacity     }      public double getfuelcurrent()     {         return fuelcurrent; //returns fuel ship has before being refilled     }      public double getfuelconsumed()     {         return fuelconsumed;               //returns fuel consumed ship     }      public void deploy()     {         fuelcurrent = fuelcurrent/2;     //reduces ships current fuel half every depolyment         fuelconsumed += fuelcapacity/2;  //adds fuel used in depolyment fuelconsumed track total fuel used     }      public double refuel()     //refueling each ship returns full fuel capacity     {         fuelcurrent = fuelcapacity;     }    }     /**  * fleet of navy ships.  *   * @author elizabeth rehbein   * @version 02/05/16  */ public class fleet {     // instance variables      private ship ship1;     //ship1 in fleet     private ship ship2;     //ship2 in fleet     private ship ship3;     //ship3 in fleet     private ship ship4;     //ship4 in fleet      //constructor     public fleet(ship inship1, ship inship2, ship inship3, ship inship4)     {         ship1=inship1;         ship2=inship2;         ship3=inship3;         ship4=inship4;     }       //deploys ships     public void deploy()     {         ship1.deploy();         ship2.deploy();         ship3.deploy();         ship4.deploy();     }      //refuels ships after deployment     public void refuel()     {         ship1.refuel();         ship2.refuel();         ship3.refuel();         ship4.refuel();     }      //prints out fuel consumed each ship in fleet     public double printsummary()     //prints out fuelconsumed each ship     {     system.out.println(ship1.getname() +" 's total fuel consumption " + ship1.getfuelconsumed());     system.out.println(ship2.getname() +" 's total fuel consumption " + ship2.getfuelconsumed());     system.out.println(ship3.getname() +" 's total fuel consumption " + ship3.getfuelconsumed());     system.out.println(ship3.getname() +" 's total fuel consumption " + ship4.getfuelconsumed());    } }  /**  * driver outlab2.  */ public class driver {     public static void main(string[] args)     {         //creating 4 instances of ship         ship ship1 = new ship("carrier", 150);         ship ship2 = new ship("anti-submarine", 35);         ship ship3 = new ship("patrol", 22);         ship ship4 = new ship("destroyer", 83);          //creating instance of fleet         fleet fleet1 = new fleet(ship1, ship2, ship3, ship4);          //deploying fleet twice         fleet1.deploy();         fleet1.deploy();          //refuel fleet once         fleet1.refuel();          //print summary         fleet1.printsummary();     } } 

also, not supposed alter driver assignment.

let me know thoughts may have gone wrong. cheers!

here:

public double refuel()     //refueling each ship returns full fuel capacity     {         fuelcurrent = fuelcapacity;     } 

and here:

//prints out fuel consumed each ship in fleet     public double printsummary()     //prints out fuelconsumed each ship     {     system.out.println(ship1.getname() +" 's total fuel consumption " + ship1.getfuelconsumed());     system.out.println(ship2.getname() +" 's total fuel consumption " + ship2.getfuelconsumed());     system.out.println(ship3.getname() +" 's total fuel consumption " + ship3.getfuelconsumed());     system.out.println(ship3.getname() +" 's total fuel consumption " + ship4.getfuelconsumed());    } 

you have 2 methods, have said return double in body there no return a_doube. fix them adding return statement or make them void depends on problem.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -