SlideShare a Scribd company logo
1 of 16
Objectives: Create a Java program using programming
fundamentals (file I/O, loops, conditional statements, arrays,
functions)
Problem: In an effort to win a coding competition, you decided
to create an awesome Obstacle Warrior game. The game is
played on a 2-dimensional board similar to a Chess board, but
the dimensions may be different. The minimum size of the
board is 2x2. The board will have a Start square and an Exit
square that are not stored on the board. Start and Exit squares
cannot be the same. Other board squares may contain obstacles
in the form of an integer that will define how the warrior
position and score will be affected. The obstacle squares can
have values from 0 to -10 only. The Start square is always a
clear square. All clear squares are marked with # on the board.
The Exit square may contain an obstacle that is not a zero. The
size of the board, number of obstacles, and Start and Exit
squares are all unknow to your code prior to running. This
information is stored in a file that your code will read at the
beginning of the game. The board.dat file must be read into a 2-
D array.
A warrior must start at the Start square and find their way to the
Exit square. The warrior can move on the board in any direction
including diagonally, one square at a time. A warrior has a
running score (integer) maintained from the start of the game
until the warrior exits the board. If the warrior lands on an
obstacle square with a value of zero, the warrior is sent back to
the starting position and the obstacle square will become a
normal square (obstacle removed). If the obstacle square has a
negative number, that number will reduce the warrior's score by
the value of the obstacle, and the obstacle square will become a
clear square (obstacle removed). Each VALID move that the
warrior makes without landing on an obstacle will earn the
warrior one point. The moves for the warrior are randomly
generated by your code in the form of a direction (0-UP, 1-
DOWN, 2-LEFT, 3-RIGHT, 4-UPRIGHT, 5-DOWNRIGHT, 6-
UPLEFT, 7-DOWNLEFT). If the warrior is at the boundary of
the board and your code generates an invalid move, that move
will be ignored. Your code will keep generating moves until the
warrior exits at the Exit square. Once the warrior exits, your
program will store the updated board information to a new file
ResultBoard.dat as single-space separated data. The program
will also display the total number of valid moves, the total time
elapsed in milliseconds since the first move until the warrior
exited the board, the final score of the warrior and the formatted
board information (right aligned columns with total of 5
spaces).
Output Format:
Each column in the final board display must be of total width of
5 spaces
Data in each column must be right aligned
Enter the board data file path: C:board.dat //Repeat prompt
until valid file OR show error and exit.
Type "Start" to start the game or "Exit" to exit the game: exit
//Your program must exit
Enter the board file path: C:board.dat
Type "Start" to start the game or "Exit" to exit the game: start
//You may display the moves and the running score after each
move but it is not required
The warrior made 270 valid moves in 503 milliseconds. The
final score is 175 points.
# # # # #
# # # 0 #
# # # # #
# -3 # # -4
# # # # #
Press any key to exit!
Program Structure: Your code should be modular and easy to
understand. In addition to the main method, the following
methods are required to be in your code. These methods will be
used by the unit testing to test the accuracy of your code.
public static String[][] ReadBoardFromFile(String fileName,
Position startPosition, Position exitPosition)
public static boolean WriteBoardToFile(String fileName,
String[][] boardArray)
public static int GenerateDirection()
public static boolean MoveWarrior(int direction, String[][]
boardArray, Position currentPosition)
public static int CalculateWarriorScore(int currentScore,
Position currentPosition, String[][] boardArray)
public static String DisplayResults(int currentScore, int
numberOfMoves, int timeElapsed, String[][] boardArray)
Program Flow:
Program starts in main() method
Prompt user for Board.dat file path
Read board from file
Generate a direction
Move the warrior
Calculate new score
Check conditions and clear square if needed
Repeat until the warrior is at the exit square
Display the results
Prompt user to exit game
Board.dat file format:
The data in the file will be separated by one space
Assume that all data in the file is valid
Clear and Start squares (no obstacles) will be marked with # in
the file
The first line of the file contains the dimensions of the board
(rows and columns) e.g. 3 7
The second line contains the Start square indexes (rowIndex,
columnIndex)
The third line contains the Exit square indexes (rowIndex,
columnIndex)
The rest of the lines represent the contents, including obstacles,
of a row on the board
Example of a Board size 5x5 data file:
5 5
2 2
4 3
# -5 # # #
# # # 0 #
# # # # #
# -3 # # -4
-10 # # # #
**ResultBoard.dat file format: **
Data must be separated by a single space
# # # # #
# # # 0 #
# # # # #
# -3 # # -4
# # # # #
Grading:
Coding standards, style and comments (10 Points)
Unit testing methods x6, one for each of the methods mentioned
above (10 Points)
ReadBoardFromFile (10 Points)
WriteBoardToFile (10 Points)
GenerateDirection (10 Points)
MoveWarrior (20 Points)
CalculateWarriorScore (20 Points)
DisplayResults (10 Points)
Unit Test
package ObstaclesWarrior;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.PrintWriter;
import org.junit.Test;
/**
* Unit test
*/
public class MainTest {
@Test
public void ReadBoardFromFileTest()
{
final String FILE_NAME = "Board.dat";
//Either dynamically create the Board.dat file or assume it
already exists
/*File file = new File(FILE_NAME);
PrintWriter printToFile = new PrintWriter(file);
printToFile.println("4 4");
printToFile.println("0 2");
printToFile.println("2 2");
printToFile.println("0 # # #");
printToFile.println("# -3 # -5");
printToFile.println("# # # #");
printToFile.println("# # -1 #");
printToFile.close();
*/
//Create start and exit positions to pass to the method.
//These objects will be set with actual values from the
//board file by your code inside the ReadBoardFromFile()
method
Position actualStartPosition = new Position(0, 0);
Position actualExitPosition = new Position(0, 0);
//These are the expected values for the start and exit postions
Position expectedStartPosition = new Position(0, 2);
Position expectedExitPosition = new Position(2, 2);
//Create the expected array with the data
String[][] expectedBoardArray = {
{"0", "#", "#", "#" },
{"#", "-3", "#", "-5" },
{"#", "#", "#", "#" },
{"#", "#", "-1", "#" },
};
//Invoke the ReadBoardFromFile() method and capture the
returned array
String[][] actualBoardArray = Main.ReadBoardFromFile(
FILE_NAME,
actualStartPosition,
actualExitPosition);
//Check if the start and exit positions match
if((expectedStartPosition.getX() != actualStartPosition.getX())||
(expectedStartPosition.getY() != actualStartPosition.getY()))
{
assertTrue("Start position does not match", false);
}
if((expectedExitPosition.getX() != actualExitPosition.getX())||
(expectedExitPosition.getY() != actualExitPosition.getY()))
{
assertEquals("Exit position does not match",false);
}
//Compare the actualBoardArray with the testBoardArray.
//Size and data must match.
//Make sure the number of rows match
assertArrayEquals("Board array read from file does not match
expected array",
expectedBoardArray,
actualBoardArray );
}
@Test
public void WriteBoardToFileTest()
{
}
@Test
public void GenerateDirectionTest()
{
}
@Test
public void MoveWarriorTest()
{
}
@Test
public void CalculateWarriorScoreTest()
{
}
@Test
public void DisplayResultsTest()
{
}
}
Main.java
package ObstaclesWarrior;
/**
* ObstaclesWarrior
*
*/
public class Main
{
public static void main( String[] args )
{
}
public static String[][] ReadBoardFromFile(String fileName,
Position startPosition,
Position exitPosition)
{
//This code was added just to enable you to run the provided
unit test.
//Replace this code with your own code.
String[][] gameBoard = {
{"0", "#", "#", "#"},
{"#", "-3", "#", "-5"},
{"#", "#", "#", "#"},
{"#", "#", "-1", "#"},
};
startPosition.setX(0);
startPosition.setY(2);
exitPosition.setX(2);
exitPosition.setY(2);
return gameBoard;
}
public static boolean WriteBoardToFile(String fileName,
String[][] boardArray)
{
return true;
}
public static int GenerateDirection()
{
return 0;
}
public static Boolean MoveWarrior(int direction,
String[][] boardArray,
Position currentPosition)
{
return true;
}
public static int CalculateWarriorScore(int currentScore,
Position currentPosition,
String[][] boardArray)
{
return 0;
}
public static String DisplayResults(int currentScore,
int numberOfMoves,
int timeElapsed,
String[][] boardArray )
{
return "";
}
}
Position.java
package ObstaclesWarrior;
/**
* Position
*/
public class Position {
private int x;
private int y;
public Position(int xValue, int yValue) {
x = xValue;
y = yValue;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

More Related Content

Similar to Objectives Create a Java program using programming fundamentals (fi.docx

PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
Yashpatel821746
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
bhim1213
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data types
James Wong
 
ma project
ma projectma project
ma project
Aisu
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
shakilaghani
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 

Similar to Objectives Create a Java program using programming fundamentals (fi.docx (19)

Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
RDataMining slides-r-programming
RDataMining slides-r-programmingRDataMining slides-r-programming
RDataMining slides-r-programming
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
ma project
ma projectma project
ma project
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 

More from amit657720

Organizational BehaviorThe field of organizational behavior ca.docx
Organizational BehaviorThe field of organizational behavior ca.docxOrganizational BehaviorThe field of organizational behavior ca.docx
Organizational BehaviorThe field of organizational behavior ca.docx
amit657720
 
Organizational Culture Edgar H. Schein I I I I II I II .docx
Organizational Culture Edgar H. Schein I I I I II I II .docxOrganizational Culture Edgar H. Schein I I I I II I II .docx
Organizational Culture Edgar H. Schein I I I I II I II .docx
amit657720
 
Organizational culture is so ubiquitous that it affects all area.docx
Organizational culture is so ubiquitous that it affects all area.docxOrganizational culture is so ubiquitous that it affects all area.docx
Organizational culture is so ubiquitous that it affects all area.docx
amit657720
 
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docxOracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
amit657720
 
Option A.  You are a student at a New York City college in Septe.docx
Option A.  You are a student at a New York City college in Septe.docxOption A.  You are a student at a New York City college in Septe.docx
Option A.  You are a student at a New York City college in Septe.docx
amit657720
 
Organizational change initiatives are a team effort. It is the j.docx
Organizational change initiatives are a team effort. It is the j.docxOrganizational change initiatives are a team effort. It is the j.docx
Organizational change initiatives are a team effort. It is the j.docx
amit657720
 
Organizational Behavior OpenStax Rice Univer.docx
Organizational Behavior OpenStax Rice Univer.docxOrganizational Behavior OpenStax Rice Univer.docx
Organizational Behavior OpenStax Rice Univer.docx
amit657720
 
Organisms Causing Systemic MycosesObjectives -.docx
Organisms Causing Systemic MycosesObjectives   -.docxOrganisms Causing Systemic MycosesObjectives   -.docx
Organisms Causing Systemic MycosesObjectives -.docx
amit657720
 
Option 1 Media and Mental IllnessFind a source of informa.docx
Option 1 Media and Mental IllnessFind a source of informa.docxOption 1 Media and Mental IllnessFind a source of informa.docx
Option 1 Media and Mental IllnessFind a source of informa.docx
amit657720
 
Option One—The Odyssey  For the first option, focused solely on.docx
Option One—The Odyssey  For the first option, focused solely on.docxOption One—The Odyssey  For the first option, focused solely on.docx
Option One—The Odyssey  For the first option, focused solely on.docx
amit657720
 
Option 2 Art Select any 2 of works of art about the Hol.docx
Option 2 Art Select any 2 of works of art about the Hol.docxOption 2 Art Select any 2 of works of art about the Hol.docx
Option 2 Art Select any 2 of works of art about the Hol.docx
amit657720
 

More from amit657720 (20)

Organizational Analysis  Write a 5-7-page paper on a conflict th.docx
Organizational Analysis  Write a 5-7-page paper on a conflict th.docxOrganizational Analysis  Write a 5-7-page paper on a conflict th.docx
Organizational Analysis  Write a 5-7-page paper on a conflict th.docx
 
Organizational BehaviorThe field of organizational behavior ca.docx
Organizational BehaviorThe field of organizational behavior ca.docxOrganizational BehaviorThe field of organizational behavior ca.docx
Organizational BehaviorThe field of organizational behavior ca.docx
 
Organizational behavior is the combination of four areas of study—ps.docx
Organizational behavior is the combination of four areas of study—ps.docxOrganizational behavior is the combination of four areas of study—ps.docx
Organizational behavior is the combination of four areas of study—ps.docx
 
Organizational CommunicationPeople in this organization don’t.docx
Organizational CommunicationPeople in this organization don’t.docxOrganizational CommunicationPeople in this organization don’t.docx
Organizational CommunicationPeople in this organization don’t.docx
 
Organizational Culture Edgar H. Schein I I I I II I II .docx
Organizational Culture Edgar H. Schein I I I I II I II .docxOrganizational Culture Edgar H. Schein I I I I II I II .docx
Organizational Culture Edgar H. Schein I I I I II I II .docx
 
Organizational culture is so ubiquitous that it affects all area.docx
Organizational culture is so ubiquitous that it affects all area.docxOrganizational culture is so ubiquitous that it affects all area.docx
Organizational culture is so ubiquitous that it affects all area.docx
 
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docxOracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
OracleFIT5195-2-Star Schema.pdfWeek 2 – Star SchemaSe.docx
 
Oral PresentationPlease pick (1) one of the following topics.docx
Oral PresentationPlease pick (1) one of the following topics.docxOral PresentationPlease pick (1) one of the following topics.docx
Oral PresentationPlease pick (1) one of the following topics.docx
 
Option A.  You are a student at a New York City college in Septe.docx
Option A.  You are a student at a New York City college in Septe.docxOption A.  You are a student at a New York City college in Septe.docx
Option A.  You are a student at a New York City college in Septe.docx
 
Order #12087Type of serviceWriting from ScratchWork type.docx
Order #12087Type of serviceWriting from ScratchWork type.docxOrder #12087Type of serviceWriting from ScratchWork type.docx
Order #12087Type of serviceWriting from ScratchWork type.docx
 
ORAL PRESENTATION( POWER POINT ) 12 SLICES . use the Manual of Menta.docx
ORAL PRESENTATION( POWER POINT ) 12 SLICES . use the Manual of Menta.docxORAL PRESENTATION( POWER POINT ) 12 SLICES . use the Manual of Menta.docx
ORAL PRESENTATION( POWER POINT ) 12 SLICES . use the Manual of Menta.docx
 
Organizational change initiatives are a team effort. It is the j.docx
Organizational change initiatives are a team effort. It is the j.docxOrganizational change initiatives are a team effort. It is the j.docx
Organizational change initiatives are a team effort. It is the j.docx
 
Organizational Behavior OpenStax Rice Univer.docx
Organizational Behavior OpenStax Rice Univer.docxOrganizational Behavior OpenStax Rice Univer.docx
Organizational Behavior OpenStax Rice Univer.docx
 
Organisms Causing Systemic MycosesObjectives -.docx
Organisms Causing Systemic MycosesObjectives   -.docxOrganisms Causing Systemic MycosesObjectives   -.docx
Organisms Causing Systemic MycosesObjectives -.docx
 
Option 2Several artists created multiple self-portraits. Select.docx
Option 2Several artists created multiple self-portraits. Select.docxOption 2Several artists created multiple self-portraits. Select.docx
Option 2Several artists created multiple self-portraits. Select.docx
 
Option 1 Media and Mental IllnessFind a source of informa.docx
Option 1 Media and Mental IllnessFind a source of informa.docxOption 1 Media and Mental IllnessFind a source of informa.docx
Option 1 Media and Mental IllnessFind a source of informa.docx
 
Option 1 Thought about a child who is dying. Is a death of a chil.docx
Option 1 Thought about a child who is dying. Is a death of a chil.docxOption 1 Thought about a child who is dying. Is a death of a chil.docx
Option 1 Thought about a child who is dying. Is a death of a chil.docx
 
Option One—The Odyssey  For the first option, focused solely on.docx
Option One—The Odyssey  For the first option, focused solely on.docxOption One—The Odyssey  For the first option, focused solely on.docx
Option One—The Odyssey  For the first option, focused solely on.docx
 
Option 1Right to Counsel PresentationAnalyze two case.docx
Option 1Right to Counsel PresentationAnalyze two case.docxOption 1Right to Counsel PresentationAnalyze two case.docx
Option 1Right to Counsel PresentationAnalyze two case.docx
 
Option 2 Art Select any 2 of works of art about the Hol.docx
Option 2 Art Select any 2 of works of art about the Hol.docxOption 2 Art Select any 2 of works of art about the Hol.docx
Option 2 Art Select any 2 of works of art about the Hol.docx
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 

Objectives Create a Java program using programming fundamentals (fi.docx

  • 1. Objectives: Create a Java program using programming fundamentals (file I/O, loops, conditional statements, arrays, functions) Problem: In an effort to win a coding competition, you decided to create an awesome Obstacle Warrior game. The game is played on a 2-dimensional board similar to a Chess board, but the dimensions may be different. The minimum size of the board is 2x2. The board will have a Start square and an Exit square that are not stored on the board. Start and Exit squares cannot be the same. Other board squares may contain obstacles in the form of an integer that will define how the warrior position and score will be affected. The obstacle squares can have values from 0 to -10 only. The Start square is always a clear square. All clear squares are marked with # on the board. The Exit square may contain an obstacle that is not a zero. The size of the board, number of obstacles, and Start and Exit squares are all unknow to your code prior to running. This information is stored in a file that your code will read at the beginning of the game. The board.dat file must be read into a 2- D array. A warrior must start at the Start square and find their way to the Exit square. The warrior can move on the board in any direction including diagonally, one square at a time. A warrior has a running score (integer) maintained from the start of the game until the warrior exits the board. If the warrior lands on an obstacle square with a value of zero, the warrior is sent back to the starting position and the obstacle square will become a normal square (obstacle removed). If the obstacle square has a negative number, that number will reduce the warrior's score by the value of the obstacle, and the obstacle square will become a clear square (obstacle removed). Each VALID move that the warrior makes without landing on an obstacle will earn the warrior one point. The moves for the warrior are randomly
  • 2. generated by your code in the form of a direction (0-UP, 1- DOWN, 2-LEFT, 3-RIGHT, 4-UPRIGHT, 5-DOWNRIGHT, 6- UPLEFT, 7-DOWNLEFT). If the warrior is at the boundary of the board and your code generates an invalid move, that move will be ignored. Your code will keep generating moves until the warrior exits at the Exit square. Once the warrior exits, your program will store the updated board information to a new file ResultBoard.dat as single-space separated data. The program will also display the total number of valid moves, the total time elapsed in milliseconds since the first move until the warrior exited the board, the final score of the warrior and the formatted board information (right aligned columns with total of 5 spaces). Output Format: Each column in the final board display must be of total width of 5 spaces Data in each column must be right aligned Enter the board data file path: C:board.dat //Repeat prompt until valid file OR show error and exit. Type "Start" to start the game or "Exit" to exit the game: exit //Your program must exit Enter the board file path: C:board.dat Type "Start" to start the game or "Exit" to exit the game: start //You may display the moves and the running score after each move but it is not required The warrior made 270 valid moves in 503 milliseconds. The
  • 3. final score is 175 points. # # # # # # # # 0 # # # # # # # -3 # # -4 # # # # # Press any key to exit! Program Structure: Your code should be modular and easy to understand. In addition to the main method, the following methods are required to be in your code. These methods will be used by the unit testing to test the accuracy of your code. public static String[][] ReadBoardFromFile(String fileName, Position startPosition, Position exitPosition) public static boolean WriteBoardToFile(String fileName, String[][] boardArray) public static int GenerateDirection() public static boolean MoveWarrior(int direction, String[][] boardArray, Position currentPosition) public static int CalculateWarriorScore(int currentScore, Position currentPosition, String[][] boardArray)
  • 4. public static String DisplayResults(int currentScore, int numberOfMoves, int timeElapsed, String[][] boardArray) Program Flow: Program starts in main() method Prompt user for Board.dat file path Read board from file Generate a direction Move the warrior Calculate new score Check conditions and clear square if needed Repeat until the warrior is at the exit square Display the results Prompt user to exit game Board.dat file format: The data in the file will be separated by one space Assume that all data in the file is valid Clear and Start squares (no obstacles) will be marked with # in
  • 5. the file The first line of the file contains the dimensions of the board (rows and columns) e.g. 3 7 The second line contains the Start square indexes (rowIndex, columnIndex) The third line contains the Exit square indexes (rowIndex, columnIndex) The rest of the lines represent the contents, including obstacles, of a row on the board Example of a Board size 5x5 data file: 5 5 2 2 4 3 # -5 # # # # # # 0 # # # # # # # -3 # # -4 -10 # # # # **ResultBoard.dat file format: **
  • 6. Data must be separated by a single space # # # # # # # # 0 # # # # # # # -3 # # -4 # # # # # Grading: Coding standards, style and comments (10 Points) Unit testing methods x6, one for each of the methods mentioned above (10 Points) ReadBoardFromFile (10 Points) WriteBoardToFile (10 Points) GenerateDirection (10 Points) MoveWarrior (20 Points) CalculateWarriorScore (20 Points) DisplayResults (10 Points)
  • 7. Unit Test package ObstaclesWarrior; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.PrintWriter; import org.junit.Test; /** * Unit test */ public class MainTest { @Test public void ReadBoardFromFileTest() { final String FILE_NAME = "Board.dat"; //Either dynamically create the Board.dat file or assume it already exists /*File file = new File(FILE_NAME);
  • 8. PrintWriter printToFile = new PrintWriter(file); printToFile.println("4 4"); printToFile.println("0 2"); printToFile.println("2 2"); printToFile.println("0 # # #"); printToFile.println("# -3 # -5"); printToFile.println("# # # #"); printToFile.println("# # -1 #"); printToFile.close(); */ //Create start and exit positions to pass to the method. //These objects will be set with actual values from the //board file by your code inside the ReadBoardFromFile() method Position actualStartPosition = new Position(0, 0); Position actualExitPosition = new Position(0, 0); //These are the expected values for the start and exit postions Position expectedStartPosition = new Position(0, 2);
  • 9. Position expectedExitPosition = new Position(2, 2); //Create the expected array with the data String[][] expectedBoardArray = { {"0", "#", "#", "#" }, {"#", "-3", "#", "-5" }, {"#", "#", "#", "#" }, {"#", "#", "-1", "#" }, }; //Invoke the ReadBoardFromFile() method and capture the returned array String[][] actualBoardArray = Main.ReadBoardFromFile( FILE_NAME, actualStartPosition, actualExitPosition); //Check if the start and exit positions match if((expectedStartPosition.getX() != actualStartPosition.getX())|| (expectedStartPosition.getY() != actualStartPosition.getY())) { assertTrue("Start position does not match", false);
  • 10. } if((expectedExitPosition.getX() != actualExitPosition.getX())|| (expectedExitPosition.getY() != actualExitPosition.getY())) { assertEquals("Exit position does not match",false); } //Compare the actualBoardArray with the testBoardArray. //Size and data must match. //Make sure the number of rows match assertArrayEquals("Board array read from file does not match expected array", expectedBoardArray, actualBoardArray ); } @Test public void WriteBoardToFileTest() { } @Test
  • 11. public void GenerateDirectionTest() { } @Test public void MoveWarriorTest() { } @Test public void CalculateWarriorScoreTest() { } @Test public void DisplayResultsTest() { } } Main.java package ObstaclesWarrior;
  • 12. /** * ObstaclesWarrior * */ public class Main { public static void main( String[] args ) { } public static String[][] ReadBoardFromFile(String fileName, Position startPosition, Position exitPosition) { //This code was added just to enable you to run the provided unit test. //Replace this code with your own code. String[][] gameBoard = { {"0", "#", "#", "#"},
  • 13. {"#", "-3", "#", "-5"}, {"#", "#", "#", "#"}, {"#", "#", "-1", "#"}, }; startPosition.setX(0); startPosition.setY(2); exitPosition.setX(2); exitPosition.setY(2); return gameBoard; } public static boolean WriteBoardToFile(String fileName, String[][] boardArray) { return true; } public static int GenerateDirection() { return 0;
  • 14. } public static Boolean MoveWarrior(int direction, String[][] boardArray, Position currentPosition) { return true; } public static int CalculateWarriorScore(int currentScore, Position currentPosition, String[][] boardArray) { return 0; } public static String DisplayResults(int currentScore, int numberOfMoves, int timeElapsed, String[][] boardArray ) {
  • 15. return ""; } } Position.java package ObstaclesWarrior; /** * Position */ public class Position { private int x; private int y; public Position(int xValue, int yValue) { x = xValue; y = yValue; } public int getX() { return x; }
  • 16. public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } }