2D Array HKIS Logo

public class image
public static void main(String []args) {
int[][] hkisLogo= ((** THE HKIS LOGO THAT MR LIN SENT US **))
String[][] replace = new String[hkisLogo.length][hkisLogo[0].length];

for (int row = 0; row < hkisLogo.length; row++){ // goes over every row and changes the value to whatever I want to set it to, loop continues till it reaches every row.
for (int col = 0; col < hkisLogo[row].length; col++){ //goes over every column and changes the specific value to whatever I want it to be
if(hkisLogo[row][col] == 255){ // tells the computer that if it sees 255 in the 2d array, then it should change the value to 00.
replace[row][col] = “00”;
else if (hkisLogo[row][col] == 0){ // tells the computer that if it sees a 0 in the 2d array then it should change it to a space
replace[row][col] = ” “;
System.out.print(replace[row][col]); // tells the computer to print the 2d array with the altered values from the conditional statements above

System.out.println(); // prints the array

In my code, I first wrote a series of two for loops in order to convert and identify values in each and every single one of the rows and columns in the ascii picture that Mr. Lin sent us. After that, I wrote a conditional statements that tells the computer to change every 255 value to a 00, and every 0 to a ‘space.’ This essentially alters the photo to look a little bit different. Finally, I wrote a print statement to print my new and improved picture.

APCS A: D(Encryption) Summative

At first when approaching this summative, I was really confused at where to start. I originally had an idea to create an array which would be paralleled onto a new array, which would be made out of different letters and symbols. However, after a class period where we review how to utilise ASCII in java, I chose a slightly easier pathway.

First, both my Encrypt and Decrypt class contained one constructor and four methods. In each class, the only constructor defined the instance variable of word and text in the encrypt and decrypt classes respectively.

The first of the four methods, named getLength, simply identified how many characters existed a word that was specified within the main method class. I was able to utilise this method in my final encrypt method to set a a parameter for the loop, ending where there were only so many characters in whatever string input that the user wanted to use.

The second of the four methods, the returnACharacter method, functioned to return each of the characters that are present in the word, then spacing them out. This was utilised in my final method to make each character unique before I altered them into different forms, as you’re about to see. This method also used the getLength method in order to see how many characters a word had, thus only carrying out a function on the letters in the word and no more.

The third of the four methods was the returnASCII method. This method took characters and returned their ASCII value instead of their string value, thus assigning each character to a numeric value that we could use to further encrypt our code.

Finally, our fourth of the four methods was used to actually wrap everything together. Here, I set up two variables, x, which represented the getLength method, letting me set a parameter on the function that I was planning to carry out. The second variable, counter, helping me make increments on the progress of the reaction, where each increment had a function that was carried out on that certain letter. Finally, I had a final variable which was just an empty string which I later combined with an integer in order to turn it back into a string. After setting up these variables, I created a while loop, setting the parameter to up to as many characters there are in the word. Here, I created an integer-based ASCII variable, which first took the character at a certain place depending on the counter, then returned it’s respective ASCII value. Here is where the two classes, Encrypt and Decrypt, were different. Encrypt had a +1 after the returnASCII and returnACharacter, this ensured that the letters were scrambled to go from ‘abc’ to ‘bcd,’ which actually resulted in a different character, which is where the encryption was happening. Decrypt did the opposite, returning a word to it’s original meaning by being able to go from ‘bcd’ back to ‘abc.’ After this ASCII variable was declared, I set a new variable which changed the numeric-integer value that the ASCII variable contained into a character, which would be turning the numeric value back into english alphabetic letters. Then, a simple line of code adding together each of the characters in order to build a word back up using characters, which would be concatenated into words.

When writing this code, I didn’t actually consult any online sources or something like stack overflow. Instead, I took the work that we did in class on Tuesday, the 21st of November, and added a few changes to it. Things that really aided me in this project included the creation of flowcharts which helped me understand what I was trying to accomplish, and the steps that it took for me to get there. From previous classes, I was able to understand that in order to turn the integer value back into a string, I had to concatenate it with an empty string, as indicated in my code. By doing this, I was able to create the flow of how my code worked.

Finally, after all pulling together, I was able to create a program that took a string that could take in all words and letters, and changed it into something different, an encrypted word! In a similar way, my program is also able to return an encrypted word into it’s generic english meaning, or at least back to whatever you were trying to hide…

Proof that it works:

Sorry about the quality of the second picture, blueJ doesn’t fold into new lines and I wanted to show off all of the symbols. You can click on it to enlarge it.

APCS: Creating a Basic File and Class on Terminal

Today we looked over creating a simple file and class on Terminal.

Through terminal, we were able to look through the difference functions that we could perform on the terminal bash.

The first step to the task of creating a file that we could carry out included creating a directory on our desktop, to do this, we use the syntax: ‘ cd desktop (finding the directory for the desktop) –> mkdir HelloWorld.java (creating the folder which will include the java file –> nano HelloWorld.java (opening the editing directory for the file)’ 

This opens up a directory on terminal that looks different (^^^as inserted above^^^)

Within this tab, we inserted the syntax:

public class HelloWorld {
public static void main( String[] args ) {
System.out.println( “Hello World!” );
System.exit( 0 ); //success

This, followed by:

‘ javac HelloWorld.java ‘


‘ less HelloWorld.java ‘

summons a window that shows you what it looks like on a window without code : )