APCSA Final Project #4 – Final Coding Checkup, Unsolved Challenges, Reflection

Challenges that I solved from the last checkup:

On the last checkup, I still had some unsolved issues that I needed to solve.

I was able to solve my last bug with the help of Mr. Lin, were my conversion from the ArrayList<Student> to the 2D Student Array. When I tried coding this, I tried using the designated rows and cols as my parameters in a for loop but that did not work properly as I needed a way to also print out successive Students from the ArrayList. I was able to solve the issue by using multiple count methods.

Instead of having a nested for loop, I used only one while loop and two counts: count and  . The count would increase with every run of the while loop and would only increase while count was less than the number of columns designated. Colcount is another counter that increases for every loop, however, when the counter is divisible by the number of columns, it increases the row number.

I also applied this to my GUI which I will get into more later.

Implementation of GUI and debugging:

The GUI was definitely the most challenging thing to code and required a lot off troubleshooting to get work. In the end, I wasn’t able to fully create what I wanted but there will be more on that in the challenges section. In my GUI, I was able to create a user interface that showed the seating chart for a certain list of students in a specific order. The precondition was that the tables must be separated (no grouped tables like we see in our classes).

In my GUI, I was able to create multiple buttons, labels, textfields, and attach icons to these things by using  java.awt.* and java.swing.*;

In order to code this, I mainly used an external library called acm which I had to import. This helps with creating the GUI and starting it, allowing for certain graphic elements to be implemented.

In order to code the actual use of the buttons, I used java.awt.event.* to insert ActionListeners and ActionCommands to program buttons to do and read certain things. Below will be my code.

Final Challenges:

Overall coding the buttons and different labels and such was not the greatest problem. But printing out the seating chart within the GUI was a task a had a lot of trouble with.

My initial idea was to create the chart within the GUI below the buttons and labels. My first idea was to create a label per student, but that quickly appeared not to work as the number of students was a variable that could not be applied to creating new labels with new positionings.

I tried to do it like such but it did not work.

My next idea was to simply use one label and concatenate a the student onto one String, and set the singular label as the String. This too did not work. My initial idea to create a blank temporary String add the names/numbers did not work as the label was never big enough and would simply print … In order to combat that, I tried setting dimensions to the label.

This did not solve the problem as every time I tried to create the chart, nothing would show up. I had to try finding a different method in order to solve this issue. Instead, was I did was every time the button to create the chart was clicked, a new JFrame was created. As long as the String did not exceed the limits of the new window, the String could be as long as it wanted. This fixed my initial problem of printing the chart out.

This, unfortunately, lead to another major issue, line breaks. I wanted to visualize the rows and columns with line breaks and spaces between the students. I quickly learned that line breaks within JLabels were not possible. I tried using multiple methods: I used “\n”, “\r”, System.lineSeparator(), System.getProperty(“line.separator”), and html tags. The html tags did work when line-breaking a simple String, but when I tried to add different instance variables to the method, it did not print out the inherent Strings but the names of the variables themselves (eg. if String test = “abc”, it would not print out “abc” but “test” itself).

While browsing the internet, I did find a glimmer of hope: a package created just for the issue.

I downloaded and manually imported the package into my project in order to use its custom methods and classes, but still did not work. I tried looking through its README textfiles and comments to no avail.

(the sas package)

This leads me to my final and yet unresolved problem. I am still unable to create the visual representations of rows and columns and instead had to explicitly state when a new row should appear.

Conclusions and Reflections

Overall the project was a challenging one, where I spent hours debugging and learning new solutions to my problems. Coding the GUI was difficult but fun because I was able to create an interactable interface which allowed for a more dynamic experience for the one using the code. I am kind of bummed out that I was not able to fully achieve what I had planned, but I am still proud of the effort and time I put into the creating what I have created so far.

Final Code:

YouTube Video


APCSA Final Project #3 – Coding Checkup Part 1

Check-in on coding process part 1: Basic coding before GUI.

So far in the coding process, I have completed the first four classes – Tester, Student, SeatingList, and SeatingArrangement.



The tester is self-explanatory: it creates new instances of Student, creates a seating list with the students, and arranges them in specific ways.


The Student class includes a constructor for the name and student ID and stores them as private field variables. There are two methods for the class: getStudentNumber() and getName().


The SeatingList class will take multiple students and incorporate them into an array list of students. Within the class, there are multiple methods to reorient lists through alphabetical order, numerical order of the student ID, and random order.



The seating arrangement class took the seating list from the SeatingList class and arranged it into a 2D Student array, where one index would represent one table. The postcondition is that the tables are separated and not clumped into groups of four.

Some challenges I ran into:

One of the first challenges I ran into was a NullPointerException in the Seating List class.

I was trying to create a method to add new Student objects into the ArrayList but I kept on getting a NullPointerException. I came to realize that was because ClassList was not properly initialized and simply declared as an ArrayList<Student> in the fields, therefore the null Student e (the parameter) could not be “added” to the list. Therefore, in order to solve the issue, I simply changed private ArrayList<Student> ClassList;  to ArrayList<Student> ClassList = new ArrayList<Student>();

Another problem I ran into was the implementation of the alphabetical sort method. What I was trying to do was sort the Students by implementing a selection sort (which in itself was a problem that I had to search up to refresh my memory) where the first letters of the names were converted into Ascii values to be compared with other letters. However, if two first letters were the same, I would somehow have to go to the second letter and compare them. So far I have yet to solve the problem.

