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

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

    21-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    2

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

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

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.

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.

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.

Questions?

4

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

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.

Debugger

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Friday

Lab 5

Classes

32