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;

}

}

Java program

Objectives:

  • Use inheritance to create base and child classes
  • Utilize multiple classes in the same program
  • Perform standard input validation
  • Implement a solution that uses polymorphism

Problem:

A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes re-ordering the menu items and making changes to the description of a menu item without having to change the code.

Security:

The company has suggested to start the application by prompting the user for a username and password to authenticate the user. There are two types of users at this company, managers and employees. If managers log on to the application, they will see all options on the menu list. If employees log on to the application, they will see a limited set of options on the menu list. User information is stored in Users.dat file, which may or may not exist at the start of the program. A super user “admin” with password “admin” has already been hardcoded in the program to allow for the initial setup and the creation of other users. The Users.dat file contains the FirstName, LastName, Username (case insensitive), HashedPassword and a flag to indicate whether a user is a manager or not. The file is comma separated and it is formatted as follows:

Joe, Last, jlast, 58c536ed8facc2c2a293a18a48e3e120, true
Sam, sone, samsone, 2c2a293a18a48e3e12058c536ed8facc, false
Jane, Best, jbest, 293a18a48e3e12052058c536ed8facc2c, false

Note: Ensure that the ‘AddUser’ function does not add duplicate values, and the ‘ChangePassword’ function does not change password if username/password is entered incorrectly. If adding a new user or changing the password is successful, return true, or else return false.

Application Menu:

The menu of the application is dynamically loaded and displayed to the user only after the user successfully logs on. The menu items will be loaded from file “MenuList.dat”, which may or may not exist at the start of the application. If the file doesn’t exist, the application should show at least an Exit menu item as default. The file will contain all menu items details, including the name of the command that will be executed when the menu item is selected. If a menu item is marked as restricted (Boolean flag), only managers can see that item. The file contains the following comma separated fields, Description, a Boolean flag to indicate if the option is restricted to managers only, and the name of the menu command that will be executed when the option is chosen. The order and option number of a menu item may change depending on how they are listed in the file. The Exit option will always be listed last and it will not be in the file. 

Below is a sample of how the MenuList.dat file looks like:

Add User, true, AddUserCommand
Delete User, true, DeleteUserCommand
Change Password, false, ChangePasswordCommand
Add New Product, true, AddProductCommand

Note: The command name of each menu item must match the name of the class that you will create in the code (See AddProductCommand class in the code for example).

Inventory:

The inventory consists of multiple products of type Product stored in class ProductCatalog. The ProductCatalog is responsible of all inventory operations that add, remove, find and update a product. When printing a product information, the product retail price should be calculated and displayed as well. Retail price = (cost + (margin * cost/100)). A list of functions has been added to this class in the provided code template. You must implement all listed functions. The inventory products will be saved in file Inventory.dat, which may or may not exist when the program first starts. The file will contain the product unique id (int), product name (string), cost (double), quantity (int) and margin (int, integer that represents margin percentage). 

The Inventory.dat file is comma separated and formatted as follows:

3424, Smart Watch, 20.45, 23, 80
65454, Flat Screen TV, 465.98, 15, 35
435, Computer Monitor, 123.54, 84, 43

Program Flow:

  • Program starts in main() method
  • Prompt user for username and password
  • Authenticate user and maintain the logged-on user object
  • Load inventory
  • Load and create menu list
  • Display menu list and prompt the user for option
  • Execute selected option
  • Keep displaying the menu until the user chooses to exit

Output Format:

Enter username: some username
Enter password: some password //Repeat prompts until user is authenticated OR show error and
option to exit.
Invalid username or password!
Press enter to continue or “Exit” to exit:
Enter username: some username
Enter password: some password
Welcome Firstname LastName!
Inventory Management System Menu //This is the header of the MenuList

// The order and option number of a menu item may change depending on how they are listed in the MenuList.dat file. The Exit option will always be listed last and it will not be in the MenuList.dat file.

1- Add user
2- Remove user
3- Change password
4- Add new product
5- Update product information
6- Delete product
7- Display product information
8- Display inventory
9- Exit
Enter your selection: 7
Enter product name: sMaRt wAtCh

Id Name Cost Quantity Retail
----------------------------------------------------
3424 Smart Watch $20.45 23 $36.81

//Repeat the menu after each command is executed

Unit Testing:

A unit test method is required to test each of the methods listed below. These methods will be used by the unit testing framework to test the accuracy of your code.

  • InventoryManagementSecurity.AuthenticateUser
  • InventoryManagementSecurity.AddNewUser
  • InventoryManagementSecurity.RemoveUser
  • InventoryManagementSecurity.ChangePassword
  • MenuList.AddMenuItem()
  • ProductCatalog.AddUpdateProduct(Product product)
  • ProductCatalog.RemoveProduct(int productId)
  • ProductCatalog.FindProduct(int productId)
  • ProductCatalog.PrintProductInformation(int productId)
  • ProductCatalog.PrintInventoryList()

Grading:

  • Coding standards, style and comments (10 Points)
  • Unit testing methods x 10, (2 points for each of the methods mentioned above – 20 Points)
  • The rest of the grade will be broken down as follows:
  • InventoryManagementSecurity.AuthenticateUser (5 Points)
  • InventoryManagementSecurity.AddNewUser (5 Points)
  • InventoryManagementSecurity.RemoveUser (5 Points)
  • InventoryManagementSecurity.ChangePassword (5 Points)
  • MenuList.AddMenuItem() (20 Points) //This includes implementing all commands for the menu list
  • ProductCatalog.AddUpdateProduct(Product product) (10 Points)
  • ProductCatalog.RemoveProduct(int productId) (5 Points)
  • ProductCatalog.FindProduct(int productId) (5 Points)
  • ProductCatalog.PrintProductInformation(int productId) (5 Points)
  • ProductCatalog.PrintInventoryList() (5 Points)

