Methods & Classes COMP163

Size: px
Start display at page:

Download "Methods & Classes COMP163"

Transcription

1 Methods & Classes COMP163

2 People think that computer science is the art of geniuses, but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones. Donald Knuth

3 Convocation The Fall Convocation will be on Thursday, November 1, at 10:00am in Harrison Auditorium All classes are cancelled on November 1 from 10:00 to noon Students in section 5, the 10:00 lab section, will not have lab this week Section 5 students do not have to do the lab assignment The other sections WILL have lab as scheduled

4 ZyBooks Read chapter 10 except section 10.9 of the ZyBooks online textbook and answer all of the participation questions Due by midnight on Sunday, November 4, 2018

5 Static Variables Class variables can be specified as static public class electric { static int cow; // static class variable int goat; // non- static class variable There is only one copy of a static variable shared by all objects of that class There is a separate copy of non-static variables for each object

6 Multiple Objects public class Electric { static int cow = 1; int goat = 2; Electric possum = new Electric(); Electric rat = new Electric(); Electric mouse = new Electric(); There are three Electric objects Each object has its own copy of goat There is only one cow variable

7 Static and Instance Variables There is only one cat variable, but there is a dog for every object Electric class cow possum rat mouse Electric object goat 1 Electric object goat Electric object goat 2 2 2

8 Using Instance Variables public class Electric { static int cow = 1; int goat = 2; public void cow2() { cow = cow + 2; public void goat3() { goat = goat + 3; public void prtcow() { System.out.println(cow); public void prtgoat() { System.out.println(goat); Electric volt = new Electric(); Electric watt = new Electric(); volt.cow2(); watt.goat3(); displays volt.prtcow(); 3 volt.prtgoat(); 2 watt.prtcow(); 3 watt.prtgoat(); 5

9 public class SandD { static int snake = 1; int dog = 5; void plusboth() { snake++; dog++; System.out.println(snake+" "+dog); static public void main(string[] x) { SandD goat = new SandD(); SandD pig = new SandD(); goat.plusboth(); pig.plusboth(); What is displayed? A B C D

10 Data in Every Object When you create an object of a class, the object contains its own copy of each non-static variable Static variables are not separate for each object

11 Making Multiple Objects public class Wombat { public int koala; private double roo; public Wombat( int cat, double dog) { koala = cat; roo = dog; goat cow // in another class Wombat goat = new Wombat( 3, 1.5 ); Wombat cow = new Wombat( 2, 4.7 ); koala 3 roo 1.5 koala 2 roo 4.7

12 final variables A variable declared as final cannot be changed If you want to define a constant value, it should be declared final final int MAXTHINGS = 10; Variables that are final must be initialized with a value It is good programming practice to put constants at the beginning of the program instead of using a number throughout the code

13 final is final final variables must be initialized when they are declared You will get a compiler error if you try to change a final variable final double dragon = 47.0; dragon = -3.5; // this will get an error

14 static Constants Typically a program constant would apply to all objects in a class Therefore it is useful to make constants static so there is only one copy public class Both { private static final int MAXSIZE = 12; Variable attributes can be in any order final static private int MAXSIZE = 12;

15 Review of Variable Attributes public variable can be used anywhere private variable can only be used in the same class static variable belongs to the class not objects. Only one copy final variable cannot be changed

16 Attributes on Instance Variables public class Modified { public static int dog; private final double cat; public void doit( int bull) { public int cow; // not allowed final int GERBIL = 7; dog = (double)bull + GERBIL;

17 What is displayed? Wombat cat = new Wombat( 3, 4.0 ); Wombat dog = new Wombat( 5, 7.0 ); dog.koala = cat.koala; cat.koala = 2; System.out.println(cat.koala+" "+dog.koala); A. 2 3 B. 3 5 C. 3 2 D. 2 5 E. none of the above

18 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); frog toad Egg yolk bird

19 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); bird.whites Egg.yolk 2 frog toad 2 4

20 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); bird.whites 4 Egg.yolk 2 frog toad 2 4

21 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); bird.whites 4 Egg.yolk 2 lizard

22 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); bird.whites 4 Egg.yolk 3 frog lizard.whites toad 3 5

23 Only One Copy of Static Variables public class Egg { static int yolk; int whites; public Egg(int frog, int toad) { yolk = frog; whites = toad; // In another class Egg bird = new Egg( 2, 4 ); Egg lizard = new Egg( 3, 5 ); bird.whites 4 Egg.yolk 3 frog lizard.whites 5 toad 3 5

24 Static and Non-static A non-static variable can only be accessed by non-static methods Non-static variables belong to the object A static variable can be accessed by any method Static variables belong to the class

25 Static and Non-static Example public class Program { static int statdata = 3; int dydata = 1; void inc() { dydata++; statdata++; // non-static method public static void main(string[] x) { Program thing = new Program(); Program other = new Program(); thing.inc(); statdata = 2; dydata = 5; thing.dydata = 7; // not Allowed // this is allowed

26 Static or Non-static? If a method uses class instance variables, it cannot be static If a method does not use any class instance variables, it can be static

27 Hashtable This week's programming assignment requires you to use a java.util.hashtable object A hash table is a data structure that stores information with a keyword You can later retrieve the information by using that keyword Hash tables make it very easy to save data and find it later

28 Creating a HashTable java.util.hashtable<keyword type, data type> dog = new java.util.hashtable<>(maxsize); java.util.hashtable<string, WordValue> cat = new java.util.hashtable<>(22000); java.util.hashtable<string, String> goat = new java.util.hashtable<>();

29 Using a Hashtable The Hashtable class has two useful methods mytable.put( keyword, data) Adds the data to the table under the specified keyword mytable.get( keyword ) Returns the data previously added under that keyword or null if there is no such data goat.put("anteater", "aardvark"); String frog = goat.get("anteater");

30 Instance and Local Example public class PermTemp { static int aardvark = 1; 1 public static void main(string[] uu) { addto( 2 ); addto( 1 ); static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark); aardvark termite ant Output

31 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

32 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

33 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

34 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { 9 3 int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

35 Instance and Local Example public class PermTemp { static int aardvark = 1; 3 public static void main(string[] uu) { addto( 2 ); addto( 1 ); static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark); aardvark termite ant Output 9 3

36 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { 9 3 int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

37 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { 9 3 int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

38 Instance and Local Example public class PermTemp { aardvark termite ant static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); Output static void addto( int ant ) { 9 3 int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark);

39 Instance and Local Example public class PermTemp { static int aardvark = 1; public static void main(string[] uu) { addto( 2 ); addto( 1 ); static void addto( int ant ) { int termite = 7; aardvark = aardvark + ant; termite = termite + ant; System.out.println( termite+" "+ aardvark); aardvark termite ant Output

40 Static or Not If all objects are going to share the variable, make it static If each object should have its own value, do not make it static If a method uses instance variables, it cannot be static If a method does not use any instance variables, it can be static

41 What is displayed? public class Teach { public int cat = 2; public Teach(int dog) { cat = dog; public void prtcat() { System.out.print(cat); public class MyProg { public static void main( ) { Teach mine = new Teach(5); Teach yours = new Teach(3); mine.prtcat(); yours.prtcat(); A. 2 2 B. 3 3 C. 5 3 D. 5 5

42 Queuing Theory Queuing theory is the mathematics of waiting lines It is extremely useful in predicting and evaluating system performance

43 Single or Multiple Queues M/M/N Bank Teller model λ S S S M/M/1 Grocery Store model λ /2 λ /2 S S

44 Queuing Theory The probability that all n servers are busy in an M/M/N system (bank teller model) is C where N sk K C 1 1 N i i s N i i s i i K 0! ) ( 1 0! ) (

45 Example Method Write a method that returns the value C given the three input parameters lambda(λ), s and n The method will have the header double proballbusy( double lambda, double s, int n)

46 Solution Outline In the equation for K, the denominator is a sum that is the same as the numerator except that it is one term longer If we have a method to calculate the sum, the rest of the method is simple

47 proballbusy method double proballbusy( double lambda, double s, int n) { double k = ksum(lambda, s, n-1) / ksum(lambda, s, n); return (1.0 - k) / (1.0 lambda*s*k/n); 1 K C sk 1 N K N 1 ( s) i 0 i! N i ( s) i 0 i! i

48 ksum method The ksum method calculates this sum given the parameters lambda, s and n N i ( 0 i! s i ) We will need a method to calculate factorials

49 factorial method The factorial function in mathematics, n!, is 1 * 2 * 3 * 4 * * n For the special case of zero, 0! = 1

50 The header for factorial should be A. int factorial( int n ) B. void factorial( int n, int fac ) C. static factorial( int n ) D. none of the above

51 Write the factorial method With your team, write a method with one integer parameter, n, that returns n! Don t forget the special case for zero You might not have to do anything special

52 Possible Solution int factorial( int n ) { int fac = 1; for (int i =1; i <= n; i++) { fac = fac * i; return fac;

53 Write the ksum method Write a method to calculate this sum given the parameters lambda, s and n N i ( 0 i! s i ) double ksum( double lambda, double s, int n )

54 Possible Solution double ksum( double lambda, double s, int n ) { double sum = 0.0; for (int i = 0; i <= n; i++) { sum += Math.pow( lambda*s, (double)i ) / factorial( i ); return sum;

55 It looks Greek to me double ksum( double λ, double s, int n ) { double sum = 0.0; for (int i = 0; i <= n; i++) { sum += Math.pow( λ*s, (double)i ) / factorial( i ); return sum;

56 Small Steps The value of using methods is that you can break a larger problem into small steps The proballbusy method called the ksum method twice ksum called factorial Note that we wrote the program using methods we had not yet written, but knew we could write

57 Recursion (N-1)! is 1 * 2 * 3 * 4 * * N-1 N! is 1 * 2 * 3 * 4 * * N-1 * N or (N-1)! * N If you have a factorial method that computes (N-1)!, you can calculate N! by multiplying the result of the method by N You need to be mindful that N-1 might drop to zero

58 Recursive Solution int factorial( int n ) { if (n <= 1) return 1; return n * factorial( n-1 );

59 Methods and Object Data Methods belong to a class or object Methods can use all instance variables, parameters and local variables In a typical program, you keep the data in instance variables which is accessed and modified by methods

60 Convocation The Fall Convocation will be on Thursday, November 1, at 10:00am in Harrison Auditorium All classes are cancelled on November 1 from 10:00 to noon Students in section 5, the 10:00 lab section, will not have lab this week Section 5 students do not have to do the lab assignment The other sections WILL have lab as scheduled

61 ZyBooks Read chapter 10 except section 10.9 of the ZyBooks online textbook and answer all of the participation questions Due by midnight on Sunday, November 4, 2018

Loops. GEEN163 Introduction to Computer Programming

Loops. GEEN163 Introduction to Computer Programming Loops GEEN163 Introduction to Computer Programming Simplicity is prerequisite for reliability. Edsger W. Dijkstra Programming Assignment A new programming assignment has been posted on Blackboard for this

More information

Using Classes. GEEN163 Introduction to Computer Programming

Using Classes. GEEN163 Introduction to Computer Programming Using Classes GEEN163 Introduction to Computer Programming Unless in communicating with it one says exactly what one means, trouble is bound to result. Alan Turing talking about computers Homework The

More information

Review for the Third Exam COMP163

Review for the Third Exam COMP163 Review for the Third Exam COMP163 On the plains of hesitation lie the blackened bones of countless millions who at the dawn of victory lay down to rest, and in resting died. Adlai E. Stevenson to the United

More information

One Ring to rule them all, One Ring to bring them all,

One Ring to rule them all, One Ring to bring them all, Binding COMP360 One Ring to rule them all, One Ring to find them, One Ring to bring them all, And in the darkness bind them. inscription on the One Ring J. R. R. Tolkien Reading Read chapter 10 of the

More information

Object Orientated Programming Details COMP360

Object Orientated Programming Details COMP360 Object Orientated Programming Details COMP360 The ancestor of every action is a thought. Ralph Waldo Emerson Three Pillars of OO Programming Inheritance Encapsulation Polymorphism Inheritance Inheritance

More information

Decisions, Decisions, Decisions. GEEN163 Introduction to Computer Programming

Decisions, Decisions, Decisions. GEEN163 Introduction to Computer Programming Decisions, Decisions, Decisions GEEN163 Introduction to Computer Programming You ve got to be very careful if you don t know where you are going, because you might not get there. Yogi Berra TuringsCraft

More information

Using Classes. GEEN163 Introduction to Computer Programming

Using Classes. GEEN163 Introduction to Computer Programming Using Classes GEEN163 Introduction to Computer Programming The history of all previous societies has been the history of class struggles. Karl Marx Programming Assignment The first programming assignment

More information

More Methods GEEN163

More Methods GEEN163 More Methods GEEN163 There is method to her madness. TuringsCraft Read the material in chapter 7 of the textbook Answer the questions in section 7 of the TuringsCraft tutorial 4 points for each correct

More information

Bjarne Stroustrup. creator of C++

Bjarne Stroustrup. creator of C++ We Continue GEEN163 I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. Bjarne Stroustrup creator

More information

Peace cannot be kept by force; it can only be achieved by understanding. Albert Einstein

Peace cannot be kept by force; it can only be achieved by understanding. Albert Einstein Semantics COMP360 Peace cannot be kept by force; it can only be achieved by understanding. Albert Einstein Snowflake Parser A recursive descent parser for the Snowflake language is due by noon on Friday,

More information

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Spring 2007 Midterm 2 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 3 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

COMP102: Test. 18 April, 2005

COMP102: Test. 18 April, 2005 Name:.................................. ID Number:............................. Signature:............................... COMP102: Test 18 April, 2005 Instructions Time allowed: 1 1 2 hours. Answer all

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

Snobol. Snowflake. and COMP360

Snobol. Snowflake. and COMP360 Snobol and Snowflake COMP360 The original name was Symbolic EXpression Interpreter (SEXI) It was clear that we needed another name!! We sat and talked and drank coffee and shot rubber bands and after much

More information

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation. Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop

More information

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object Review: Diagrams for Inheritance - String makemodel - int mileage + (String, int) Class #3: Inheritance & Polymorphism Software Design II (CS 220): M. Allen, 25 Jan. 18 + (String, int) + void

More information

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS121/IS223. Object Reference Variables. Dr Olly Gotel CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223

More information

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std; Review Problems for Final Exam 1. What is the output of the following program? int draw(int n); int n = 4; while (n>0) n = draw(n); int draw(int n) for(int i = 0; i < n; i++) cout

More information

Activity 1: Introduction

Activity 1: Introduction Activity 1: Introduction In this course, you will work in teams of 3 4 students to learn new concepts. This activity will introduce you to the process. We ll also take a first look at how to store data

More information

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Announcements PS 3 is due Thursday, 10/6 Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Room TBD Scope: Lecture 1 to Lecture 9 (Chapters 1 to 6 of text) You may bring a sheet of paper (A4, both sides) Tutoring

More information

Compiler Code Generation COMP360

Compiler Code Generation COMP360 Compiler Code Generation COMP360 Students who acquire large debts putting themselves through school are unlikely to think about changing society. When you trap people in a system of debt, they can t afford

More information

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion. Notes - Recursion So far we have only learned how to solve problems iteratively using loops. We will now learn how to solve problems recursively by having a method call itself. A geeky definition of recursion

More information

CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files

CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files Due: Wednesday July 11th by 8:00 a.m., via Blackboard. Optional

More information

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back

More information

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 13: Recursion Sandeep Manjanna, Summer 2015 Announcements Final exams : 26 th of June (2pm to 5pm) @ MAASS 112 Assignment 4 is posted and Due on 29 th of June

More information

Introduction to Data Structures

Introduction to Data Structures 15-121 Introduction to Data Structures Lecture #1 Introduction 28 August 2019 Margaret Reid-Miller Today Course Administration Overview of Course A (very basic) Java introduction Course website: www.cs.cmu.edu/~mrmiller/15-121

More information

Over and Over Again GEEN163

Over and Over Again GEEN163 Over and Over Again GEEN163 There is no harm in repeating a good thing. Plato Homework A programming assignment has been posted on Blackboard You have to convert three flowcharts into programs Upload the

More information

Technical Section. Lab 4 while loops and for loops. A. while Loops or for loops

Technical Section. Lab 4 while loops and for loops. A. while Loops or for loops Lab 4 while loops and for loops The purpose of this lab is to introduce you to the concept of a for loop, gain experience distinguishing between a while loop (which is a more general type of loop than

More information

Chapter 9 Lab Text Processing and Wrapper Classes

Chapter 9 Lab Text Processing and Wrapper Classes Lab Objectives Chapter 9 Lab Text Processing and Wrapper Classes Use methods of the Character class and String class to process text Be able to use the StringTokenizer and StringBuffer classes Introduction

More information

Remaining Enhanced Labs

Remaining Enhanced Labs Here are some announcements regarding the end of the semester, and the specifications for the last Enhanced Labs. Don t forget that you need to take the Common Final Examination on Saturday, May 5, from

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Multilink cubes. strävorna

Multilink cubes. strävorna Multilink cubes p r o b l e m s o lv i n g c o n c e p t s n u m b e r sense a l g e b r a g e o m e t r y Product description Cubes in 10 bright colours. Use them from early stacking, sorting and counting

More information

CS Week 2. Jim Williams, PhD

CS Week 2. Jim Williams, PhD CS 200 - Week 2 Jim Williams, PhD Society of Women Engineers "Not just for women and not just for engineers; all students are welcome. We are especially looking for more computer science students!" - Emile

More information

COMP-202 Unit 0: Course Details

COMP-202 Unit 0: Course Details COMP-202 Unit 0: Course Details CONTENTS: Focus of the Course and Prerequisites Outline and Textbook Course Structure and Grading Scheme Computer Lab Info and Required Software Getting started thinking

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Let s get some practice creating programs that repeat commands inside of a loop in order to accomplish a particular task. You may

More information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

Rules of Exponents Part 1[Algebra 1](In Class Version).notebook. August 22, 2017 WARM UP. Simplify using order of operations. SOLUTION.

Rules of Exponents Part 1[Algebra 1](In Class Version).notebook. August 22, 2017 WARM UP. Simplify using order of operations. SOLUTION. WARM UP Simplify using order of operations. Aug 22 3:22 PM 1 Aug 22 4:09 PM 2 WARM UP a) The equation 3(4x) = (4x)3 illustrates which property? b) Which property of real numbers is illustrated by the equation

More information

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

CS Programming I: Arrays

CS Programming I: Arrays CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics

More information

For example, when your method is added to the class with the main method below, the output should be:

For example, when your method is added to the class with the main method below, the output should be: Sample Problems (from past midterms) 1. Writing Methods, Passing Parameters. Write a method called FindDistance that takes as input four integers, x1, y1, x2, y2, where (x1,y1) and (x2,y2) specify points

More information

Introduction to Java https://tinyurl.com/y7bvpa9z

Introduction to Java https://tinyurl.com/y7bvpa9z Introduction to Java https://tinyurl.com/y7bvpa9z Eric Newhall - Laurence Meyers Team 2849 Alumni Java Object-Oriented Compiled Garbage-Collected WORA - Write Once, Run Anywhere IDE Integrated Development

More information

11th Annual NB (English) High School Programming Competition

11th Annual NB (English) High School Programming Competition 11th Annual NB (English) High School Programming Competition hosted by UNB Saint John Friday, May 12, 2017 Competition Problems TEAM Rules: 1. For each problem, your program must read from the standard

More information

CompSci 201, LinkedLists

CompSci 201, LinkedLists CompSci 201, LinkedLists Nat Huffman for Jeff Forbes February 23, 2018 2/23/18 CompSci 201, Spring 2018, LinkedLists 1 K is for K-means Unsupervised learning can help predict a user s preferences or identify

More information

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims Lecture 1: Overview http://courses.cs.cornell.edu/cs2110 1 Course Staff Instructor Thorsten Joachims (tj@cs.cornell.edu)

More information

CSC 172 Data Structures and Algorithms. Fall 2017 TuTh 3:25 pm 4:40 pm Aug 30- Dec 22 Hoyt Auditorium

CSC 172 Data Structures and Algorithms. Fall 2017 TuTh 3:25 pm 4:40 pm Aug 30- Dec 22 Hoyt Auditorium CSC 172 Data Structures and Algorithms Fall 2017 TuTh 3:25 pm 4:40 pm Aug 30- Dec 22 Hoyt Auditorium Agenda Administrative aspects Brief overview of the course Hello world in Java CSC 172, Fall 2017, UR

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

Activity 1: Introduction

Activity 1: Introduction Activity 1: Introduction In this course, you will work in teams of 3 4 students to learn new concepts. This activity will introduce you to the process. We ll also take a first look at how to store data

More information

Computers, Variables and Types. Engineering 1D04, Teaching Session 2

Computers, Variables and Types. Engineering 1D04, Teaching Session 2 Computers, Variables and Types Engineering 1D04, Teaching Session 2 Typical Computer Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 1 An Abstract View of Computers Copyright 2006 David Das, Ryan Lortie,

More information

Arrays. Eng. Mohammed Abdualal

Arrays. Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays

More information

CSCI 111 Midterm Spring 2014

CSCI 111 Midterm Spring 2014 CSCI 111 Midterm Spring 2014 Question Number Point Value 1 40 2 20 3 15 4 25 Total 100 Points Awarded Name Student Id Lab Section 50 Minutes If I can t read your handwriting I have to count it wrong Keep

More information

Lab 9: Creating a Reusable Class

Lab 9: Creating a Reusable Class Lab 9: Creating a Reusable Class Objective This will introduce the student to creating custom, reusable classes This will introduce the student to using the custom, reusable class This will reinforce programming

More information

RAID 0 (non-redundant) RAID Types 4/25/2011

RAID 0 (non-redundant) RAID Types 4/25/2011 Exam 3 Review COMP375 Topics I/O controllers chapter 7 Disk performance section 6.3-6.4 RAID section 6.2 Pipelining section 12.4 Superscalar chapter 14 RISC chapter 13 Parallel Processors chapter 18 Security

More information

Summer Assignment for the School Year

Summer Assignment for the School Year Summer Assignment for the 2018-2019 School Year Course: AP Computer Science A Instructor: Mr. Rivera Welcome to AP Computer Science A. I am looking forward to an exciting school year of teaching Computer

More information

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. Name: Sample Final Exam 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. are included): a) int start = 10, end = 21; while (start < end &&

More information

Computer Science II Data Structures

Computer Science II Data Structures Computer Science II Data Structures Instructor Sukumar Ghosh 201P Maclean Hall Office hours: 10:30 AM 12:00 PM Mondays and Fridays Course Webpage homepage.cs.uiowa.edu/~ghosh/2116.html Course Syllabus

More information

Computer Science 210: Data Structures

Computer Science 210: Data Structures Computer Science 210: Data Structures Welcome to Data Structures! Data structures are fundamental building blocks of algorithms and programs Csci 210 is a study of data structures design efficiency implementation

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

Exercise 4: Loops, Arrays and Files

Exercise 4: Loops, Arrays and Files Exercise 4: Loops, Arrays and Files worth 24% of the final mark November 4, 2004 Instructions Submit your programs in a floppy disk. Deliver the disk to Michele Zito at the 12noon lecture on Tuesday November

More information

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean Practice Final Quiz 1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean 2 If you wanted to divide two numbers precisely, which

More information

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub I2204- Imperative Programming Schedule 08h00-09h40

More information

SYLLABUS PLUS: PRINTING & REPORTING

SYLLABUS PLUS: PRINTING & REPORTING SYLLABUS PLUS: PRINTING & REPORTING Syllabus Plus Printing & Reporting This Syllabus Plus training guide covers printing and reporting data from Syllabus Plus (referred to as S+ throughout the manual).

More information

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016 Final Exam CS 152, Computer Programming Fundamentals December 9, 2016 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

More information

UNIT 6B Organizing Data: Hash Tables. Announcements

UNIT 6B Organizing Data: Hash Tables. Announcements UNIT 6B Organizing Data: Hash Tables 1 Announcements Online assignment due Wednesday 27 th Lab Exam 1 Thursday 28 th Write simple programs during recitation 2 1 Last Lecture Arrays, lists, stacks, queues

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2018 CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,

More information

Programming Exercise 7: Static Methods

Programming Exercise 7: Static Methods Programming Exercise 7: Static Methods Due date for section 001: Monday, February 29 by 10 am Due date for section 002: Wednesday, March 2 by 10 am Purpose: Introduction to writing methods and code re-use.

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

CpSc 1111 Lab 9 2-D Arrays

CpSc 1111 Lab 9 2-D Arrays CpSc 1111 Lab 9 2-D Arrays Overview This week, you will gain some experience with 2-dimensional arrays, using loops to do the following: initialize a 2-D array with data from an input file print out the

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos. Lecture 05: Methods AITI Nigeria Summer 2012 University of Lagos. Agenda What a method is Why we use methods How to declare a method The four parts of a method How to use (invoke) a method The purpose

More information

Final Exam COMP Fall 2004 Dec 16, 2004

Final Exam COMP Fall 2004 Dec 16, 2004 1. Closed book and closed notes. Final Exam COMP 14-062 Fall 2004 Dec 16, 2004 2. Write all scratch work and answers on the exam itself. If you need extra space, let me know. Indicate your final answer

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 03: Control Flow Statements: Selection Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad Noor

More information

CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13

CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13 CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13 Question 1. (3 points) Java classifies exceptions as either checked or unchecked. For each of the following, indicate whether it is checked or unchecked

More information

Agenda: Discussion Week 7. May 11, 2009

Agenda: Discussion Week 7. May 11, 2009 Agenda: Discussion Week 7 Method signatures Static vs. instance compareto Exceptions Interfaces 2 D arrays Recursion varargs enum Suggestions? May 11, 2009 Method signatures [protection] [static] [return

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with

More information

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++ Comp Sci 1570 Introduction to C++ Outline 1 Outline 1 Outline 1 switch ( e x p r e s s i o n ) { case c o n s t a n t 1 : group of statements 1; break ; case c o n s t a n t 2 : group of statements 2;

More information

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable? Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable

More information

Instance Members and Static Members

Instance Members and Static Members Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these

More information

Faculty of Science FINAL EXAMINATION

Faculty of Science FINAL EXAMINATION Faculty of Science FINAL EXAMINATION COMPUTER SCIENCE COMP 250 INTRODUCTION TO COMPUTER SCIENCE Examiner: Prof. Michael Langer April 27, 2010 Associate Examiner: Mr. Joseph Vybihal 9 A.M. 12 P.M. Instructions:

More information

Assignment #1 Simple C++

Assignment #1 Simple C++ Eric Roberts Handout #5 CS 106B January 7, 2015 Assignment #1 Simple C++ Due: Friday, January 16 Part 1. Get Qt Creator working Parts of this handout were written by Julie Zelenski. Your first task is

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

CS 116 Week 8 Page 1

CS 116 Week 8 Page 1 CS 116 Week 8: Outline Reading: 1. Dale, Chapter 11 2. Dale, Lab 11 Objectives: 1. Mid-term exam CS 116 Week 8 Page 1 CS 116 Week 8: Lecture Outline 1. Mid-term Exam CS 116 Week 8 Page 2 CS 116 Week 8:

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

CS61B - Exam 2 March 17, Consider the following example of a program that uses inheritance.

CS61B - Exam 2 March 17, Consider the following example of a program that uses inheritance. CS61B - Exam 2 March 17, 2003 Problem 0 (1 point): Identification Fill out you name, you neighbor s names and other information in the grid on the solution sheet. Problem 1: (4 points) Inheritance Consider

More information

2.Simplification & Approximation

2.Simplification & Approximation 2.Simplification & Approximation As we all know that simplification is most widely asked topic in almost every banking exam. So let us try to understand what is actually meant by word Simplification. Simplification

More information

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COMP 250 Winter 2011 Reading: Java background January 5, 2011 Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP

More information

CSCI 136: Fundamentals of Computer Science II. Keith Vertanen Museum

CSCI 136: Fundamentals of Computer Science II. Keith Vertanen Museum CSCI 136: Fundamentals of Computer Science II Keith Vertanen Museum 102 496-4385 kvertanen@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II Keith Vertanen

More information

class objects instances Fields Constructors Methods static

class objects instances Fields Constructors Methods static Class Structure Classes A class describes a set of objects The objects are called instances of the class A class describes: Fields (instance variables)that hold the data for each object Constructors that

More information

Class Schedule and Rosters

Class Schedule and Rosters This guide outlines the process for faculty to review their class schedule and rosters in mycsustan for Fall 2008 and beyond. Class Rosters are available from the faculty center as soon as students start

More information

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Web-CAT submission URL:  CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

Introduction to Java Unit 1. Using BlueJ to Write Programs

Introduction to Java Unit 1. Using BlueJ to Write Programs Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 8, 2017 Outline Outline 1 Chapter 11: C++ Linked Structures Outline 1 Chapter 11: C++ Linked Structures A ListNode

More information

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey Exam 1 CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey I understand that this exam is closed books and closed notes and is to be completed without a calculator, phone, or other computer.

More information

Final Exam Practice. Partial credit will be awarded.

Final Exam Practice. Partial credit will be awarded. Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2

More information