COMP 110: Introduction to Programming Tyler Johnson Feb 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.

Slides:



Advertisements
Similar presentations
Composition Program 09 Grading Workshop Conclusion Ellen Barton Director of Composition
Advertisements

COMP 110: Introduction to Programming Tyler Johnson Feb 11, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 18, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 20, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 13, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 26, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 12, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 8, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 1, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 28, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming
COMP 110: Introduction to Programming Tyler Johnson Mar 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 4, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Warm up.
Weather Discussion August 23-25, A local hotspot…
To 5th Grade! Blessings Ms Danza Rivera. School Bible Verse: Do your best to present yourself to God as one approved, a workman who does not need to be.
NANC Report Future of Numbering Working Group FoN Co-Chairs Jim Castagna, Verizon Don Gray, Nebraska PSC Adam Newman, Telcordia Technologies October 15,
Fun with Bridges KNEX Competition Engineering the Future: working together to enhance understanding, commitment and participation.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
2008 May 31Standards PD: Day 2 morning: slide 1 Feedback from Yesterday We want to begin today by reviewing some the things you said yesterday afternoon.
CISC Data Structures Ben Perry University of Delaware Summer 2011.
1 Cathay Life Insurance Ltd. (Vietnam) 27/11/20091.
Language Arts, Math, Science. Monday April 23 rd through Friday May 25 th Everyone needs to follow the provided schedule in order to ensure we get all.
Florida Internet Claims Filing System Power Point Presentation.
February 12, 2013 COMP Introduction to Programming For Statement and More Loops Haohan Li TR 11:00 – 12:15, SN 011 Spring 2013.
LESSON 4-1 Preparing a Chart of Accounts
25 seconds left…...
Current Assignments Homework 1 due in 4 days (June 16 th ) Variables, mathematical and logical operators, input/output, and the “ if ” operator. Project.
Lesson Objectives. 1. Learn how to finish Unit 4 Assessment 2.
We will resume in: 25 Minutes.
FINAL EXAMINATION SCHEDULE SPRING 2009 MAY 15 – MAY 22 NOTE: A class that meets at more than one of the times on this final examination schedule will take.
Web Time Entry Hours Entry in ESS 04/26/12 1 Banner.
Panel 3D = XML file pointer 08/09/20091 LHCb calorimeter meeting (jean-luc PANAZOL)
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt WHILE.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
02/25/2005ENEE408G Spring 2005 Multimedia Signal Processing 1 ENEE408G: Capstone Design Project: Multimedia Signal Processing Design Project 2: Video Processing.
1 COMP 110 Arrays Tabitha Peck M.S. March 31, 2008 MWF 3-3:50 pm Philips 367.
Revisions If you received the grade: “R” If you received the grade: “R” You must do a revision to receive a grade for lab 2. You must do a revision to.
COMP 110 If / Else and Case Statements Tabitha Peck M.S. February 4, 2008 MWF 3-3:50 pm Philips
COMP 110 Errors, Strings, and Review Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Scavenger Hunt Scavenger Hunt Scavenger Hunt BLACKBOARD SCAVENGER HUNT.
Welcome to CS 3260 Dennis A. Fairclough. Overview Course Canvas Web Site Course Materials Lab Assignments Homework Grading Exams Withdrawing from Class.
COMP Introduction to Programming Yi Hong May 13, 2015.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Catie Welsh January 10, 2011 MWF 1-1:50 pm Sitterson 014.
COMP 110 Constructors Luv Kohli October 13, 2008 MWF 2-2:50 pm Sitterson 014.
Computer Science II Spring Introduction Dr. Robb T. Koether Office: Bagby 114 Office phone: Home phone: (before 11:00 p.m.) Office.
Computer Science II Spring Introduction Dr. Robb T. Koether Office: Bagby 114 Office phone: Home phone: (before 11:00 p.m.) Office.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
Foundations of engineering design I Class 12 – Oct 2 manufacturing presentations + teaming activity.
COMP 110: Introduction to Programming Tyler Johnson Feb 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
How to submit an assignment to Turn It In Log in to Turn It In and select the class Find the assignment to be submitted Click “Submit”
COMP 110 More loops Luv Kohli September 15, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
COMP Loop Statements Yi Hong May 21, 2015.
DNA 2/8/16 Look at your data from Thursday’s lab… 1. Did the foods you tested contain the macromolecules that you thought they would? 2. Why did the Benedict’s.
Grading Transparent Clearly defined criteria for each grade No limits on how many students can get any particular grade No curve No preset or target median.
COMP 110 Augustus Gloop, Augustus Gloop… Luv Kohli September 24, 2008 MWF 2-2:50 pm Sitterson 014.
Physics 103 General Astronomy
Michele Weigle - COMP 14 - Spr 04
COMP 110 Loops, loops, loops, loops, loops, loops…
Recitation 2 September 2, 2011 Ben Newton.
Announcements Homework #2 scores in Blackboard
Presentation transcript:

COMP 110: Introduction to Programming Tyler Johnson Feb 23, 2009 MWF 11:00AM-12:15PM Sitterson 014

COMP 110: Spring Announcements Lab 3 & 4 as well as Program 2 are graded

COMP 110: Spring Submitting Assignments There is a penalty of 1-day late (25%) for all resubmissions You spend a lot of time on these assignments Spend a few minutes making sure youve submitted correctly Follow the instructions for checking your jar file Check the name of the file blackboard has received

COMP 110: Spring Lab 3

COMP 110: Spring Today in COMP 110 A few random things Objects & References

COMP 110: Spring If-Statement Example What is the output? int x = 7; int y = 5; if(y > x) x = x + y; System.out.println("y > x"); System.out.println("y <= x"); y > x y <= x Output

