comp 110: introduction to programming tyler johnson apr 27, 2009 mwf 11:00am-12:15pm sitterson 014
TRANSCRIPT
![Page 1: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/1.jpg)
COMP 110:Introduction to Programming
Tyler JohnsonApr 27, 2009
MWF 11:00AM-12:15PMSitterson 014
![Page 2: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/2.jpg)
COMP 110: Spring 20092
Announcements
Final exam Monday May 4, 12 noonIn this room
Program 5 due today by 5pm
![Page 3: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/3.jpg)
COMP 110: Spring 20093
Questions?
![Page 4: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/4.jpg)
COMP 110: Spring 20094
Final Exam
20% of final grade
Exam will be cumulativeLecturesReadings from textbookLabsProgramsMidterm
No computers, notes, calculators etc.
You will be allowed a 1-page cheat-sheet
![Page 5: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/5.jpg)
COMP 110: Spring 20095
Today in COMP 110
Review for Final
![Page 6: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/6.jpg)
COMP 110: Spring 20096
Objects/Arrays & Memory
The value of an object is a memory address
Student s1 = new Student("Jack Smith", 2342342);Student s2 = new Student("Jack Smith", 2342342);
s1 == s2 is false!
Arrays are objects!
![Page 7: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/7.jpg)
COMP 110: Spring 20097
What is the Output?
int a = 7;int b = a; b = 8;
System.out.println("A: " + a);System.out.println("B: " + b);
A: 7
B: 8
Output
//a is not changed by this
![Page 8: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/8.jpg)
COMP 110: Spring 20098
What is the Output?
int[] a = {4, 5, 6};int[] b = a;b[0] = 3;
System.out.println("a: {" + a[0] + ", " + a[1] + ", " + a[2] + "}");
System.out.println("b: {" + b[0] + ", " + b[1] + ", " + b[2] + "}");
a: {3, 5, 6}
b: {3, 5, 6}
Output
//b holds same memory address as a//we’re changing both b & a!
This is like giving the array two names (a & b)
![Page 9: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/9.jpg)
COMP 110: Spring 20099
Array Assignment
int[] a = {4, 5, 6};int[] b = a;b[0] = 3;
4 5 6a
b
3
![Page 10: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/10.jpg)
COMP 110: Spring 200910
Copying Arrays
int[] a = {4, 5, 6};int[] b = new int[a.length]; //create a new array b
//copy a’s entries into bfor(int i = 0; i < b.length; b++) {
b[i] = a[i];}
![Page 11: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/11.jpg)
COMP 110: Spring 200911
What is the Output?
public void changeNumber(int num) {num = 7;
}
public static void main(String[] args) {int a = 9;changeNumber(a);System.out.println("a = " + a);
int num = 9;changeNumber(num);System.out.println("num = " + num);
}
a = 9
num = 9
Output
![Page 12: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/12.jpg)
COMP 110: Spring 200912
What is the Output?
public void changeNumber(int num) {num = 7;
}
public static void main(String[] args) {int[] a = {4, 5, 6};
changeNumber(a[0]);System.out.println("a: {" + a[0] + ", " + a[1] + ", " + a[2] + "}");
}
a: {4, 5, 6}
Output
![Page 13: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/13.jpg)
COMP 110: Spring 200913
What is the Output?
public void changeArray(int[] array) {array[0] = 7;
}
public static void main(String[] args) {int[] a = {4, 5, 6};
changeArray(a);System.out.println("a: {" + a[0] + ", " + a[1] + ", " + a[2] + "}");
}
a: {7, 5, 6}
Output
![Page 14: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/14.jpg)
COMP 110: Spring 200914
What is the Output?
public void changeArray(int[] array) {array = new int[3];array[0] = 7;array[1] = 5;array[2] = 6;
}
public static void main(String[] args) {int[] a = {4, 5, 6};
changeArray(a);System.out.println("a: {" + a[0] + ", " + a[1] + ", " + a[2] + "}");
}
a: {4, 5, 6}
Output
![Page 15: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/15.jpg)
COMP 110: Spring 200915
Graphical Example
public void changeArray(int[] array) {array = new int[3];array[0] = 7;array[1] = 5;array[2] = 6;
}
public static void main(String[] args) {int[] a = {4, 5, 6};
changeArray(a);System.out.println("a: {" + a[0] + ", " + a[1] + ", " + a[2] + "}");
}
4 5 6a
array 7 5 6
a: {4, 5, 6}
Output
![Page 16: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/16.jpg)
COMP 110: Spring 200916
Review Worksheet
![Page 17: COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014](https://reader036.vdocument.in/reader036/viewer/2022062618/551410bb550346dd488b5069/html5/thumbnails/17.jpg)
COMP 110: Spring 200917
Course Evaluation