Intro to Java - RobotGirls/FTC-Team-25 GitHub Wiki
Java is a high-level, class-based, object-oriented programming language.
- An object-oriented programming language organizes data into "objects" that are made up of things like methods, variables, or data structures
- A class-based languages organize data into a certain format called a "class". A class is like a blueprint for how an object looks
- High-level programming languages abstract details of the computer. These languages take more memory and are less efficient, but they make it easier for humans to understand and debug
VS Code is a source code editor that can be used with many programming languages, we'll use it for practice so you can get familiar with how to write, compile, and run code on your own
These sites below that can help explain some basic concepts. The best way to understand programming is to just play around with it, so these sites also include short exercises that can help you familiarize yourself with how it all works. Feel free to look through the other pages on the site, I'm just highlighting a few that I think will be most helpful
More practice:
- Write a program that prints your age in days
- Start with a variable for your age in years
- Use operators to calculate how many days your age in years is
- Display the result in system output
- Write a program that
More practice:
- Write a program that prints your name 5 times
- Write a program that prints only the numbers between 1-50 that are divisible by 7
- Write a program that prints all numbers between 1-50. If that number is a multiple of 4, also print the word "Fizz". If that number is a multiple of 9, print the word "Buzz". If that number is a multiple of 4 and 9, print the word "FizzBuzz"
-
Linked Lists
- A specific Linked List exercise to try that mirrors some of the structures in the FIRST infrastructure:
- Go to https://www.w3schools.com/java/tryjava.asp?filename=demo_linkedlist_add
- Paste the following code into the editor:
- A specific Linked List exercise to try that mirrors some of the structures in the FIRST infrastructure:
import java.util.LinkedList;
// class named Main
public class Main {
String name;
int grade;
String clubs;
// class constructor with 2 arguments
public Main(String nm, int grd) {
name = nm;
grade = grd;
clubs = "n/a";
}
// class constructor with 3 arguments
public Main(String nm, int grd, String clb) {
name = nm;
grade = grd;
clubs = clb;
}
public static void main(String[] args) {
// create a new linked list of Main types
LinkedList<Main> roster = new LinkedList<Main>();
// create a Main type named newStudent
Main newStudent;
// replace newStudent information with information for another student
newStudent = new Main("John", 10, "soccer");
roster.add(newStudent);
// replace newStudent information with information for another student
newStudent = new Main("Jane", 9);
roster.add(newStudent);
// loop through the linked list, printing out student information
System.out.println("NAME\tGRADE\tCLUBS");
for(int i=0; i<roster.size(); i++) {
System.out.println(roster.get(i).name + "\t" + roster.get(i).grade + "\t" + roster.get(i).clubs);
}
}
}
Try making these changes to the code:
- How would you add another student's information, Jack in grade 7 who hasn't joined any clubs?
- How would you add another student's information, Jill in grade 11 who's in the debate and robotics clubs?
- How would you change the order that information is printed out?
- How would you add another field to the student's information table, one of type String called "classes"?