Java program

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 2×2. 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 5×5 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;

}

}

DATABASE

   

                        1.5 Marks
                Learning     Outcome(s):
Create entity-relationship     model, relational model, and write SQL queries
 
 
 
 
 
 
      Question One

Consider the below schema for a library database and write relational algebra expressions for the following queries  

  

   

1. Author ( authorname, citizenship, birthyear) 

2. Book (isbn, title, authorname)

3. Topic (isbn, subject)

4. Branch (libname, city)

5. Instock (isbn, libname, quantity)

1. Give all authors’ names born after 1940. [0.25 Point]

2. Give the names of libraries in Sydney. [0.25 Point]

3. Give the city/cities and “isbn” where each book is held.    [0.25 Point]

4. Give the title of each book on the topic of either alcohol or drugs. [0.25 Point]

5. Give the title and author of each book of which at least two copies are held in a branch located in Melbourne.  [0.50 Point]

   

                        1 Mark
                Learning     Outcome(s):
Explain database concepts,     systems, and architectures
 
 
 
 
 
      Question Two

What is the different between the database schema and the database instance? Give an example for each.

   

                        1 Mark
                Learning     Outcome(s):
Design a database starting from     the conceptual design to the implementation of database schemas
 
 
 
 
 
      Question Three

Name at least three tables that might be used to store information in the following systems:

a. An e-commerce system such as Amazon.  [0.25 Point]

b. A social media system such as Twitter.    [0.25 Point]

c. A health care system. [0.25 Point]

d. A university system. [0.25 Point]

   

                        1.5 Marks
                Learning     Outcome(s):
Create entity-relationship     model, relational model, and write SQL queries
 
 
 
 
      Question Four

Given the relation below named Contact_Info, answer the following questions:

  

SSN

Name

Phone

Email

Age

 

234-356

Sara Fahad

340-675-9876

[email protected]

22

 

673-980

Mohammad Ahmed

234-896-2567

[email protected]

28

 

129-678

Waad Saud

280-986-8736

[email protected]

31

a. What is the relational schema of the relation Contact_Info?  [0.25 Point]

 

b. What is the degree of the giving relation? [0.25 Point]

 

c. Is the column Name an atomic attribute/value? If no, justify your answer? [0.25 Point]

d. What are the outputs of the given operations?  

1.                      (Contact_Info)  [0.50 Point]

2.   (Contact_Info)   [0.25 Point]

Computer Forensics-SP21

You are a digital forensics intern at Azorian Computer Forensics, a privately owned forensics investigations and data recovery firm in the Denver, Colorado area.

Your company creates a quarterly newsletter for its clients, many of which are law enforcement agencies, law firms, corporations, and insurance companies. It’s a Tuesday morning and you are sitting in a meeting with the team that produces the newsletter. While everyone is discussing which new section could be added to the newsletter, the senior editor turns to you and asks for your opinion. This is your chance to come up with a brilliant idea! You suggest that the company includes an insert containing contact information for and brief descriptions of government agencies to which computer crimes should be reported. The information would be very helpful to clients and could increase readership. She likes your idea and asks you to create the document. The document should include contact information for:

The local police department

The county sheriff’s office

The state police agency

Because the upcoming newsletter issue has several articles on cybercrime in particular, your document should also include the federal investigative law enforcement agencies that handle the following types of Internet-based crime:

Internet fraud and spam

Internet harassment

Create the document, presenting the local, county, and state contact information in one table and the Internet-based crime federal agency information in a second table.

Discussion with 2 peer responses

  Mobile networks in a global economy can be a challenge for multiple reasons.  First, governments in other countries control the mobile networks.  Second is the technology.  Mobile networks in other countries might not be as good as the mobile networks within the US.  As a global company, how can we deal with this?  With a big push for 5G, which has speeds well over 2Gbps, how does that change the way you do business?  What are some things you need to think about when it comes to doing business globally, using a wireless mobile network? 

8-1 Discussion: Technical Communications and the World Wide Web

When discussing technical and business communications, we generally think of memos, email, presentations, and the like. We do not always immediately think of using the World Wide Web, although it is a key component of technical communication in the twenty-first century. Why is the web so important to business (technical) communications today? What are some of the ways that the web is used for technical communications?

Discussion forum on chapter readings

 Textbook: Tapscott, D., &Tapscott, A. (2016). Blockchain revolution: how the technology behind bitcoin is changing money, business, and the world. Penguin.  

Chapter-6: The Ledger of Things: Animating the Physical World

Discussion:

 In chapter 6, the author describes twelve disruptions to existing markets. Choose one of the disruptions discussed in chapter 6, and explain how you think it will impact today’s economy, and provide at least two real examples of the chosen disruption being realized with blockchain technology today.

Then think of three questions you’d like to ask other students. The questions should be taken from material you read in Chapter 6. 

Write 300 words APA format document.