Forum Posts

William Li
Dec 02, 2021
In Introduction to Java
Today we learned the following: -If/else statements review if statements use the following format: if (boolean_expression) { //run something } else { //if the code in the if block isn't ran, run this } boolean_expression should equal true in order for the code in the block to be ran. Else ifs are also used, but you must have an if statement first. If the first one isn't satisfied, it'll run the following until it reaches the end or the else statement. Note that once an if or if else condition is met none of the other blocks will run. We then completed several problems that involved the use of if statements and a kahoot. Nested if-else: We can put two if statements inside one another. That way, the code inside the second will only be run if both are true, and code inside the first will be run if only that one is true.
0
2
10
William Li
Nov 11, 2021
In Introduction to Java
In today's class, we reviewed concepts we've been learning over the past few weeks, such as flow structures. Refer to previous posts if a refresher is needed. We then practiced this by doing two kahoots and some practice problems such as https://drive.google.com/file/d/0B8J8S-phorS-WkdaYkNEM29uejQ/view?resourcekey=0-BPl1qwxFmuErTcNBH57q7Q. Homework for this week can be found here: https://docs.google.com/forms/d/e/1FAIpQLSegJfIjB8Egdajk3mETgipHcK3tGF2ANJh81vBYxrXhRzUOng/viewform?usp=sf_link Have a great Veteran's Day!
0
1
6
William Li
Oct 28, 2021
In Introduction to Java
Today in class, we learned about: - Control structures Normally, code will execute in a sequential manner. This is the simplest version of code, but we can make more complex programs as well. There are three fundamental control structures: Sequential control, which is a form of execution where the code is run line by line in the order that they appear. There are other types of flows as well, and they can be found here along with diagrams of the structures: https://drive.google.com/file/d/1oc1SGn1B4NFyqTYEM6Bu73IP75UAARXL/view Decision Control structures are dependent on boolean, or whether something is true or false. This lets them decide whether to run a piece of code or not. For example, the if statement only runs what's in the brackets if the condition is met, or true. Loop Control structures loop for a certain amount of times or until a condition is met: For loops loop for a certain amount of times. A for each loops through each element in a data type such as an array. While loops run until a condition is met. Note that this means if you run the code while (True) { //do something } it will run forever or until the break; function is called. Another sequence type is a subroutine. These perform a specific task and are packaged in a unit, referred to as a function or a method. This can be called wherever applicable. When called, the program will wait for it to finish executing before continuing. In the second part of the class, we put this information to use by trying out some practice problems on https://www.lol-101.com/classrooms/introduction-to-java/2-8-project-analyzing-before-coding.
0
1
7
William Li
Oct 07, 2021
In Introduction to Java
Today we went over: Standard functions and methods These are basically preset functions that we can use that are provided to us by the Java Standard Library. For example, after importing java.lang.Math, we have access to methods such as the following: (a full list can be found at https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html) Then we did some practice problems and 2 Kahoots. Homework for this week can be found here: https://docs.google.com/forms/d/e/1FAIpQLSedXfCxD0EeQ1pQYysIw3jgRBXZGsD_3oldmzlPDf7WvbfCvw/viewform?usp=sf_link As always, I'll try and get the solution out by Tuesday night.
10/6 notes content media
0
1
17
William Li
Sep 23, 2021
In Introduction to Java
In today's class, we started by reviewing the homework, and then we learned about the following: - Variables Variables are handy for several reasons. They simplify code especially in repetition of one phrase (such as post.comment.comment1 which can be shortened with a variable down to "comment1"). To initialize a variable in Java, we use <data type> <variable name> = <assigned value>; For example: int thisIsANumber = 39494; If you don't know the value of the variable yet, you can alternatively use <data type> <variable name>; Which lets you assign a value to it later. Refer to https://www.lol-101.com/classrooms/introduction-to-java/2-2-how-to-declare-and-initialize-variables-for-computation for primitive types and their limitations as well as a slightly more in depth explanation. - Classes A class is where a program is saved. It's a good practice to name the class based on what it's for, such as BankBalance. - Functions A function is also known as a method. The first function called is always main(), because each Java program needs a place to start. As beginners we'll start by only coding in main, and once we get more familiar with functions, classes, and the keywords that go along with them, we'll start to use other functions and classes more and more. For further reference on the above two you can visit https://drive.google.com/file/d/1zrjDYIQVM0fVDCNTCDRNH_3jeXXNX3rc/view. - Naming conventions Names must start with a letter or an underscore. *The others should be alphanumeric. *Avoid special characters (or basically anything that doesn't fall under the category of "alphanumeric") Spaces are not allowed. Names in Java are case sensitive. Reserved words such as "int" or "class" are not allowed. *Class names should be nouns with the first letter capitalized, and methods/functions should be verbs written in camelcase. Variables should be nouns as well, and the first letter should be lowercase. These should not start with an underscore or a $. *One character names should be avoided because they create confusion as to the purpose of the variable. Anything with a * is technically allowed in Java and should compile fine. However, it is generally a bad practice and should be avoided. Some non-alphanumeric characters are allowed in Java as names, but you will rarely see these.
0
2
15
William Li
Sep 16, 2021
In Introduction to Java
Today in class, we learned about: - Algorithms and pseudo-code. When solving a problem using code, we need steps to solve it, and this list of steps is an algorithm. An example is a morning routine: function morningRoutine() { getOutOfBed(); while (hair == messy) { combHair(); } takeShower(); eatBreakfast(); brushTeeth(); leaveForSchool(); } Note that this is written in Pseudo-code, which is talked about below: Pseudo-code is written in the style of code, but won't run properly in an actual IDE. This is a great way to understand the code you're writing and can be a first step in developing an effective algorithm. In the code I wrote above, each "function" within the morningRoutine function is an activity one would normally do to get ready for school. There is no correct way to write pseudo-code, but it's best to write in a style that you and other people will understand later. You can, however, write it in the style of a programming language, and in the example above it looks similar to Javascript. - System.out.printf() We learned about System.out.print() and System.out.println() last class, but this week we learned about a new function, printf(). This lets you format the output you want. For example: System.out.printf("%.2f", Math.pi); Will print out π to 2 decimal places. You can find references for the printf() function here: https://docs.oracle.com/javase/tutorial/java/data/numberformat.html When using print functions, special characters are reserved. For example, " is reserved because it is used to tell the compiler that the phrase you want to output is finished. In order to actually output a ", you must use an escape character, \. The backslash itself is a reserved character, which means to print it out, you need to use \\. More escape sequences can be found at https://www.tutorialspoint.com/escape-sequences-in-java.
0
3
66
William Li
Sep 12, 2021
In Introduction to Java
On Wednesday's class, we learned basic components of a computer, as well as what an IDE is, using an online IDE (repl.it and codiva.io), using System.out.print and System.out.println, and using line breaks (\n) in your System.out.println. Homework from Wednesday can be found here: https://docs.google.com/forms/d/e/1FAIpQLSeX9eHc9sFH3-Nt8X5By16Vttk0cRE0rEZoGwSuXnqix0idMg/viewform?usp=sf_link I will aim to post the solution to the homework the evening of the day before the next class. However, answers for this one will vary because everyone has different names. If you know that you will miss any classes in the future, please email Ian so he can record the meeting.
1
1
24
W
William Li

William Li

More actions