Welcome ot Java Workshop - Lesson #1. This lesson is provided to you by class Code() at Virginia Tech.
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Go to Https://repl.it/Mrkm/9
This will let you edit and run code on your web browser! On the left, you will see a white screen. This is where all of your coding will go! We'll touch on this later.
On the right, you'll see what's being run. Don't worry about what's in there right now.
Step 2: Create Hello World
Every programmers first program is always the "Hello World!" program. It's a very simple program that just displays Hello World to the console (the screen).
Let's try it!
Replace: //PUT YOUR CODE HERE with System.out.println("Hello World!");
Step 3: Run Your First Program
Press the Run Button, and you should see Hello World! printed onto the console.
Now, replace everything inside the quotations with anything you want (try your name).
For example, try typing System.out.println("Programming is awesome!") and click run again!
Step 4: Look at the PowerPoint
Now, check out the powerpoint emailed to you. This will teach you in greater detail what we just did, what variables are, and how to define a type for a variable. You will also learn more advanced techniques such as casting.
Check out the powerpoint, and go to the next step once you are ready!
Note: If you want to see some actual results, type each of the examples on the powerpoint into the repl.it link provided earlier, and use System.out.println(); to display it. When you want to display a variable, just do System.out.println(x); where x is the name of the variable you chose.
Step 5: Tip Calculator Part 1 - Introduction
Now that you're back, let's get started on this great coding exercise!
We are going to make a basic Tip Calculator.
Start off by clicking this link: https://repl.it/MuCZ/12
You'll notice that there's a lot more text in this one. Don't worry! We'll make sure you're good with everything.
Step 6: Tip Calculator Part 2 - Add 3 Variables
Use the instructions to add three new marble variables: they are all doubles, and they should be called priceOfFood, tipPercent, and totalPriceOfFood. Don't give these values an initial value yet. Use the powerpoint if you need any help!
Step 7: Tip Calculator Step 3 - Find an Algorithm for the Total Price
There's a lot going on after you create the variables. This stuff is a little out of the scope of the tutorial, but feel free to research.
To sum it up: we are using a Scanner to scan user input from the console. First it takes the input of the price of the food without tip. Then, it takes the tip percent you want to pay. This stores values in the priceOfFood and tipPercent variables. Give a decimal number less than 1 for tip (something like .2).
Now it's time to calculate the total price. First, think of the algorithm that you would need to use to find this.
total price is equal to the price of the food plus the tip times the price of the food.
Now, write this in more mathematical terms;
total price = price of food + (tipPercent * price of food).
Lastly, write it out in Java
totalPriceOfFood = priceOfFood + (tipPercent * priceOfFood);
Step 8: Tip Calculator Part 4 - Test Your Code
Let's test your code!
When you click run, it should start by asking what the price of your food was. Enter a value, like 10 (don't put anything other than this). Then, it will ask you to give your tip percent. Give a value that is less than 1 (so something like .20).
Then, watch the magic!
Step 9: Conclusion
I hope you had a great time learning some basic Java. To sum up, today you learned how to print to the console, how to set up variables, and basic type definitions. We also learned stuff like casting, and even a little bit about scanning user input! That's an insane amount for your first time!
Use these replits whenever you want if you want to code on your own; they are all yours.
If you have any questions, please feel free to shoot us an email at firstname.lastname@example.org, or coming to our General Body Meetings. We will answer all questions you have at workshops, so feel free to stop by!