The most recent problem I have run into is a bug with the converting the seating list to the 2D array.

Instead of printing the desired 2D array, it only got one of the Student objects from the list and printed that one person over and over. I created a test method to just print out the list, and it did show all the different Student objects. I am also still trying to fix this issue.

APCSA Final Project #2 – Getting started with the coding

Starting the coding process: skeleton code/mind map.

The first step in the process was to start up the code. I first separated my overall project into 5 classes:

  1. Tester
  2. Student
  3. SeatingList
  4. SeatingArrangement
  5. GUI

The first four would create these seating charts and the fifth class would represent it in a visual and interactive way.

I have yet to implement the GUI elements but know that I need to use swing and awt standard libraries.

(Below shown in mindmap but easier to see here)

 Class  Description
 Student -two variables of name and student ID

 -incorporates an ArrayList of students

-includes methods that can reorient a list


 -representing a class list as a 2D array where

each index represents a table

 GUI  -shows the seating arrangement in a visual       and interactive sense
 Tester  -tests the different methods by printing them out


APCSA Final Project #1 – Research and Idea Brainstorm

Overall Idea: Use GUI, libraries, and packages to create an interactive game (or something of the sort)

Research Topics Explanation   Examples

GUI is a graphical user interface which allows users to interact with the program through visual queues. This is an example of a GUI which allows the user to interact with the program by clicking different icons to navigate to different pages.

How to use GUI and code GUI in BlueJ:



Libraries in Java are represented in jar files (basically a zip file for classes) and can be referenced in the classpath to be invoked by other classes.

How to add libraries:

If you want to add in just one library or so, drag and drop the jar file into the project file and type import BLANK;

If you want to add in multiple projects, go to BlueJ -> Preferences -> Libraries -> Add user libraries from config


Packages in Java are encapsulations of multiple classes or sub-packages and are similar to libraries in the sense that libraries group up packages. Eg. API groups up all default packages such as java.util.*

Users can also create their own packages and import them with myPackages.packagename.


Code Idea Brainstorm:

Simple interactive “Choose your own adventure” game.

Why it could work Questioning the idea

-Can implement GUI effectively and import game libraries.

-Easy to play and understand for players.

-Can I fully demonstrate my coding knowledge (as it would only use System.out.println)?

-Is it original enough?

Student Class List and Seating

Why it could work Questioning the idea

-Can implement GUI effectively by showing class seating arrangement.

-Can demonstrate my full understanding of my coding abilities.


-Will I be able to complete the task to completion?



Create a modifiable class list and changeable student seating GUI.

8. Java Coding – Searching and Sorting + ArrayLists

For this formative, I made code for searching and two methods of sorting: the insertion sort and the selection sort using my main class ArrayLists and the SearchAndSortMethods class.

(Some of the actual sorting code was taken from StackOverflow)

Some challenges that I encountered during this was trying to find out how to set elements in an ArrayList, get the length of an ArrayList, and return the values of elements in an ArrayList. I found out that the methods were different, where instead of using .length() you use .size(), arr(#) you use arr.get(#), and arr(#) = b you use arr.set(#,b).


7. Java Coding – Encryption Decryption (S)

This project for me was a very tenuous one. I had switched my ideas from my original ideas almost last minute, which gave me quite a hard time. The reason for my switch was the difficulty of the cipher I was initially trying to do. At the start, I wanted to do a Chinese style transposition which did not require a key and instead arranged the message in a unique way. However, I was struggling to assign the number of columns and rows for the 2D array I was trying to make. In the end, I spent hours trying to find out how to fix my problems but was unable to until the last day. Because of this, I decided to take a risk by choosing a different cipher that may have been more do-able for me, which was the Caesar cipher. The Caesar cipher is a special type of cipher where characters in a message and shifted multiple alphabetical characters to the right of the left. I moved the characters two units to the right and printed them as numbers to create a more original spin on the classic cipher. From there, I would decrypt the encrypted message by shifting the numbers two left and then getting the corresponding characters for the numbers.

Flowchart for initial Transposition Cipher:

Transposition Cipher Code (Worked when I got it from the internet but couldn’t explain it):

Flowchart for final Caesar Cipher:

Verbal Analysis:

Code in Action:

Final Code:


6. Java Coding – Encryption and Decryption

Encryption and Decryption

Three methods:

  1. Substitution Ciphers: Switching specific letters for other letters

Eg. Caesar Cipher: rotating letters three up (A is D) and numbers are the same

  1. Transposition Ciphers: Switch the orders of the same letters/numbers
  2. ASCII Ciphers: Converting characters to ASCII numerical values

4. Java Coding – Using Multiple Classes and Constructors to Make a Game Intro

First we were tasked to make an adventure game. In the adventure game, I made 2 classes representing my main method, and the other class consisting of my user constructor and many different scenarios that could come from the adventure game.

The Run class would simply run the program, while the Character class had all of the content.

(An example of a method following to another method)

After that, I made another program only consisting of the making of the user, but I incorporated more classes to make it more compact.

The player class acts as the main method to the whole program. The user class only consists of the contructor for new classes. The intro class only serves the purpose to interact with the players and store their users (Scanner). The wait class would serve as a quick wait method, where a certain amount of seconds would pass in-between text to make it look better.

(The intro method would repeat if there is an invalid input)