There are two assignments in this lab. Everything is due by 11:59pm on Monday 8/18. If you do not finish in class, please save your .java files in google drive (or email them to yourself or put them on a USB drive or something) so you can finish at home. To submit your assignments, put them in your named google drive folder that I shared with you.
For a video version of this lesson, you can watch here: https://www.youtube.com/watch?v=3NCxXlbpMdI
1. Create a class named VariableFun (so it will be called public class VariableFun and your file will be saved as VariableFun.java). In this class, you will declare at least 3 variables (including at least one int, double, and boolean), then print out a statement or series of statements which incorporate each of your variables. Then, you will change the values of all 3 variables, and print out the same statement (although the values will have changed, of course).
The general structure of your program should look like this:
public class VariableFun
{
public static void main(String[] args)
{
//declare and set up the variables
// print out your statement
// change your variables
// print out the same statement again with the new values
}
}
As an example, my program could have 3 variables (int age, double salary, and boolean mathFavoriteClass). Then, it would print 2 statements that include each of these variables (changing them in the middle), perhaps like so (I have underlined the variables so you can see them in my output):
-Hello, you are 15 years old. You make $15.65 per hour, and it is true that math is your favorite class.
-Hello, you are 26 years old. You make $12.35 per hour, and it is false that math is your favorite class.
Feel free to use whatever variables and println statement that you like, this is just an example. Do something cool and creative. Once you are done and have tested your program, submit VariableFun.java to your named google drive folder.
2. In a new file (each class will be in a new file), create a class named ChangeTemp (public class ChangeTemp). This program will allow you to convert a temperature from Celsius to Fahrenheit and Kelvin, the most common units for measuring temperatures.
Create a program that makes a double variable for your temperature in Celsius (you can call it whatever you like and initialize it to any value), and then calculates and prints what the equivalent temperature would be in both Fahrenheit and Kelvin. Use these equations:
-To convert Celsius to Fahrenheit, multiply the Celsius temperature by 1.8 then add 32.
-To convert Celsius to Kelvin, add 273.15 to the Celsius temperature
For example, if you set up your initial Celsius temperature to be 20, your program would print out something like:
In Celsius, it is 20 degrees.
In Fahrenheit, that is 68 degrees. //because 20*1.8 + 32 = 68
In Kelvin, that is 293.15 Kelvins. //because 20 + 273.15 = 293.15
Submit ChangeTemp.java
As always, make sure all your .java files are in your google drive by the due date. Please send me an email (gborish(at)hartdistrict.org) if there are any questions. Have fun!