Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I tried to fix my code but I still getting this error #140

Open
wareef09 opened this issue Apr 3, 2023 · 1 comment
Open

I tried to fix my code but I still getting this error #140

wareef09 opened this issue Apr 3, 2023 · 1 comment

Comments

@wareef09
Copy link

wareef09 commented Apr 3, 2023

No description provided.

@wareef09
Copy link
Author

wareef09 commented Apr 3, 2023

`import java.util.Random;
import java.util.Scanner;
public class VacuumAgent
{
public static char Reflex_Vacuum_Agent(char Location)
{
char otherLoc;//the next destination
char status;// the statues: [clean or dirty]
String input="DC";
int statesNumb=input.length();
Random r = new Random();
status=input.charAt(r.nextInt(statesNumb));//status gets C or D randomly
if(Location=='A')
otherLoc='B';
else
otherLoc='A';
if (status == 'D') { // the location is dirty
System.out.println("\n"+Location+ " [Detected-Dirty], clean and go to the location " + otherLoc);
return otherLoc;
}

if (status=='C') // The location is clean
{
if ( Location == 'A') {
System.out.println("\n"+Location+" [Detected-clean], Action: go to Location B");
return otherLoc; }
else if ( Location == 'B') { System.out.println("\n"+Location+" [Detected-clean], Action: go to Location A");
return otherLoc; }
}
System.out.println("Unexpected failure with detecting the location status,try again");
return Location;
}

public static void main(String []args)
{
int times;//The number of the Agent's actions
String input;
Character Location=new Character(' ');//to keep the agent's location
Scanner userInput=new Scanner(System.in);
System.out.print("Enter the location of the Agent(A[room] or B[room]): ");
input=userInput.nextLine();
Location =input.charAt(0);

if(!(Location.equals('A')||Location.equals('B')) )//check the correct input of the location
{
System.out.println("The location is wrong, run the program again");
System.exit(0);
}
System.out.println("The Agent starts at: " + Location);

System.out.println("Enter the number of the Agaent's actions: ");
times=userInput.nextInt();
int counter=0;
while ((counter++)!=times) {
Location=Reflex_Vacuum_Agent(Location);
}
}
}`

the error
Main.java:3: error: class VacuumAgent is public, should be declared in a file named VacuumAgent.java
public class VacuumAgent
^
Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant