Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda March 8 1.PowerPoint Presentation on Variables. For download:

Similar presentations


Presentation on theme: "Agenda March 8 1.PowerPoint Presentation on Variables. For download:"— Presentation transcript:

1 Agenda March 8 1.PowerPoint Presentation on Variables. For download: http://members.shaw.ca/rzamar/IT11/Variables1.ppt http://members.shaw.ca/rzamar/IT11/VariableNotes.doc 2.Mastery Questions (5.2) on page 38. Download the Java source file ex52.java from: http://members.shaw.ca/rzamar/IT11/Unit5/ex52.java 3. Mastery Questions (5.3) on page 39. Download the Java source file ex53.java from: http://members.shaw.ca/rzamar/IT11/Unit5/ex53.java 4. Mastery Questions (5.4) on page 40. Download the Java source file ex54.java from: http://members.shaw.ca/rzamar/IT11/Unit5/ex54.java

2 The memory of a program is lot like a warehouse full of boxes.

3 A warehouse uses different boxes to store different types of items. If you are going to store soccer balls you need to use cubed shaped boxes. If you are going to store hockey sticks you need long rectangular shaped boxes. The type of boxes you use depend on the type of items you need to store.

4 A program uses different types of variables to store different types of values. If you want to store an integer value in your program you need to store it in a variable of type integer. If you want to store a string value in your program you need to store it in a variable of type string.

5 The boxes represent variables & the actual items being stored are specific values. Example of an Integer Variable

6 Example of a String Variable

7 Analogy Recap.

8 Variable Types (Table On Page 38) long num2 = 1332223423; // can store large integers double num3 = 3.14159; // can store decimal numbers char myChar = ‘c’;// can only store single characters boolean myBool = false; // can only store two values int num1 = 5;// can store integers String myString = “Hello!”; // can store many characters

9 Drawing Variables Different ways you can draw strings on your Applet: public void paint(Graphics screen) { screen.setColor(Color.blue); screen.drawString(“I am a blue string”, 25, 35); String s = “I am a gray string”; int x = 50; int y = 80; screen.setColor(Color.gray); screen.drawString(s + “!”, x, y); int myIntValue = 7; screen.setColor(Color.black); screen.drawString( “” + myIntValue, 100, 100); }

10 The output produced from previous paint method is shown below. The rectangle represents the Applet window. Drawing Variables Continued. I am a blue string I am a gray string! 7 (25,35) (50,80) (100,100)

11 Re-Using Your Variables // declare you variables here String country; public void init() { // initialize your variables here country = “Canada”; } public void paint (Graphics screen) { screen.drawString (country, 30, 30); // draws the word Canada country = “Spain”; // country now holds the value “Spain” screen.drawString (“I live in ”+ country + “!”, 30, 50); } I live in Spain!

12 // declare my variables int myAge; String myName; public void init() { // initialize variables myAge = 10 * 3; myName = “Zamar”; } public void paint (Graphics screen) { // print my variables out to the screen screen.drawString (“My name is Mr. ” + myName + “.”, 30, 30); screen.drawString (“I am ” + myAge + “ years old.”, 30, 50); } Drawing Integers

13 My name is Mr. Zamar. I am 30 years old.


Download ppt "Agenda March 8 1.PowerPoint Presentation on Variables. For download:"

Similar presentations


Ads by Google