These exercises allow you to practice creating variables, putting values in them, and displaying them on the screen.
Put your code in a new empty Java file named "VariableExercises.java", and make sure to name the class VariableExercises.
Your code should start with the structure below:
Within the method named part1(), write
code that creates three variables: an int a
double, and a String.
Put the value 113 into the first variable, the
value 2.71828 into the second, and the value "Computer Science" into the third. It does not
matter what you call the variables... this time.
Then, display the values of these three variables on the screen, one per line.
For this part, you must use println() only. You
may not use printf().
113 2.71828 Computer Science
Write a method that stores your name and year of graduation in variables, and displays their values on the screen.
Make sure that you use two variables, and that the variable that holds your name is the best type for such a variable, and that the variable that holds the year is the best type for that variable.
For this part, you must use println() only. You
may not use printf().
Also make sure that your variable names are good: the name of a variable should always relate to its contents.
My name is Juan Valdez and I'll graduate in 2009.
Notice that in the example above, the values "Juan Valdez" and 2009 have been stored in variables before printing.
Use several variables to store the names of your classes and their teachers. Then, display a nice little table displaying your schedule.
For this part, you must use println() only. You
may not use printf().
Your table doesn't need to look exactly like this, or even line up. I used a total of sixteen variables (course1, course2, ... course8, teacher1, teacher2, etc.). You should do the same.
+------------------------------------------------------------+ | 1 | English III | Ms. Lapan | | 2 | Precalculus | Mrs. Gideon | | 3 | Music Theory | Mr. Davis | | 4 | Biotechnology | Ms. Palmer | | 5 | Principles of Technology I | Ms. Garcia | | 6 | Latin II | Mrs. Barnett | | 7 | AP US History | Ms. Johannessen | | 8 | Business Computer Infomation Systems | Mr. James | +------------------------------------------------------------+