Initializing A Value Before the Constructor – Java #57

*Watch copying and pasting the quotation marks, you may have to retype them to avoid an error

Sometimes every function of a class will need the same variable so initializing a value before the constructor gives it to all of them.

First Page contains only the Main Function

//Programmer:Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Initialize A Value Before A Constructor

package DagbaSamples;

//Beginning of Class samples DagbaComputers (contains Main)
public class samples_DagbaComputers
{
//Beginning of Main Function
public static void main(String[] args)
{

//Making a starfleet object
starFleet basicShip = new starFleet();

//Printing out justCrew Speed to Test
System.out.printf(“If the ship is empty except for the crew speed = ” + basicShip.justCrew() + “\n”);

//Printing out Full Cargo Speed to Test
System.out.printf(“If the ship is full of stuff speed = ” + basicShip.fullCargo() + “\n”);

}
//end of main Function

}
//End of Class samples DagbaComputers (contains Main)

========================Second Page is the starFleet class=======================
)
{

}

//fullCargo Speed Function
public double fullCargo()
{
//decreasing emptySpeed by 2 to make the new cargoFullSpeed
double cargoFullSpeed = emptySpeed -2;

//Returning new cargoFullSpeed
return cargoFullSpeed;
}
//End of Full Cargo

//justCrew Speed Function
public double justCrew()
{
//Decreasing emptySpeed
double justCrewSpeed = emptySpeed – 0.5;

//Returning new justCrewSpeed
return justCrewSpeed;
}
//End of justCrew
}//End of starFleet Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: