--change first one to only 3 variables. cut the char?
There are three assignments in this lab. Everything is due by 12:00pm (noon) on Sunday 8/13. 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
**please use camelNotation for all your variables with more than one word. Use "double initialAmount;" instead of double IA; or double initialamount or something else weird. A name like "int radius" is fine.
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 4 variables (including one of each primitive type - int, double, char, and boolean. Remember that chars need a single quote around them, like char yourGrade = 'A'), then print out a statement or series of statements which incorporate each of your variables. Then, you will change all 4 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 statement again with the new values
}
}
As an example, my program could have 4 variables (char lastName, 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 Mr. B, you are 25 years old. You make $15.65 per hour, and it is true that math is your favorite class.
-Hello Mr. G, 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 three 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 you want), 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 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
3. Create a program named Circle.java (public class Circle) that sets up an int variable for the radius of a circle. Your program should then calculate and set up variables for the diameter, circumference and area of that circle. It should then print out each of those. Remember diameter = 2r, circumference = 2*pi*r, and area = pi*(radius squared).
You can set up pi like so:
final double PI = 3.14159;
For example, if you declare that a radius variable with a value of 10, it should print out that the diameter is 20, area is 100pi, and the circumference is 20pi (it will print out decimal equivalents of the last two).
Test your code to make sure it gives correct answers, then submit Circle.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!