COMP 110: Spring If-Statement Remember to include curly braces for if- statement bodies that include multiple statements int x = 7; int y = 5; if(y > x) { x = x + y; System.out.println("y > x"); } System.out.println("y <= x");

COMP 110: Spring Local Variables What is the output of greet()? public class Example { private String str = hello; public void foo() { String str = goodbye; } public void greet() { foo(); System.out.println(str); } hello Output

COMP 110: Spring Local Variables What is the output of greet()? public class Example { private String str = hello; public void foo() { str = goodbye; } public void greet() { foo(); System.out.println(str); } 9 goodbye Output

COMP 110: Spring Accessors & Mutators public class Example { private double data; //private, can not be accessed directly //from OUTSIDE the class public double getData() { //this is an accessor return data;//this method is the ONLY way to access }//data public void setData(double newData) { //this is a mutator data = newData; //this method is the ONLY way to } //change data }

COMP 110: Spring Accessors & Mutators public static void main(String[] args) { Example e = new Example(); e.data = 6.5; //not allowed, data is private e.setData(6.5); //ok, only way to set data double d = e.getData(); //ok, only way to get data }

COMP 110: Spring DecimalFormat import java.text.DecimalFormat; DecimalFormat df = new DecimalFormat("0.00"); double number = ; System.out.println(df.format(number)); Output: "0.00" is the pattern that the format method will use to format its output Two digits after the decimal point, one digit before (but it will display all digits if more than one before) Fractional portion will be rounded 12

COMP 110: Spring DecimalFormat DecimalFormats format method returns a StringBuffer, not a String, but you can still print out a StringBuffer See Appendix 4 for more details 13

COMP 110: Spring Programming Demo Grading Program Two quizzes – 10 points each A Midterm and Final – 100 points each Final Exam – 50% Midterm – 25% Quizzes – 25% Functionality Read in a students score and display record

COMP 110: Spring Programming Demo Approach Instance variable for each score Method to read input Method to display student record Including final score and final grade (A-F) Use two helper methods –One to calculate final score –Other to get final grade

COMP 110: Spring Programming Demo Programming

COMP 110: Spring Objects & References Section 5.3 in text

COMP 110: Spring Variables of a Primitive Type Variables of primitive type hold a value int a = 6; double d = 6.55; boolean b = a > d; We can say The value of a is 6 The value of d is 6.55 The value of b is false

COMP 110: Spring Variables of a Class Type What is the value of a variable of a class type? Student jack = new Student(); //what is the value of jack? Classes can have multiple data members public class Student { public String name; public int year; public double GPA; public String major; //… }

COMP 110: Spring Variables of a Class Type The value of a variable of a class type is a memory address The address of the object it refers to Student jack = new Student(); //jack holds the address of the newly created //object of the Student class The address to this other location is called a reference to the object Class types are also called reference types

COMP 110: Spring Example: Books public class Book { private String name; private int page; public void setPage(int page) { this.page = page; } public void setName(String name) { this.name = name; }

COMP 110: Spring Example: Books Assume we have a class named Book Book jacksBook = new Book(); Book samsBook = new Book(); //each object refers to a different book vs. Book jacksBook = new Book(); Book samsBook = jacksBook; //samsBook refers to the same object as jacksBook

COMP 110: Spring Objects in Memory jacksBook samsBook ???? Memory Book jacksBook; Book samsBook; jacksBook = new Book(); jacksBook.setName("Java"); samsBook = new Book(); samsBook.setName("Java"); jacksBook.setPage(137); samsBook.setPage(253); samsBook = jacksBook; samsBook.setPage(509); jacksBook is now on p. 509! ???????? ? Java ? Java ? Java ? Java ? Java 137 Java 253 Java 137 Java 253 Java ? ???? ?

COMP 110: Spring Remember Variables of a class type contain memory addresses NOT objects themselves

COMP 110: Spring == Operator on Objects The == operator checks whether the values of two variables are the same The value of class variable is a memory address When using the == operator to compare two objects, you are checking whether they have the same address in memory

COMP 110: Spring == vs. equals() for Strings Explained String is a class type What is the result of String s1 = new String("Hello"); String s2 = new String("Hello"); boolean strEqual = (s1 == s2); strEqual is false! Why? s1 and s2 store different addresses!

COMP 110: Spring == vs. equals() for Strings explained What is the results of String s1 = new String("Hello"); String s2 = new String("Hello"); boolean strEqual = (s1.equals(s2)); strEqual is true! Why? Strings.equals() method checks if all the characters in the two Strings are the same

COMP 110: Spring Defining an equals Method Every class has a default.equals() method Returns whether two objects of the class are equal in some sense Does not necessarily do what you want You decide what it means for two objects of a specific class type to be considered equal by writing your own.equals() method Perhaps books are equal if the names and page numbers are equal Perhaps only if the names are equal Put this logic inside.equals() method

COMP 110: Spring Writing the.equals() Method public class Book { private String name; private int page; //… //two books are equal if their name and pages are equal public boolean equals(Book book) { return (this.name.equals(book.name) && this.page == book.page); }

COMP 110: Spring Parameters of a Primitive Type public void increaseNum(int num) { num++; } public void foo() { int x = 5; increaseNum(x); System.out.println(x); } What is the output? 5

COMP 110: Spring Parameters of a Class Type public void changeBook(Book book) { book = new Book("Biology"); } public void foo() { Book jacksBook = new Book("Java"); changeBook(jacksBook); System.out.println(jacksBook.getName()); } What is the output? Java

COMP 110: Spring Parameters of a Class Type public void changeBook(Book book) { book.setName("Biology"); } public void foo() { Book jacksBook = new Book("Java"); changeBook(jacksBook); System.out.println(jacksBook.getName()); } What is the output? Biology 32

COMP 110: Spring Wednesday Constructors