1 / 32

COMP 110 Classes

COMP 110 Classes. Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367. 1. Announcements. Lab 4 Due Friday Office Hours - Today after Class Help with loops Help with Lab 4 Jason Jerald. 2.

rhian
Télécharger la présentation

COMP 110 Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 110Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips 367 1

  2. Announcements • Lab 4 Due Friday • Office Hours - Today after Class • Help with loops • Help with Lab 4 • Jason Jerald 2

  3. 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

  4. Questions? 4

  5. Today in COMP 110 • Worksheet Review (quick) • Debugger • Classes 5

  6. Debugger

  7. What is the length? 7

  8. Classes Class Object Methods 8

  9. Classes Class Object Methods 9

  10. Classes Class Object Methods 10

  11. UML Diagram Class Name: Student Class Year GPA Major Credits GPA sum + getMajor + printData + increaseYear How: increase year by 1 + calcGPA How: average grades 11

  12. UML Diagram Class 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

  13. 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

  14. Create instance of Class in main publicclass StudentStats { publicstaticvoid main(String[] args) { // instantiating object of type student Student s1 = new Student(); } } Different Name From Class Object Class Class 14

  15. Create Class in Separate File publicclass Student{ //everything in your class goes here } • Save as Student.java 15

  16. UML Diagram Class 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

  17. Data (in your class file) 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 17

  18. Public Variables Student s1 = new Student(); s1.classYear = 2; • classYear is a variable NOT a method • Don’t use () 18

  19. 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

  20. UML Diagram Class 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

  21. Method getMajor /*getMajor Input: none Return: major*/ public String getMajor() {return major; } Return type Type String 21

  22. Calling method getMajor publicstaticvoid main(String[] args) { Student s1 = new Student(); s1.major = “English”; String m = s1.getMajor(); System.out.print(m); } 22

  23. UML Diagram Class 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

  24. Method increaseYear /*increaseYear Input: none Description: increase student year by one Return: none*/ publicvoid increaseYear() {if (classYear < 4) classYear++; } 24

  25. Calling method increaseYear publicstaticvoid main(String[] args) { Student s1 = new Student(); s1.classYear = 2; s1.increaseYear(); // classYear = 3 s1.increaseYear(); // classYear = 4 s1.increaseYear(); // classYear = 4 } 25

  26. UML Diagram Class 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

  27. Method calcGpa /*calcGpa Input: grade(double) Description: update credits and gpaSum calculate GPA Return: none*/ publicvoid calcGpa(double grade){ credits++;//increase number of credits gpaSum = gpaSum + grade; gpa = gpaSum / credits;} 27

  28. Calling method calcGpa publicstaticvoid main(String[] args) { Student s1 = new Student(); s1.calcGpa(3.5); //gpa = 3.5 s1.calcGpa(2.4); // gpa = 2.95 } 28

  29. UML Diagram Class 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

  30. Method printData /*printData Input: noe Description: print instance variables Return: none*/ publicvoid printData() {DecimalFormat df = new DecimalFormat("0.00");System.out.print("Major: " + major +”\nClass year: " + classYear +”\nGPA: " + df.format(gpa)); } 30

  31. Code on Website • Open the code • Save the code • Understand the code • Run the code 31

  32. Friday • Lab 5 • Classes 32

More Related