Goal: Find out what variables are and what they do.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Variables and Names /// File Name: VariablesAndNames.java /// Date Finished: Sep. 11, 2015 public class VariablesAndNames { public static void main( String[] args ) { int cars, drivers, passengers, cars_not_driven, cars_driven; double space_in_a_car, carpool_capacity, average_passengers_per_car; cars = 100; space_in_a_car = 4.0; drivers = 30; passengers = 90; cars_not_driven = cars - drivers; cars_driven = drivers; carpool_capacity = cars_driven * space_in_a_car; average_passengers_per_car = passengers / cars_driven; System.out.println( "There are " + cars + " cars available." ); System.out.println( "There are only " + drivers + " drivers available." ); System.out.println( "There will be " + cars_not_driven + " empty cars today." ); System.out.println( "We can transport " + carpool_capacity + " people today." ); System.out.println( "We have " + passengers + " to carpool today." ); System.out.println( "We need to put about " + average_passengers_per_car + " in each car." ); } }
Goal: Work with variables to store some data.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Saving Information in Variables /// File Name: CreatingVariables.java /// Date Finished: Sep. 11, 2015 public class CreatingVariables { public static void main( String[] args ) { int x, y, age; double seconds, e, checking; String firstName, last_name, title; x = 10; y = 400; age = 39; seconds = 4.71; e = 2.71828182845904523536; checking = 1.89; firstName = "Cornelius"; last_name = "Eanes"; title = "Mr."; System.out.println( "The variable x contains " + x ); System.out.println( "The value " + y + " is stored in the variable y." ); System.out.println( "The experiment completed in " + seconds + " seconds." ); System.out.println( "My favorite irrational number is Euler's constant: " + e ); System.out.println( "Hopefully your balance is more than $" + checking + "!" ); System.out.println( "My full name is " + title + " " + firstName + last_name ); } }
Goal: Learn how to use variables in the printing methods.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: More Variables and Printing /// File Name: MoreVariablesAndPrinting.java /// Date Finished: Sep. 11, 2015 public class MoreVariablesAndPrinting { public static void main( String[] args ) { String myName, myEyes, myTeeth, myHair; int myAge, myHeight, myWeight; myName = "Cornelius A. Eanes"; myAge = 17; // not a lie myHeight = 67; // inches myWeight = 130; // lbs myEyes = "Brown"; myTeeth = "White"; myHair = "Dark Brown"; System.out.println( "Let's talk about " + myName + "." ); System.out.println( "He's " + myHeight + " inches tall." ); System.out.println( "He's " + myWeight + " pounds." ); System.out.println( "Actually, that's not too heavy." ); System.out.println( "He's got " + myEyes + " eyes and " + myHair + " hair." ); System.out.println( "His teeth are usually " + myTeeth + " depending on the coffee." ); // This line is tricky; try to get it exactly right. System.out.println( "If I add " + myAge + ", " + myHeight + ", and " + myWeight + " I get " + (myAge + myHeight + myWeight) + "." ); } }
Goal: Create and use some variables.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Using Variables /// File Name: UsingVariables.java /// Date Finished: Sep. 15, 2015 public class UsingVariables { public static void main(String[] args) { int roomNumber = 113; double e = 2.71828; String courseName = "Computer Science"; System.out.println("This is room # " + roomNumber); System.out.println("e is close to " + e); System.out.println("I am learning a bit about " + courseName); } }
Goal: Print out some information about yourself using variables.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Still Using Variables /// File Name: UsingVariables2.java /// Date Finished: Sep. 15, 2015 public class UsingVariables2 { public static void main(String[] args) { String name = "Cornelius A. Eanes"; int graduationYear = 2016; System.out.println( "My name is " + name + " and I'll graduate in " + graduationYear + "." ); } }
Goal: Work with variables using some basic arithmetic operations.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Mathematical Operations /// File Name: MathOperations.java /// Date Finished: Sep. 15, 2015 public class MathOperations { public static void main(String[] args) { int a, b, c, d, e, f, g; double x, y, z; String one, two, both; a = 10; b = 27; System.out.println("a is " + a + ", b is " + b); c = a + b; System.out.println("a + b is " + c); d = a - b; System.out.println("a - b is " + d); e = a + b * 3; System.out.println("a + b * 3 is " + e); f = b / 2; System.out.println("b / 2 is " + f); g = b % 10; System.out.println("b % 10 is " + g); x = 1.1; System.out.println("\nx is " + x); y = x * x; System.out.println("x * x is " + y); z = b / 2; System.out.println("b / 2 is " + z); System.out.println(); one = "dog"; two = "house"; both = one + two; System.out.println(both); } }
Goal: Print out your schedule, using variables to store the data.
/// Name: Cornelius Eanes /// Period: 5 /// Program Name: Your Schedule /// File Name: MySchedule.java /// Date Finished: Sep. 15, 2015 public class MySchedule { public static void main(String[] args) { String course1 = "AP AB Calulus"; String course2 = "Study Hall"; String course3 = "Economics"; String course4 = "English IV"; String course5 = "Computer Programming"; String course6 = "AP Engineering"; String teacher1 = "Mr. Ball"; String teacher2 = "Mr. Dax"; String teacher3 = "Mr. Bremer"; String teacher4 = "Mr. Ridenour"; String teacher5 = "Mr. Davis"; String teacher6 = "Mr. Becker"; System.out.println(); System.out.println("+----------------------------------------------+"); System.out.println("| 1 | " + course1 + " | " + teacher1 + " |"); System.out.println("| 2 | " + course2 + " | " + teacher2 + " |"); System.out.println("| 3 | " + course3 + " | " + teacher3 + " |"); System.out.println("| 4 | " + course4 + " | " + teacher4 + " |"); System.out.println("| 5 | " + course5 + " | " + teacher5 + " |"); System.out.println("| 6 | " + course6 + " | " + teacher6 + " |"); System.out.println("+----------------------------------------------+"); System.out.println(); } }