Я новичок в java, и мне дали 3 файла, но я не знаю, как их скомпилировать, чтобы заставить их работать вместе.
Вот файлы:
GetBurnRate . java
import java.io.*;
public class GetBurnRate{
public static void main(String[] args){
//Send welcome message
System.out.println("#Welcome to Lunar Lander");
try{
//Begin reading from System input
BufferedReader inputReader =
new BufferedReader(new InputStreamReader(System.in));
//Set initial burn rate to 0
int burnRate = 0;
do{
//Prompt user
System.out.println("#Enter burn rate or <0 to quit:");
//Read user response
try{
String burnRateString = inputReader.readLine();
burnRate = Integer.parseInt(burnRateString);
//Send user-supplied burn rate to next filter
System.out.println("%" + burnRate);
} catch(NumberFormatException nfe){
System.out.println("#Invalid burn rate.");
}
}
while(burnRate >= 0);
inputReader.close();
} catch(IOException ioe){
ioe.printStackTrace();
}
}
}
CalcNewValues. java
import java.io.*;
public class CalcNewValues{
public static void main(String[] args){
//Initialize values
final int GRAVITY = 2;
int altitude = 1000;
int fuel = 500;
int velocity = 70;
int time = 0;
try{
BufferedReader inputReader = new
BufferedReader(new InputStreamReader(System.in));
//Print initial values
System.out.println("%a" + altitude);
System.out.println("%f" + fuel);
System.out.println("%v" + velocity);
System.out.println("%t" + time);
String inputLine = null;
do{
inputLine = inputReader.readLine();
if((inputLine != null) &&
(inputLine.length() > 0)){
if(inputLine.startsWith("#")){
//This is a status line of text, and
//should be passed down the pipeline
System.out.println(inputLine);
}
else if(inputLine.startsWith("%")){
//This is an input burn rate
try{
int burnRate =
Integer.parseInt(inputLine.substring(1));
if(altitude <= 0){
System.out.println("#The game is over.");
}
else if(burnRate > fuel){
System.out.println("#Sorry, you don't" +
"have that much fuel.");
}
else{
//Calculate new application state
time = time + 1;
altitude = altitude - velocity;
velocity = ((velocity + GRAVITY) * 10 -
burnRate * 2) / 10;
fuel = fuel - burnRate;
if(altitude <= 0){
altitude = 0;
if(velocity <= 5){
System.out.println("#You have" +
"landed safely.");
}
else{
System.out.println("#You have" +
"crashed.");
}
}
}
//Print new values
System.out.println("%a" + altitude);
System.out.println("%f" + fuel);
System.out.println("%v" + velocity);
System.out.println("%t" + time);
}
catch(NumberFormatException nfe){
}
}
}
}
while((inputLine != null) && (altitude > 0));
inputReader.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
}
DisplayValues.java
import java.io.*;
public class DisplayValues{
public static void main(String[] args){
try{
BufferedReader inputReader = new
BufferedReader(new InputStreamReader(System.in));
String inputLine = null;
do{
inputLine = inputReader.readLine();
if((inputLine != null) &&
(inputLine.length() > 0)){
if(inputLine.startsWith("#")){
//This is a status line of text, and
//should be passed down the pipeline with
//the pound-sign stripped off
System.out.println(inputLine.substring(1));
}
else if(inputLine.startsWith("%")){
//This is a value to display
if(inputLine.length() > 1){
try{
char valueType = inputLine.charAt(1);
int value =
Integer.parseInt(inputLine.substring(2));
switch(valueType){
case 'a':
System.out.println("Altitude: " +
value);
break;
case 'f':
System.out.println("Fuel remaining: " +
value);
break;
case 'v':
System.out.println("Current Velocity: "
+ value);
break;
case 't':
System.out.println("Time elapsed: " +
value);
break;
}
}
catch(NumberFormatException nfe){
}
}
}
}
}
while(inputLine != null);
inputReader.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
}
Затем я должен изменить GetCalcNewValues. java и перевести его на C ++ и заставить его работать так :
| GetBurnRate. java | GetCalcNewValues. cpp | DisplayValues. java
Мне нужно только знать, как правильно их компилировать, я могу сделать перевод.