I have two classes, one that only has a main(String args[])
method and one with all the rest. I am trying to get the data from the main method into the second class to run it, and then give the information back to the main method. My program is compiling but the numbers should be going down each time I input new number, but they are not. Any help is appreciated!
public class LunarLander
{
public static void move(double efficiency, double fuelLeft, int maxFuel, int time, double Altitude, double inputFuelRate)
{
//formulas to change outputs
double velocity = time * (efficiency - 1.62); //given formula to caluculate velocity
double altChng = time * velocity; //creates a variable for atitude chage
//exceptions
if (efficiency > 0 && fuelLeft == 0){ //changes efficiency to 0 when there is no fuel left
efficiency = 0;
}
else{
}
//new outputs
Altitude = Altitude - altChng; //calculates new altitude by subtracting altitude change
velocity = time * (efficiency - 1.62); //given formula to caluculate velocity
altChng = time * velocity; //creates a variable for atitude chage
double verticalSpeed = velocity; //since the ship would only move and not go back and forth velocity is speed
efficiency = inputFuelRate / maxFuel; //recalculates efficiency
double fuelLoss = time * fuelLeft * maxFuel;// new variable to determine how much fuel was burned during time period
fuelLeft = fuelLeft - fuelLoss; //changes the values for fuel left
}
public static boolean crashed(double Altitude, double verticalSpeed)
{
if (Altitude == 0 && verticalSpeed <-1){
return true;
}
else{
return false;
}
}
public String toString(double Altitude, double verticalSpeed, double fuelLeft){
String output = "";
output += "Eagle: \n";
output += "Altitude = " + Altitude + "\n";
output += "Speed = " + verticalSpeed + "\n";
output += "Fuel = " + fuelLeft + "\n";
return output;
}
}
main method:
import java.util.Scanner;
public class Pilot
{
public static void main(String args[])
{
Scanner kb = new Scanner(System.in);
LunarLander lander = new LunarLander(); // create a LunarLander object
double Altitude = 10.0;
String Name = "Eagle";
double fuelLeft = 1000.0;
int shipWeight = 400;
int maxThrust = 10000;
int verticalSpeed = 0;
double efficiency = 0;
int maxFuel = 400; //max fuel flow
System.out.println("Initial data: ");
System.out.println("Altitude = " + Altitude);
System.out.println("Speed = " + verticalSpeed);
System.out.println("Fuel = " + fuelLeft);
while (lander.crashed(Altitude, verticalSpeed) != true && Altitude > 0)
{
System.out.println("Please enter a time in seconds: ");
int time = kb.nextInt();
System.out.println("Please enter a fuel rate between 0 and 1");
double inputFuelRate = kb.nextDouble();
System.out.println("Input time increment: " + time);
System.out.println("Input fuel rate: " + inputFuelRate);
lander.move(efficiency, fuelLeft, maxFuel, time, Altitude, inputFuelRate);
System.out.println(lander.toString(Altitude, verticalSpeed, fuelLeft));
}
}
}