SlideShare a Scribd company logo
package lab7;
import java.util.Scanner;
//Sammy Student, Programmer
public class Maze
{
static Scanner sc = new Scanner(System.in);
// maze movements
static char myMove = '0';
// cell position
static int currentCell = 0;
static int score = 0;
static boolean advance = true;
static boolean checkThis = false;
public static void main(String args[])
{
// the local variables declared and initialized
char answer = 'Y';
displayMenu();
while(answer == 'Y' || answer == 'y')
{
displayMovement();
makeYourMove();
checkThis = checkYourMove();
mazeStatus();
System.out.println("move again(Y or N)?");
answer = sc.next().charAt(0);
}
System.out.println("***************************");
}// end main() method
static void displayMenu()
{
System.out.println("");
System.out.println("***************************");
System.out.println("----The Maze Strategy---");
System.out.println("");
}// end method
static void displayMovement()
{
if(currentCell == 0)
{
System.out.println("You have entered the maze!!");
System.out.println("There is no turning back!!");
currentCell = 1;
mazeStatus();
advance = true;
}
System.out.println("make your move (W, A, S, D)");
System.out.println("W = up, A = left, S = down, D = right)");
}// end method
static void makeYourMove()
{
myMove = sc.next().charAt(0);
switch(myMove)
{
case 'W': { MoveUp(); break; }
case 'A': { MoveLeft(); break; }
case 'S': { MoveDown(); break; }
case 'D': { MoveRight(); break; }
}
// end program menu
}// end method
static boolean checkYourMove()
{
if(currentCell == 1 && advance == true)
{
if (myMove == 'W')
{
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A')
{
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D')
{
currentCell = 2;
advance = true;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S')
{
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
if(currentCell == 2 && advance == true)
{
if (myMove == 'W')
{
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A')
{
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D')
{
advance = false;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S')
{
currentCell = 5;
advance = true;
System.out.println("continue through the maze");
return advance;
}
}
return advance;
// end program menu
}// end method
static void MoveLeft()
{
System.out.println("you moved to the left");
}//end method
static void MoveRight()
{
System.out.println("you moved to the right");
}//end method
static void MoveUp()
{
System.out.println("you moved up (forward)");
}//end method
static void MoveDown()
{
System.out.println("you moved down (downward)");
}//end method
static void mazeStatus()
{
System.out.println("current position: cell " + currentCell);
}//end method
}// end class
Modifythe above code like this:
Supplement the checkYourMove() method by including the remaining if statements that allow
the maze participant to escape the maze.
1. if(currentCell== 5 &&advance==true)
{
. . .
}
if(currentCell== 6 &&advance==true)
{
. . .
}
if(currentCell== 9 &&advance==true)
{
. . .
}
2. utilize the score variable to assign a score to each move. Also for extra credit you can track the
number of moves that the user makes in their escape of the maze.
Solution
Please follow the code and comments for description :
CODE :
import java.util.Scanner;
//Sammy Student, Programmer
public class Maze { // class that runs the code
static Scanner sc = new Scanner(System.in);
// maze movements
static char myMove = '0';
// cell position
static int currentCell = 0;
static int score = 0;
static boolean advance = true;
static boolean checkThis = false;
public static void main(String args[]) {
// the local variables declared and initialized
char answer = 'Y';
displayMenu();
while (answer == 'Y' || answer == 'y') {
displayMovement();
makeYourMove();
checkThis = checkYourMove();
mazeStatus();
System.out.println("move again(Y or N)?");
answer = sc.next().charAt(0);
}
System.out.println("***************************");
System.out.println("Total Moves Done : "+score);
}// end main() method
static void displayMenu() {
System.out.println("");
System.out.println("***************************");
System.out.println("----The Maze Strategy---");
System.out.println("");
}// end method
static void displayMovement() {
if (currentCell == 0) {
System.out.println("You have entered the maze!!");
System.out.println("There is no turning back!!");
currentCell = 1;
mazeStatus();
advance = true;
}
System.out.println("make your move (W, A, S, D)");
System.out.println("(W = up, A = left, S = down, D = right)");
}// end method
static void makeYourMove() {
myMove = sc.next().charAt(0);
score++;
switch (myMove) {
case 'W': {
MoveUp();
break;
}
case 'A': {
MoveLeft();
break;
}
case 'S': {
MoveDown();
break;
}
case 'D': {
MoveRight();
break;
}
}
// end program menu
}// end method
static boolean checkYourMove() {
if (currentCell == 1 && advance == true) {
if (myMove == 'W') {
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A') {
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D') {
currentCell = 2;
advance = true;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S') {
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
if (currentCell == 2 && advance == true) {
if (myMove == 'W') {
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A') {
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D') {
advance = false;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S') {
currentCell = 5;
advance = true;
System.out.println("continue through the maze");
return advance;
}
}
if (currentCell == 5 && advance == true) {
if (myMove == 'W') {
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A') {
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D') {
currentCell = 6;
advance = true;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S') {
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
if (currentCell == 6 && advance == true) {
if (myMove == 'W') {
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A') {
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D') {
currentCell = 9;
advance = true;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S') {
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
if (currentCell == 9 && advance == true) {
if (myMove == 'W') {
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A') {
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D') {
currentCell = 9;
advance = false;
System.out.println("Escaped Through the Maze.!");
return advance;
}
if (myMove == 'S') {
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
return advance;
// end program menu
}// end method
static void MoveLeft() {
System.out.println("you moved to the left");
}//end method
static void MoveRight() {
System.out.println("you moved to the right");
}//end method
static void MoveUp() {
System.out.println("you moved up (forward)");
}//end method
static void MoveDown() {
System.out.println("you moved down (downward)");
}//end method
static void mazeStatus() {
System.out.println("current position: cell " + currentCell);
}//end method
}// end class
OUTPUT :
***************************
----The Maze Strategy---
You have entered the maze!!
There is no turning back!!
current position: cell 1
make your move (W, A, S, D)
(W = up, A = left, S = down, D = right)
D
you moved to the right
continue through the maze
current position: cell 2
move again(Y or N)?
Y
make your move (W, A, S, D)
(W = up, A = left, S = down, D = right)
S
you moved down (downward)
continue through the maze
current position: cell 5
move again(Y or N)?
Y
make your move (W, A, S, D)
(W = up, A = left, S = down, D = right)
D
you moved to the right
continue through the maze
current position: cell 6
move again(Y or N)?
Y
make your move (W, A, S, D)
(W = up, A = left, S = down, D = right)
D
you moved to the right
continue through the maze
current position: cell 9
move again(Y or N)?
Y
make your move (W, A, S, D)
(W = up, A = left, S = down, D = right)
D
you moved to the right
Escaped Through the Maze.!
current position: cell 9
move again(Y or N)?
N
***************************
Total Moves Done : 5
Hope this is helpful.

More Related Content

Similar to package lab7; import java.util.Scanner; Sammy Student, Program.pdf

Java programs
Java programsJava programs
Import java
Import javaImport java
Import java
heni2121
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android Testing
Saúl Díaz González
 
A Case for "Piggyback" Runtime Monitoring
A Case for "Piggyback" Runtime MonitoringA Case for "Piggyback" Runtime Monitoring
A Case for "Piggyback" Runtime Monitoring
Sylvain Hallé
 
(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf
f3apparelsonline
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
allystraders
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
Sylvain Hallé
 
Objectives In this lab you will review passing arrays to methods and.pdf
Objectives In this lab you will review passing arrays to methods and.pdfObjectives In this lab you will review passing arrays to methods and.pdf
Objectives In this lab you will review passing arrays to methods and.pdf
f3apparelsonline
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
forwardcom41
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
mercysuttle
 
Im getting List Full when I try to add 2nd student.Driver..pdf
Im getting List Full when I try to add 2nd student.Driver..pdfIm getting List Full when I try to add 2nd student.Driver..pdf
Im getting List Full when I try to add 2nd student.Driver..pdf
forwardcom41
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
Rebecca Murphey
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
 

Similar to package lab7; import java.util.Scanner; Sammy Student, Program.pdf (18)

Java programs
Java programsJava programs
Java programs
 
Import java
Import javaImport java
Import java
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android Testing
 
A Case for "Piggyback" Runtime Monitoring
A Case for "Piggyback" Runtime MonitoringA Case for "Piggyback" Runtime Monitoring
A Case for "Piggyback" Runtime Monitoring
 
(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Objectives In this lab you will review passing arrays to methods and.pdf
Objectives In this lab you will review passing arrays to methods and.pdfObjectives In this lab you will review passing arrays to methods and.pdf
Objectives In this lab you will review passing arrays to methods and.pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
 
Im getting List Full when I try to add 2nd student.Driver..pdf
Im getting List Full when I try to add 2nd student.Driver..pdfIm getting List Full when I try to add 2nd student.Driver..pdf
Im getting List Full when I try to add 2nd student.Driver..pdf
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 

More from infoeyecare

All fungi have tiny tube-like structures call hyphae. One is labeled .pdf
All fungi have tiny tube-like structures call hyphae. One is labeled .pdfAll fungi have tiny tube-like structures call hyphae. One is labeled .pdf
All fungi have tiny tube-like structures call hyphae. One is labeled .pdf
infoeyecare
 
15. Let’s say you are systems administrator for a hospital’s network.pdf
15. Let’s say you are systems administrator for a hospital’s network.pdf15. Let’s say you are systems administrator for a hospital’s network.pdf
15. Let’s say you are systems administrator for a hospital’s network.pdf
infoeyecare
 
What would the predicted result be if Griffith injected mice with a .pdf
What would the predicted result be if Griffith injected mice with a .pdfWhat would the predicted result be if Griffith injected mice with a .pdf
What would the predicted result be if Griffith injected mice with a .pdf
infoeyecare
 
Write a function called myfind that will search for a key in a vecto.pdf
Write a function called myfind that will search for a key in a vecto.pdfWrite a function called myfind that will search for a key in a vecto.pdf
Write a function called myfind that will search for a key in a vecto.pdf
infoeyecare
 
wright Mills proposed that sociologists could explain individual beha.pdf
wright Mills proposed that sociologists could explain individual beha.pdfwright Mills proposed that sociologists could explain individual beha.pdf
wright Mills proposed that sociologists could explain individual beha.pdf
infoeyecare
 
Why are General, Special Revenue, and other governmental (expendable).pdf
Why are General, Special Revenue, and other governmental (expendable).pdfWhy are General, Special Revenue, and other governmental (expendable).pdf
Why are General, Special Revenue, and other governmental (expendable).pdf
infoeyecare
 
Which functions of a cell membrane would be compromised if the membr.pdf
Which functions of a cell membrane would be compromised if the membr.pdfWhich functions of a cell membrane would be compromised if the membr.pdf
Which functions of a cell membrane would be compromised if the membr.pdf
infoeyecare
 
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdfWhat is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
infoeyecare
 
What is ransomware How can these cyber-attacks result in data loss.pdf
What is ransomware How can these cyber-attacks result in data loss.pdfWhat is ransomware How can these cyber-attacks result in data loss.pdf
What is ransomware How can these cyber-attacks result in data loss.pdf
infoeyecare
 
What are the 3 ways a Java method must match with its definition and.pdf
What are the 3 ways a Java method must match with its definition and.pdfWhat are the 3 ways a Java method must match with its definition and.pdf
What are the 3 ways a Java method must match with its definition and.pdf
infoeyecare
 
Using the Internet, compare and contrast two commercially available .pdf
Using the Internet, compare and contrast two commercially available .pdfUsing the Internet, compare and contrast two commercially available .pdf
Using the Internet, compare and contrast two commercially available .pdf
infoeyecare
 
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdfuetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
infoeyecare
 
The starship Epidemiology Team has cone many missions exploring the u.pdf
The starship Epidemiology Team has cone many missions exploring the u.pdfThe starship Epidemiology Team has cone many missions exploring the u.pdf
The starship Epidemiology Team has cone many missions exploring the u.pdf
infoeyecare
 
Question 3)Perform a regression analysis using compa as the depend.pdf
Question 3)Perform a regression analysis using compa as the depend.pdfQuestion 3)Perform a regression analysis using compa as the depend.pdf
Question 3)Perform a regression analysis using compa as the depend.pdf
infoeyecare
 
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdfProblems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
infoeyecare
 
Only a very small percentage of organisms actually fossilize. Based o.pdf
Only a very small percentage of organisms actually fossilize. Based o.pdfOnly a very small percentage of organisms actually fossilize. Based o.pdf
Only a very small percentage of organisms actually fossilize. Based o.pdf
infoeyecare
 
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdfOdin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
infoeyecare
 
Many new species of desert have arisen from a population which was .pdf
Many new species of desert  have arisen from a  population which was .pdfMany new species of desert  have arisen from a  population which was .pdf
Many new species of desert have arisen from a population which was .pdf
infoeyecare
 
List and analyze some of the most salient social factors of group un.pdf
List and analyze some of the most salient social factors of group un.pdfList and analyze some of the most salient social factors of group un.pdf
List and analyze some of the most salient social factors of group un.pdf
infoeyecare
 
J. A. Moore investigated the inheritance of spotting patterns in leop.pdf
J. A. Moore investigated the inheritance of spotting patterns in leop.pdfJ. A. Moore investigated the inheritance of spotting patterns in leop.pdf
J. A. Moore investigated the inheritance of spotting patterns in leop.pdf
infoeyecare
 

More from infoeyecare (20)

All fungi have tiny tube-like structures call hyphae. One is labeled .pdf
All fungi have tiny tube-like structures call hyphae. One is labeled .pdfAll fungi have tiny tube-like structures call hyphae. One is labeled .pdf
All fungi have tiny tube-like structures call hyphae. One is labeled .pdf
 
15. Let’s say you are systems administrator for a hospital’s network.pdf
15. Let’s say you are systems administrator for a hospital’s network.pdf15. Let’s say you are systems administrator for a hospital’s network.pdf
15. Let’s say you are systems administrator for a hospital’s network.pdf
 
What would the predicted result be if Griffith injected mice with a .pdf
What would the predicted result be if Griffith injected mice with a .pdfWhat would the predicted result be if Griffith injected mice with a .pdf
What would the predicted result be if Griffith injected mice with a .pdf
 
Write a function called myfind that will search for a key in a vecto.pdf
Write a function called myfind that will search for a key in a vecto.pdfWrite a function called myfind that will search for a key in a vecto.pdf
Write a function called myfind that will search for a key in a vecto.pdf
 
wright Mills proposed that sociologists could explain individual beha.pdf
wright Mills proposed that sociologists could explain individual beha.pdfwright Mills proposed that sociologists could explain individual beha.pdf
wright Mills proposed that sociologists could explain individual beha.pdf
 
Why are General, Special Revenue, and other governmental (expendable).pdf
Why are General, Special Revenue, and other governmental (expendable).pdfWhy are General, Special Revenue, and other governmental (expendable).pdf
Why are General, Special Revenue, and other governmental (expendable).pdf
 
Which functions of a cell membrane would be compromised if the membr.pdf
Which functions of a cell membrane would be compromised if the membr.pdfWhich functions of a cell membrane would be compromised if the membr.pdf
Which functions of a cell membrane would be compromised if the membr.pdf
 
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdfWhat is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
What is the state of water at 200 kPa and 250oCQuestion 7 options.pdf
 
What is ransomware How can these cyber-attacks result in data loss.pdf
What is ransomware How can these cyber-attacks result in data loss.pdfWhat is ransomware How can these cyber-attacks result in data loss.pdf
What is ransomware How can these cyber-attacks result in data loss.pdf
 
What are the 3 ways a Java method must match with its definition and.pdf
What are the 3 ways a Java method must match with its definition and.pdfWhat are the 3 ways a Java method must match with its definition and.pdf
What are the 3 ways a Java method must match with its definition and.pdf
 
Using the Internet, compare and contrast two commercially available .pdf
Using the Internet, compare and contrast two commercially available .pdfUsing the Internet, compare and contrast two commercially available .pdf
Using the Internet, compare and contrast two commercially available .pdf
 
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdfuetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
uetator Periodic Table Question 6 of 30 Incorrect Incorrect DA Saplin.pdf
 
The starship Epidemiology Team has cone many missions exploring the u.pdf
The starship Epidemiology Team has cone many missions exploring the u.pdfThe starship Epidemiology Team has cone many missions exploring the u.pdf
The starship Epidemiology Team has cone many missions exploring the u.pdf
 
Question 3)Perform a regression analysis using compa as the depend.pdf
Question 3)Perform a regression analysis using compa as the depend.pdfQuestion 3)Perform a regression analysis using compa as the depend.pdf
Question 3)Perform a regression analysis using compa as the depend.pdf
 
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdfProblems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
Problems in PYTHON3.5 1. Define a function sumOfDigits that has one .pdf
 
Only a very small percentage of organisms actually fossilize. Based o.pdf
Only a very small percentage of organisms actually fossilize. Based o.pdfOnly a very small percentage of organisms actually fossilize. Based o.pdf
Only a very small percentage of organisms actually fossilize. Based o.pdf
 
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdfOdin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
Odin and Zeus travel to the outermost reaches of our galaxy using wa.pdf
 
Many new species of desert have arisen from a population which was .pdf
Many new species of desert  have arisen from a  population which was .pdfMany new species of desert  have arisen from a  population which was .pdf
Many new species of desert have arisen from a population which was .pdf
 
List and analyze some of the most salient social factors of group un.pdf
List and analyze some of the most salient social factors of group un.pdfList and analyze some of the most salient social factors of group un.pdf
List and analyze some of the most salient social factors of group un.pdf
 
J. A. Moore investigated the inheritance of spotting patterns in leop.pdf
J. A. Moore investigated the inheritance of spotting patterns in leop.pdfJ. A. Moore investigated the inheritance of spotting patterns in leop.pdf
J. A. Moore investigated the inheritance of spotting patterns in leop.pdf
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

package lab7; import java.util.Scanner; Sammy Student, Program.pdf

  • 1. package lab7; import java.util.Scanner; //Sammy Student, Programmer public class Maze { static Scanner sc = new Scanner(System.in); // maze movements static char myMove = '0'; // cell position static int currentCell = 0; static int score = 0; static boolean advance = true; static boolean checkThis = false; public static void main(String args[]) { // the local variables declared and initialized char answer = 'Y'; displayMenu(); while(answer == 'Y' || answer == 'y') { displayMovement(); makeYourMove(); checkThis = checkYourMove(); mazeStatus(); System.out.println("move again(Y or N)?"); answer = sc.next().charAt(0); } System.out.println("***************************"); }// end main() method static void displayMenu() {
  • 2. System.out.println(""); System.out.println("***************************"); System.out.println("----The Maze Strategy---"); System.out.println(""); }// end method static void displayMovement() { if(currentCell == 0) { System.out.println("You have entered the maze!!"); System.out.println("There is no turning back!!"); currentCell = 1; mazeStatus(); advance = true; } System.out.println("make your move (W, A, S, D)"); System.out.println("W = up, A = left, S = down, D = right)"); }// end method static void makeYourMove() { myMove = sc.next().charAt(0); switch(myMove) { case 'W': { MoveUp(); break; } case 'A': { MoveLeft(); break; } case 'S': { MoveDown(); break; } case 'D': { MoveRight(); break; } } // end program menu }// end method static boolean checkYourMove() { if(currentCell == 1 && advance == true) {
  • 3. if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') { advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { currentCell = 2; advance = true; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { advance = false; System.out.println("continue through the maze"); return advance; } } if(currentCell == 2 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A')
  • 4. { advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { advance = false; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { currentCell = 5; advance = true; System.out.println("continue through the maze"); return advance; } } return advance; // end program menu }// end method static void MoveLeft() { System.out.println("you moved to the left"); }//end method static void MoveRight() { System.out.println("you moved to the right"); }//end method static void MoveUp() { System.out.println("you moved up (forward)");
  • 5. }//end method static void MoveDown() { System.out.println("you moved down (downward)"); }//end method static void mazeStatus() { System.out.println("current position: cell " + currentCell); }//end method }// end class Modifythe above code like this: Supplement the checkYourMove() method by including the remaining if statements that allow the maze participant to escape the maze. 1. if(currentCell== 5 &&advance==true) { . . . } if(currentCell== 6 &&advance==true) { . . . } if(currentCell== 9 &&advance==true) { . . . } 2. utilize the score variable to assign a score to each move. Also for extra credit you can track the number of moves that the user makes in their escape of the maze. Solution Please follow the code and comments for description : CODE : import java.util.Scanner; //Sammy Student, Programmer
  • 6. public class Maze { // class that runs the code static Scanner sc = new Scanner(System.in); // maze movements static char myMove = '0'; // cell position static int currentCell = 0; static int score = 0; static boolean advance = true; static boolean checkThis = false; public static void main(String args[]) { // the local variables declared and initialized char answer = 'Y'; displayMenu(); while (answer == 'Y' || answer == 'y') { displayMovement(); makeYourMove(); checkThis = checkYourMove(); mazeStatus(); System.out.println("move again(Y or N)?"); answer = sc.next().charAt(0); } System.out.println("***************************"); System.out.println("Total Moves Done : "+score); }// end main() method static void displayMenu() { System.out.println(""); System.out.println("***************************"); System.out.println("----The Maze Strategy---"); System.out.println(""); }// end method static void displayMovement() { if (currentCell == 0) { System.out.println("You have entered the maze!!"); System.out.println("There is no turning back!!"); currentCell = 1; mazeStatus();
  • 7. advance = true; } System.out.println("make your move (W, A, S, D)"); System.out.println("(W = up, A = left, S = down, D = right)"); }// end method static void makeYourMove() { myMove = sc.next().charAt(0); score++; switch (myMove) { case 'W': { MoveUp(); break; } case 'A': { MoveLeft(); break; } case 'S': { MoveDown(); break; } case 'D': { MoveRight(); break; } } // end program menu }// end method static boolean checkYourMove() { if (currentCell == 1 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') {
  • 8. advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { currentCell = 2; advance = true; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { advance = false; System.out.println("continue through the maze"); return advance; } } if (currentCell == 2 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') { advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { advance = false; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { currentCell = 5; advance = true; System.out.println("continue through the maze");
  • 9. return advance; } } if (currentCell == 5 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') { advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { currentCell = 6; advance = true; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { advance = false; System.out.println("continue through the maze"); return advance; } } if (currentCell == 6 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') { advance = false;
  • 10. System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { currentCell = 9; advance = true; System.out.println("continue through the maze"); return advance; } if (myMove == 'S') { advance = false; System.out.println("continue through the maze"); return advance; } } if (currentCell == 9 && advance == true) { if (myMove == 'W') { advance = false; System.out.println("try again"); return advance; } if (myMove == 'A') { advance = false; System.out.println("SORRY, there is no return"); return advance; } if (myMove == 'D') { currentCell = 9; advance = false; System.out.println("Escaped Through the Maze.!"); return advance; } if (myMove == 'S') { advance = false; System.out.println("continue through the maze");
  • 11. return advance; } } return advance; // end program menu }// end method static void MoveLeft() { System.out.println("you moved to the left"); }//end method static void MoveRight() { System.out.println("you moved to the right"); }//end method static void MoveUp() { System.out.println("you moved up (forward)"); }//end method static void MoveDown() { System.out.println("you moved down (downward)"); }//end method static void mazeStatus() { System.out.println("current position: cell " + currentCell); }//end method }// end class OUTPUT : *************************** ----The Maze Strategy--- You have entered the maze!! There is no turning back!! current position: cell 1 make your move (W, A, S, D) (W = up, A = left, S = down, D = right) D you moved to the right continue through the maze current position: cell 2
  • 12. move again(Y or N)? Y make your move (W, A, S, D) (W = up, A = left, S = down, D = right) S you moved down (downward) continue through the maze current position: cell 5 move again(Y or N)? Y make your move (W, A, S, D) (W = up, A = left, S = down, D = right) D you moved to the right continue through the maze current position: cell 6 move again(Y or N)? Y make your move (W, A, S, D) (W = up, A = left, S = down, D = right) D you moved to the right continue through the maze current position: cell 9 move again(Y or N)? Y make your move (W, A, S, D) (W = up, A = left, S = down, D = right) D you moved to the right Escaped Through the Maze.! current position: cell 9 move again(Y or N)? N *************************** Total Moves Done : 5
  • 13. Hope this is helpful.