L01 - Visual Studio Code (VS Code) Lab
- Install Visual Studio Code from FIRST, you will need their version with WPILib. Link
- In this exercise, we'll use an IDE to enter and execute a Java program. Start and the following window will appear:
- Select the File > Open and either open a folder to use as the workspace or create a new one
- Create a new file File > New File
- Save the file as Test.java
- Add the following code to start your program.
public class Test { }
- Add these standard comment lines at the start of the Class (use your name and the current date), this goes above line 1:
/** * Print the Answer to Life, the Universe, Everything. * @author Enter your name * @version Enter today's date */
- Enter the following code starting inside your class.
public class Test { static int answer1 = 0; static int answer2; static int theAnswer; public static void main(String[] args) { answer1 = 20; answer2 = 2 * answer1; theAnswer = answer2 + 2; System.out.println("The answer is..."); System.out.println(theAnswer); } }
- To run the program, press run above the main method. The output should be:
The answer is....42
- Create a new file named
ComputeCA
. - Create a class in the file named the same as the file name. It always has to be the same. Your class and file name should ALWAYS start with a capital letter.
- Change the class description to
Computes the circumference and area of a circle
. - Change the author and the version by entering your name and today's date, respectively.
- Enter the signature for the main method, this signature is:
public static void main(String[] args){ }
- Declare a variable named
radius
of typedouble
that has a value of 4.5. - Declare another variable named
circumference
of typedouble
that has the value of 2π × radius. Use 22.0/7.0 for the value of π. - Declare a third variable named
area
of typedouble
that has the value of π × radius2. To easily compute the radius2, multiply the radius by itself. - Display the value of the
circumference
. - Display the value of the
area
.Circumference: 28.285714285714285 Area: 63.64285714285714
Java API Documentation
If you have enough screen real estate, open your browser and visit http://java.oracle.com then follow the link to the API documentation. Having the API window always available speeds up the development process.
No Comments