![Page 1: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/1.jpg)
COMP 110Classes
Tabitha Peck M.S.
February 20, 2008
MWF 3-3:50 pm
Philips 367
1
![Page 2: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/2.jpg)
Announcements Lab 4 Due Friday
Office Hours - Today after Class Help with loops Help with Lab 4
Jason Jerald
2
![Page 3: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/3.jpg)
Participants Needed for Virtual RealityMotion Perception in Virtual Environments During Head Turns
What you get Learn about programming in a research environment Learn what grad students are doing in computer science Help contribute to improving virtual reality technology Earn real money
The task select which of two presentations you believe contains scene motion 600-1000 trials Earn $.05 for each correct selection - Do the math! Study takes 3-5 Hours
For more info Filling out form is not committing Name Preferred contact (email or phone) Preferred hours
3
![Page 4: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/4.jpg)
Questions?
4
![Page 5: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/5.jpg)
Today in COMP 110
Worksheet Review (quick)
Debugger
Classes
5
![Page 6: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/6.jpg)
Debugger
![Page 7: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/7.jpg)
What is the length?
t h i s i s a s t r i n g
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
7
![Page 8: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/8.jpg)
Classes
wagTail
Terrier
bark
Retriver
beg
Shepard
DogClass
Object
Methods
8
![Page 9: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/9.jpg)
Classes
nextInt
keyboard
next
sc
nextDouble
s
ScannerClass
Object
Methods
9
![Page 10: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/10.jpg)
Classes
getMajor
Jack
calcGpa
Amanda
increaseYear
Spencer
StudentClass
Object
Methods
10
![Page 11: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/11.jpg)
UML Diagram
11
Class Name: Student
Class YearGPAMajorCreditsGPA sum
+ getMajor+ printData+ increaseYear
How: increase year by 1+ calcGPA
How: average grades
![Page 12: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/12.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade): void+ printData(): void
12
![Page 13: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/13.jpg)
Class File
Each class in SEPARATE file Create instance of Class in main You will have TWO (or more) files!! Call methods in main You must run your file from main!!!!!!!
13
![Page 14: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/14.jpg)
Create instance of Class in main
public class StudentStats{
public static void main(String[] args){
// instantiating object of type student Student s1 = new Student();
}} Class Object Class
Different NameFrom Class
14
![Page 15: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/15.jpg)
Create Class in Separate File
public class Student{
//everything in your class goes here
} Save as Student.java
15
![Page 16: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/16.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade): void+ printData(): void
16
![Page 17: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/17.jpg)
Data (in your class file)
17
public int classYear;private double gpa;public String major;private int credits = 0;private double gpaSum; private - only access variables INSIDE
your class public - access to variables OUTSIDE your
class
![Page 18: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/18.jpg)
Public Variables
Student s1 = new Student();
s1.classYear = 2;
classYear is a variable NOT a method Don’t use ()
18
![Page 19: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/19.jpg)
Private Variables
Variables you do not want a user to manipulate
GPA - calculate GPA in your class Don’t want user to reset the value
19
![Page 20: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/20.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade): void+ printData(): void
20
![Page 21: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/21.jpg)
Method getMajor
/*getMajor
Input: none
Return: major*/
public String getMajor()
{ return major;
}
21
Return type
Type String
![Page 22: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/22.jpg)
Calling method getMajor
22
public static void main(String[] args){ Student s1 = new Student(); s1.major = “English”; String m = s1.getMajor(); System.out.print(m);}
![Page 23: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/23.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade): void+ printData(): void
23
![Page 24: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/24.jpg)
Method increaseYear/*increaseYearInput: noneDescription: increase student year by oneReturn: none*/
public void increaseYear(){ if (classYear < 4) classYear++;
}
24
![Page 25: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/25.jpg)
Calling method increaseYear
25
public static void main(String[] args){ Student s1 = new Student(); s1.classYear = 2; s1.increaseYear(); // classYear = 3 s1.increaseYear(); // classYear = 4 s1.increaseYear(); // classYear = 4}
![Page 26: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/26.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade): void+ printData(): void
26
![Page 27: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/27.jpg)
Method calcGpa/*calcGpaInput: grade(double)Description: update credits and gpaSum
calculate GPAReturn: none*/
public void calcGpa(double grade){ credits++; //increase number of credits gpaSum = gpaSum + grade; gpa = gpaSum / credits;}
27
![Page 28: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/28.jpg)
Calling method calcGpa
28
public static void main(String[] args){ Student s1 = new Student(); s1.calcGpa(3.5); //gpa = 3.5 s1.calcGpa(2.4); // gpa = 2.95 }
![Page 29: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/29.jpg)
UML DiagramClass Name: Student
Class Year (int)GPA (double)Major (String)Credits (int)GPA sum (double)
+ getMajor(): String+ increaseYear(): void+ calcGPA(double grade1, double grade2): void+ printData(): void
29
![Page 30: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/30.jpg)
Method printData/*printDataInput: noeDescription: print instance variablesReturn: none*/
public void printData(){DecimalFormat df = new DecimalFormat("0.00"); System.out.print("Major: " + major + ”\nClass year: " + classYear + ”\nGPA: " + df.format(gpa));
}
30
![Page 31: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/31.jpg)
Code on Website
Open the code
Save the code
Understand the code
Run the code
31
![Page 32: COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1](https://reader034.vdocument.in/reader034/viewer/2022051619/56649d565503460f94a34a25/html5/thumbnails/32.jpg)
Friday
Lab 5
Classes
32