Sample Projects for a Beginner Programmer
Episode 8, walks through sample coding projects that have a text-based UI.
What is a text-based UI?
First, let’s define what UI means.
A UI (User Interface) is something that allows a user to interact with a system. A UI is simply an intermediary for input and output. In web applications, the UI (often called a GUI — Graphical User Interface) is the screen containing graphics you can interact with. For instance, a GUI may have graphics such as text or images for output, and buttons or text boxes for input.
As a refresher, input into a system is any information that a user sends to a system. Alternatively, output is any information that a system sends to a user. We use the word ‘system’ because input/output doesn’t necessarily need to be used in the context of computers. In our case, of course, we’re generally referring to a program/application or a computer when we use the word ‘system’.
A program with a text-based UI is an application that lacks all graphical components for input and output. Instead, all output will be strings of text printed to the console, and all input will be entered by the user in the console from the keyboard when prompted.
Console is a synonym for the Terminal application. Terminal is an example of an application with a text-based UI since it prints text as output to the user and takes text as input from the user.
The way input works in a text-based UI application is as follows: the application either continuously waits (or listens) for the user to type something on their keyboard and then press enter.
Commands in Terminal:
- cd: change directories
- ls: list files
- dir: display list of all files and subdirectories within a directory
Text Editors: applications that programmers use for typing code for their coding projects.
- VIM: used in your terminal (“text editor inside the command land”)
- Sublime: can be downloaded for free on the web
- TextEdit (on Mac)
IDE (Integrated Development Environment): applications that contain a text editor, console, debugger, and other important tools for programmers to create, run, and debug their programs.
IDES that you can download for free online—
- Visual Studio: suitable for most programming languages
- Eclipse: suitable for Java
- Android Studio: most suitable IDE for Android development
- Xcode: most suitable IDE for iOS development on Mac OS
There are many IDEs to choose from. Be sure to choose the one most suitable for your goals.
Libraries in a programming language:
A library is a unit of code, often organized into a class based on the purpose or functionality, that other programmers can use within their programs. For example, File.java is a Java file containing the library for the File class.
A library is a collection of definitions and/or functions written in a specific programming language. Each programming language typically provides several libraries as standards for commonly used functionalities. It’s often best programming practice to avoid re-creating the wheel. This means, your goal is to use libraries (code that other programmers have already created) to minimize the amount of effort spent rewriting code that already exists. For instance, the Document Editor project example that Kathryn covers in Episode 8 relies on several methods from the String library.
- Functions vs. class methods: A method is a defined like a function, but gets called on an object. A method is a function that can only be called on an object of the class it is defined in. (Note: in Java, variable names for objects typically begin with a lowercase letter.) In Java, you call a method on an object by using the dot operator (.). When using the String library in Java, split is considered a method because you call split on a String object. A function is just like a method except that you don’t call it on an object. You call a function by importing the library in which the function is defined, and then type the class name (note: class names typically begin with an uppercase letter) followed by the dot operator (.), followed by the function call. If your function is defined within the same file that calls the function, you can omit the class name and dot operator.
“Parse a string”: refers to the process of examining each individual character in a string, in order.
Data types: float (Floating Point) vs. double (Double Floating Point):
If you open your calculator app and enter 100 / 3, the result will be 33.33333…
If we want to store a decimal value (such as the result of 100 divided by 3) as a variable in a computer program, we’d need to declare the variable’s data type as either a float or a double.
The difference between a float and a double is the amount of space that main memory provides for each. A double is typically given twice as much space in memory as a float (depending on your machine and possibly the programming language you’re using — if your programming language even has data types). What that means for values such as 33.33333… or 3.1415926… is that a double can store many more decimal places than a float.
For the purposes of our ATM simulator project, you don’t need to think about these differences, as they’re somewhat trivial here. They will be relevant as you progress as a software developer. But for now a float will provide sufficient space for our balance variable in the ATM simulator code.
Hardcoding values for variables means that you assign an explicit value to a variable. When we declare our balance variable in the ATM simulator and set its value to 50.25, shown below, we are hardcoding the balance variable:
float balance = 50.25;
Global Variable vs. Local Variable
A global variable in Java is defined within a unit of code (i.e., a class) but outside of a function. A global variable is public to all the files within your project’s directory. This means that any class file that resides in the same directory can access the variable. A global variable exists throughout the entire execution (start to end) of a program. Any changes to a global variable’s value will persist throughout the program’s execution.
A local variable is a variable that is defined within a function and only exists during the execution of (the call to) the function. Its value will not be persisted, meaning that it will be reset to whatever value it was originally hardcoded to be each time the function is called. Additionally, since it only exists within a function, the variable can only be accessed within the function.
What are we referring to when we say the “Execution of a Program”?
The execution of a program is everything that occurs on your computer beginning when you run (start/launch/execute/open) the program and ending when you terminate the program (or the program terminates itself). Hence, the execution of an application refers to the time that you launch it, up until you close it.
Switch Statements: an alternative to using if, else if, else if, …, else statements.