Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Java program

21/09/2020 Client: joediv12 Deadline: 10 Days

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;


}


}

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Smart Homework Helper
Assignment Hub
Top Academic Guru
Writing Factory
Homework Guru
University Coursework Help
Writer Writer Name Offer Chat
Smart Homework Helper

ONLINE

Smart Homework Helper

Greetings! I am the professional electrical, telecom engineer, rich experience in QPSK, OFDM, FFT, such signal processing concetps with matlab, I can satisfy you definitely. more in chat.thanks.

$105 Chat With Writer
Assignment Hub

ONLINE

Assignment Hub

I feel, I am the best option for you to fulfill this project with 100% perfection. I am working in this industry since 2014 and I have served more than 1200 clients with a full amount of satisfaction.

$105 Chat With Writer
Top Academic Guru

ONLINE

Top Academic Guru

This project is my strength and I can fulfill your requirements properly within your given deadline. I always give plagiarism-free work to my clients at very competitive prices.

$85 Chat With Writer
Writing Factory

ONLINE

Writing Factory

I can help you with creating a presentation of one slide for The Word of William Hunter. I will be happy to offer you 100% original work with high-quality standard, professional research and writing services of various complexities.

$75 Chat With Writer
Homework Guru

ONLINE

Homework Guru

I am a Ph.D. writer with more than 9 years of working experience in Writing. I have successfully completed more than 4500 projects for my clients with their full amount of satisfaction. I will provide you super quality work according to your given requirements and deadline with ZERO plagiarism.

$90 Chat With Writer
University Coursework Help

ONLINE

University Coursework Help

Greetings! I’m very much interested to write for attendance systems. I am a Professional Writer with over 5 years of experience, therefore, I can easily do this job. I will also provide you with TURNITIN PLAGIARISM REPORT. You can message me to discuss the details.

$90 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Ryan clark sickle cell trait - Monster high 13 wishes - Suppose mr smith marries ms brown what are the chances - A.1 Accounting/FInance - I love u daddy shrek - Final proposal - Applications of nanotechnology ppt - 3 pilgrimage festivals in judaism - Discussion Post - On july 31 2012 mexico company paid - Clampitt's five common communication strategies - Stirling 4.1 kw portable air conditioner - When did the eureka stockade occur - How do poseidon and zeus interact in this book - Under absorption and over absorption of overheads - Whitney simmons body weight workout - Bt 81 newgate street - +91-8890675453 love marriage problem solution IN Bally - Art in world culture - Amortized cost computer science - The establishment of permanent agricultural communities marked the beginning of what? - Dog walking contract example - What is a characteristic of a hot swappable esata drive - Discussion needed by 1pm Sunday - Acsm guidelines for exercise testing and prescription online - Four dimensions of competency - New heritage doll company capital budgeting case analysis - Post 2 responses to other students' posts, at least 75 words for each response that shows original thinking, contributes to the conversation and engages in discussion, using personal experience or information from the textbook or other outside sources - Uob bank transaction code - Dr walter c mccrone forensic science - NEED IN 15 HOURS or LESS - Http www strategicbusinessinsights com vals presurvey shtml - PRINCIPLES OF INDUSTRIAL AND ORGANIZATIONAL PSYCHOLOGY - Business revolution stylist station plugged in - Week 4 Discussion - Gatsby chapter 6 discussion questions - Wk reply 2 contemporary international problems - Greene and lidinsky habits of mind - Advanced Financial Accounting Problems - Bsc final year project - Master and margarita chapter summaries - Assessment 3: Report - Character description year 1 - Writing 2111 uwo - Airline Crew Scheduling Problems - 5 cheeky monkeys teasing mr crocodile - Egyptian civiliaztion - Comprehensive problem 1 the accounting cycle general journal - Flinders harvard reference guide - Simpsons genetics problems worksheet answer key - H2po4 mg oh 2 - Graduate engineer cover letter sample - Chemical companies in jurong island - Walter cronkite vietnam editorial - Combined and ideal gas laws worksheet answers - Neo behaviorism ppt - Rodney rude santa song - Discussion120 - Is great expectations a novel - 7th grade animal cell - Chester barnard contribution to management - Lab 02 - Writing chaincode - What is environmental threat and opportunity profile - St george term deposit interest - All resources are limited marketing - Cannon bard theory of emotion - Lawlink nsw local daily court lists - Easynews global search 2.0 - The yellow wallpaper as a feminist text - How to choose a level of significance - Essay on laptop in 250 words - Amazon vs walmart case study answers - Articles with ethos pathos and logos - High pass filter using hanning window - Writing assignment - Global interior design market - #2 Two Discussion Responses Needed 100 words each 200 words - What are some personal and professional responsibilities related to altruism - Sensation and perception essay - African American Literature Capstone Paper - Co2 dragster designs for speed - Agarose gel electrophoresis of dna fragments late nite labs - Compentency Journal - Governments often intervene in international trade and impose quotas to - Nissan of dearborn dearborn mi - Use case diagram for course management system - Rossendale pet crematorium and memorial gardens - How many types of stages are there - Accounting Discussion - In assessing the need for organizational change managers must - Is anthony cardell haynes still alive - Aib business banking helpline - Animal cell biology corner - Nothing gold can stay - Everyday use by alice walker symbolism - John moores university blackboard - How to extract creosote oil from coke oven - Education should be free argument essay - Americans are often accused of ethnocentricity this means that - Public relations project