A list of coding exercises to help get you from “Beginner” to “OK”
- Hello World: Create a program that outputs “Hello World”.
- Loop: Create a program that loops 10 times and output the current loop (ex. “I’m on loop 6”, then “I’m on loop 7”).
- First Class: Create a class called “Car” that has 1 variable called “licensePlate”. Within the class, create a default constructor that sets “licensePlate” to ‘Unknown’ and a method/function called “getLicensePlate” that returns the variable “licensePlate”.
- Second Class: Add a second Car constructor to our class that takes 1 input of type String. This is the license plate number. Assign the value of the inputLicensePlate to our variable licensePlate.
- Inheritance: Create an abstract class called “Vehicle”. Within “Vehicle”, create a variable called ‘wheels” and create a method/function called “getWheels” and return the variable wheels with that method. In addition, create an abstract method/function called “washVehicle”. NOTE: Usually you would create an Abstract class BEFORE creating the concrete class implementation (so you’d create Vehicle and then extend Car/Motorcycle after that) but in this specific case I wanted to make sure everyone knew how to create a simple class before going on to an Abstract class.
- Inheritance pt. 2: Make your Car class from before inherit from the Vehicle class. Alter the constructors accordingly and override the necessary functions/methods. In the Car class, your “washVehicle” method should output a String that reads “I’m going through the car wash!”.
- Inheritance pt. 3: Create a “Motorcycle” class that inherits from the Vehicle class. Create the necessary constructors (wheels = 2, etc). For the “washVehicle” method, output a String that reads “I’m washing my motorcycle by hand!”.
- Version Control: Create a GitHub project repository and upload your code there.
- Critique: Share your GitHub project here if you have any questions or want any critiques!
- Profit: Make $200k because you’re now the greatest developer since Bill Gates.
EDIT: More problems.
- Fibonacci Sequence Calculator: From an interview with a fairly popular messaging app company in Asia. Create a program that calculates the nth number in the Fibonacci sequence. What is the your runtime? Can you think of any better ways to calculate it?
- Design Exercise: You are tasked with creating the battle system for Creative Assembly’s “Total War Warhammer”. The following are the requirements:
- A battle is in real time between 2 players (one AI, one human player)
- Each player has anywhere from 1 to 20 units (or squads)
- Each unit is comprised of anywhere from 1 to 120 individual models.
- Every model within the unit has the same stats (attack, defense, armor, etc) EXCEPT for “current health” (which will change as the battle progresses).
- Each model does damage to an enemy model based on a formula Creative Assembly uses (I’ll add this when I remember where it was)
- A player wins when the enemy has no more units
- For simplicity’s sake, start off with Player A having 1 unit of melee units and Player B having 1 unit of melee units.
- Minimum Viable Product: Battle Report should output a list of each player’s units before the battle. Upon 1 player’s victory, another Battle Report should be generated that states the winning players current unit’s, unit size, etc. No need to display graphics, a simple text will do.
- At a high level, how would you design this? Would you use an inheritance structure or something different? How would you scale your program from 2 total units in combat to 20 vs 20 (with potentially thousands of models engaging in combat)? Are there any constraints to the language you’re using? If I added a requirement of “only IndividualModels within X distance of the enemy can attack”, how would you approach this?
- Island Counter: This was from an interview with a midsized company for a Backend Dev position: You have a 2-dimensional array (or grid) of 1’s and 0’s. The 1’s represent “land” and the 0’s represent “water”. An island is defined as a group of at least 1 “1” that is surrounded by water. It is assumed that the edges outside of our grid are water for the sake of simplicity. Create an algorithm that calculates how many UNIQUE islands are present in our grid. What is your runtime? Is there any improvement that can be made to your runtime?
- Multi-threading: I’d like to input a multi-threading problem in here, but I can’t think of one off the top of my head. I’ll edit later as I think of it.
- Data Pulls: You are the developer for an organization that needs data from different data sources. These data sources are comprised of databases (Oracle, MySQL, Postgres), copying and pulling flat files (.txt, .csv, .tsv), using FTP to pull an XML file, and a potential for many future data sources to be added. You are tasked with creating a brand new “data pull program” that manages the various data source pulls. All data sources must be written to a file of some kind and stored on a generic file server in any format you wish (so SQL query results should be written to a file and then sent to the destination).
- How would you design this? What language would you use? Are there any frameworks/libraries you can think of that would assist you?
- What are some potential issues you could run into? What sort of Unit Tests would you write to test out the various pulls?
- How would you manage to QA each file to ensure it is complete and accurate (with no dropped data between source and destination)?