Notes:

  • The “InventoryManagement” Maven solution zip file has been provided to you in eLearning.
  • All *.dat files are assumed to be local to the current executable.
  • Do not change the methods stubs or constructors in the template. If in doubt, please ask.
  • Your program is expected to have basic input validation.
  • You may use ArrayList in this project
  • Part 1 deliverables: Unit Test methods + AuthenticateUser() function (no add or remove user is required in part 1). See eLearning for due date.
  • Part 2 deliverables: Functioning program including the Unit Test methods

Advanced Graphs in R-Studio.

Advanced Graphs in R-Studio.

  1. Discuss the importance of regular expressions in data analytics. 
  2. Also, discuss the differences between the types of regular expressions.
  3. Choose two types of regular expressions…

For example: 

[brackets] (Matches the enclosed characters in any order anywhere in a string), and 

* wildcards (Matches the preceding character 0 or more times) and discuss the differences between the two.

  • Please be sure to include two or three differences for each and include how they help manipulate data.

Reply Post

When replying to a classmate, offer your opinion on what they describe as important regarding regular expressions and whether you agree or disagree, and why.

Assignment

 

This week’s journal articles focus on empowering leadership and effective collaboration in geographically dispersed teams, please answer the following questions:

  1. How do geographically dispersed teams collaborate effectively?
  2. Please find at least three tools on the market that teams can use to collaborate on a geographically dispersed team.  Please note the pros and cons of each tool. 
  3. Based on the research above, note which tool you would select if you were managing the geographically dispersed team and why.

Be sure to use the UC Library for scholarly research. Google Scholar is also a great source for research.  Please be sure that journal articles are peer-reviewed and are published within the last five years.

The paper should meet the following requirements:

  • 3-5 pages in length (not including title page or references)
  • APA guidelines must be followed.  The paper must include a cover page, an introduction, a body with fully developed content, and a conclusion.
  • A minimum of five peer-reviewed journal articles.

The writing should be clear and concise.  Headings should be used to transition thoughts.  Don’t forget that the grade also includes the quality of writing.

Software Development History Presentation (6-8) slides

Assignment Instructions

Create a narrated 6-8 slide presentation in Microsoft PowerPoint® in which you discuss the aspect of software development history that you found most interesting during this week’s learning. Be sure to discuss whether this historical aspect has a continuing influence in today’s software development environment in terms of core programming concepts such as repetition structures, decision structures, arrays, functions, and variables. For example, think about how the shift from procedural programming to object-oriented programming changed or did not change how the core concepts were handled. When composing your presentation, be sure to use Standard English and a highly developed and sustained viewpoint and purpose. The communication of your presentation should be highly ordered, logical and unified.

Additionally, one slide must be devoted to some aspect of software development history demonstrating the benefits of multiculturalism and diversity in a global context. How has software development evolved as we have become more globalized and how has it influenced the growth and change in software development?

Your presentation must have narration throughout as if you were delivering it in a live, professional setting. Focus on your word choice. Your oral delivery techniques, including word choice and oral expressiveness, should display exceptional content, organization, and style, while leading the audience to a dynamic and supported conclusion.

For instructions on adding audio to your presentation, please review the HOONUIT module on adding media.
https://learnit.hoonuit.com/5567/learnit

Assignment Requirements

Narrated content must be effectively incorporated into the presentation. Oral delivery techniques, including word choice and oral expressiveness, displays exceptional content, organization, and style, while leading the audience to a dynamic and supported conclusion.

At least one slide must demonstrate the ability to analyze the benefits of multiculturalism and diversity in a global context.

Assignment Requirements

Points

Possible

Points

Earned

Student selects a specific aspect of software development history to discuss.

5

At least one slide analyzes an aspect of software development history that demonstrates the benefits of multiculturalism and diversity in a global context.

5

Student work includes recommended solutions to issues that arise from a more globalized software development environment.

5

Effectively discusses how this historical aspect continues to influence today’s software development environment (taking into account covered programming concepts, such as repetition structures, decision structures, arrays, functions, and variables).

15

Student’s voice narration effectively incorporated into the presentation.

10

Presentation is 6–8 slides in length.

5

Total (Sum of all points)

45

BI_Discussion_3

 Create a discussion thread (with your name) and answer the following question:
Discussion (Chapter 3): Why are the original/raw data not readily usable by analytics tasks? What are the main data preprocessing steps? List and explain their importance in analytics. 

Add 3 References.

binary search tree java

need all bst.java methods to be completed and working. 

the instructions for the methods are in DefaultMap.java

no need to look into other 3 files, mainly for testing and compiling

do not change source code

Big Data analytics

 This week’s reading centered around how Big Data analytics can be used with Smart Cities. This is exciting and can provide many benefits to individuals as well as organizations. For this week’s research assignment, you are to search the Internet for other uses of Big Data in RADICAL platforms. Please pick an organization or two and discuss the usage of big data in RADICAL platforms including how big data analytics is used in those situations as well as with Smart Cities. Be sure to use the UC Library for scholarly research. Google Scholar is the 2nd best option to use for research. Your paper should meet these requirements:

  • Be approximately four to six pages in length, not including the required cover page and reference page.
  • Follow APA 7 guidelines. Your paper should include an introduction, a body with fully developed content, and a conclusion.
  • Support your answers with the readings from the course and at least two scholarly journal articles to support your positions, claims, and observations, in addition to your textbook. The UC Library is a great place to find resources.
  • Be clearly and well-written, concise, and logical, using excellent grammar and style techniques. You are being graded in part on the quality of your writing.