Question: Help me fix this code to run in java ONLY. This is a ecosystem game I created public class Game { private boolean running; private

Help me fix this code to run in java ONLY. This is a ecosystem game I created
public class Game {
private boolean running;
private int water;
private int soilHealth;
private int biodiversity;
private int pollution;
private String currentScene;
/**
* Constructor to initialize game state.
*/
public Game(){
this.running = true;
this.water =100;
this.soilHealth =100;
this.biodiversity =100;
this.pollution =0;
this.currentScene = "MainMenu";
}
/**
* Starts the game loop.
*/
public void start(){
Scanner scanner = new Scanner(System.in);
while (running){
switch (currentScene){
case "MainMenu":
showMainMenu();
break;
case "ResourceManagement":
showResourceManagement();
break;
case "EcosystemStatus":
showEcosystemStatus();
break;
case "Exit":
exit();
return;
default:
System.out.println("Unknown scene: "+ currentScene);
running = false;
return;
}
int choice = scanner.nextInt();
handleChoice(choice);
}
scanner.close();
}
/**
* Displays the main menu.
*/
private void showMainMenu(){
System.out.println("Welcome to EcoGame");
System.out.println("1. Manage Resources");
System.out.println("2. Check Ecosystem Status");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
}
/**
* Handles the user's choice at the main menu.
*
* @param choice the user's menu choice
*/
private void handleChoice(int choice){
switch (currentScene){
case "MainMenu":
switch (choice){
case 1:
currentScene = "ResourceManagement";
break;
case 2:
currentScene = "EcosystemStatus";
break;
case 3:
currentScene = "Exit";
break;
default:
System.out.println("Invalid choice. Please try again.");
}
break;
case "ResourceManagement":
manageResources(choice);
break;
case "EcosystemStatus":
currentScene = "MainMenu";
break;
}
}
/**
* Displays the resource management scene.
*/
private void showResourceManagement(){
System.out.println("Manage Resources:");
System.out.println("1. Add Water");
System.out.println("2. Improve Soil Health");
System.out.println("3. Promote Biodiversity");
System.out.println("4. Reduce Pollution");
System.out.println("5. Return to Main Menu");
System.out.print("Enter your choice: ");
}
/**
* Manages resources based on the user's choice.
*
* @param action the user's resource management choice
*/
private void manageResources(int action){
switch (action){
case 1:
water +=10;
System.out.println("You added water. Water level increased by 10.");
break;
case 2:
soilHealth +=10;
System.out.println("You improved soil health. Soil health increased by 10.");
break;
case 3:
biodiversity +=10;
System.out.println("You promoted biodiversity. Biodiversity increased by 10.");
break;
case 4:
pollution -=10;
System.out.println("You reduced pollution. Pollution decreased by 10.");
break;
case 5:
currentScene = "MainMenu";
return;
default:
System.out.println("Invalid action. Please try again.");
}
System.out.println("Resource management complete.");
}
/**
* Displays the ecosystem status.
*/
private void showEcosystemStatus(){
System.out.println("Ecosystem Status:");
System.out.println("Water: "+ water);
System.out.println("Soil Health: "+ soilHealth);
System.out.println("Biodiversity: "+ biodiversity);
System.out.println("Pollution: "+ pollution);
System.out.println("Press any key to return to the main menu.");
}
/**
* Handles game events (placeholder for future event logic).
*/
private void handleEvents(){
// Placehold

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!