Initial Commit
This commit is contained in:
8
Source Code/Assignment 8/.idea/.gitignore
generated
vendored
Normal file
8
Source Code/Assignment 8/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 8\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
7
Source Code/Assignment 8/.idea/codeStyles/Project.xml
generated
Normal file
7
Source Code/Assignment 8/.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
Source Code/Assignment 8/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
Source Code/Assignment 8/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
6
Source Code/Assignment 8/.idea/discord.xml
generated
Normal file
6
Source Code/Assignment 8/.idea/discord.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
</component>
|
||||
</project>
|
10
Source Code/Assignment 8/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
10
Source Code/Assignment 8/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="51" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
Source Code/Assignment 8/.idea/misc.xml
generated
Normal file
6
Source Code/Assignment 8/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Source Code/Assignment 8/.idea/modules.xml
generated
Normal file
8
Source Code/Assignment 8/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Assignment 8.iml" filepath="$PROJECT_DIR$/Assignment 8.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Source Code/Assignment 8/Assignment 8.iml
Normal file
11
Source Code/Assignment 8/Assignment 8.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
10
Source Code/Assignment 8/input/input1.txt
Normal file
10
Source Code/Assignment 8/input/input1.txt
Normal file
@ -0,0 +1,10 @@
|
||||
8
|
||||
7
|
||||
1000000
|
||||
11111G0
|
||||
00B0101
|
||||
1111111
|
||||
101R101
|
||||
1010101
|
||||
0001111
|
||||
0B010G0
|
6
Source Code/Assignment 8/input/input2.txt
Normal file
6
Source Code/Assignment 8/input/input2.txt
Normal file
@ -0,0 +1,6 @@
|
||||
4
|
||||
6
|
||||
100000
|
||||
11111G
|
||||
00B010
|
||||
111111
|
9
Source Code/Assignment 8/input/input3.txt
Normal file
9
Source Code/Assignment 8/input/input3.txt
Normal file
@ -0,0 +1,9 @@
|
||||
2
|
||||
28
|
||||
10B011100B01011G1R1010001111
|
||||
11111G0111111110101010B010G0
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
33
Source Code/Assignment 8/src/PaintDriver.java
Normal file
33
Source Code/Assignment 8/src/PaintDriver.java
Normal file
@ -0,0 +1,33 @@
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
/**
|
||||
* Driver for the painter method
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
|
||||
public class PaintDriver {
|
||||
public static void main(String[] args) {
|
||||
File input = null;
|
||||
if (args.length > 0) {
|
||||
input = new File(args[0]);
|
||||
}
|
||||
else {
|
||||
System.out.print("File does not exist");
|
||||
System.exit(1);
|
||||
}
|
||||
Painter painter = null;
|
||||
try {
|
||||
painter = new Painter(input);
|
||||
} catch (FileNotFoundException exception) {
|
||||
System.out.print("File does not exist");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
System.out.println("Before Paint:");
|
||||
System.out.print(painter.toString());
|
||||
painter.paint();
|
||||
System.out.println("\nAfter Paint:");
|
||||
System.out.print(painter.toString());
|
||||
}
|
||||
}
|
164
Source Code/Assignment 8/src/Painter.java
Normal file
164
Source Code/Assignment 8/src/Painter.java
Normal file
@ -0,0 +1,164 @@
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Painter object that paints the room and reads the input file
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
|
||||
public class Painter {
|
||||
Scanner sc;
|
||||
int height;
|
||||
int width;
|
||||
char[][] room;
|
||||
|
||||
/**
|
||||
* Constructor for painter
|
||||
* @param fileIn The file containing the information to construct the room
|
||||
* @throws FileNotFoundException When file does not exist
|
||||
*/
|
||||
Painter(File fileIn) throws FileNotFoundException {
|
||||
sc = new Scanner(fileIn);
|
||||
height = Integer.parseInt(sc.nextLine());
|
||||
width = Integer.parseInt(sc.nextLine());
|
||||
room = new char[height][width];
|
||||
|
||||
for(int i = 0; i < height; i++) {
|
||||
String currentLine = sc.nextLine();
|
||||
for(int j = 0; j < width; j++) {
|
||||
room[i][j] = currentLine.charAt(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the colors in the room and calls to paint the room
|
||||
*/
|
||||
public void paint() {
|
||||
char[] colors = new char[]{'R', 'B', 'G'};
|
||||
int indexLine = 0;
|
||||
int indexCell = 0;
|
||||
|
||||
for(char colorName: colors) {
|
||||
for(char[] line: room) {
|
||||
for(char cell: line) {
|
||||
if (cell == colorName) {
|
||||
paint(indexLine, indexCell, colorName);
|
||||
}
|
||||
indexCell++;
|
||||
}
|
||||
indexLine++;
|
||||
indexCell = 0;
|
||||
}
|
||||
indexLine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method that paints the room
|
||||
* @param row The row in which to be painted
|
||||
* @param col The column in which to be painted
|
||||
* @param color The color to be painted
|
||||
*/
|
||||
private void paint(int row, int col, char color) {
|
||||
room[row][col] = color;
|
||||
if (row == 0) {
|
||||
if (col == 0) {
|
||||
//case for when the row and column is zero. (first position)
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
}
|
||||
else if (col == width - 1) {
|
||||
//case for when the row is zero and the column is max (top right)
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row, col - 1, color);
|
||||
}
|
||||
//case for when the row being operated on is zero
|
||||
else {
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row , col - 1, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
}
|
||||
} else if (row == height - 1) {
|
||||
if (col == width - 1) {
|
||||
//case for when the row and the column are at the max value (last position)
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row - 1, col - 1, color);
|
||||
}
|
||||
else if (col == 0) {
|
||||
//case for when the row is max and the column is zero (bottom left)
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
}
|
||||
else {
|
||||
//case for when the row is at its maximum value
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row - 1, col, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row, col - 1, color);
|
||||
}
|
||||
} else if (col == 0) {
|
||||
//case for when just the column is zero
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row + 1, col, color);
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
} else if (col == width - 1) {
|
||||
//case for when the column is at its last position
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row - 1, col, color);
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row, col - 1, color);
|
||||
} else {
|
||||
//case for any middle position on board
|
||||
if (room[row - 1][col] == '0') //up
|
||||
paint(row - 1, col, color);
|
||||
if (room[row + 1][col] == '0') //down
|
||||
paint(row + 1, col, color);
|
||||
if (room[row][col - 1] == '0') //left
|
||||
paint(row, col - 1, color);
|
||||
if (room[row][col + 1] == '0') //right
|
||||
paint(row, col + 1, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toString method for Painter object. Prints the room as was in the text file
|
||||
* @return String containing the room
|
||||
*/
|
||||
public String toString() {
|
||||
int indexCell = 0;
|
||||
StringBuilder returnString = new StringBuilder();
|
||||
for (char[] line : room) {
|
||||
for (char cell : line) {
|
||||
indexCell++;
|
||||
if (indexCell == width) {
|
||||
returnString.append(cell).append("\n");
|
||||
}
|
||||
else {
|
||||
returnString.append(cell);
|
||||
}
|
||||
}
|
||||
indexCell = 0;
|
||||
}
|
||||
return returnString.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user