Rules Two Teams Questions worth 1-3 points – Entire team can confer to answer the question – Max of 2 minutes per question – You can use a computer on.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Python Objects and Classes
CSCI 160 Midterm Review Rasanjalee DM.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
1 Various Methods of Populating Arrays Randomly generated integers.
Written by: Dr. JJ Shepherd
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Arrays and Lists.  Properties ◦ Contents are stored in contiguous memory locations ◦ Elements of the array are of the same type  (Perl allows for.
1 CSE 303 Lecture 12 structured data reading: Programming in C Ch. 9 slides created by Marty Stepp
Final and Static Keywords. Creating constants  There will be occasions where data items in a program have values that do not change.  Maximum score.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Ch 13. Features Found Only in Java Timothy Budd Oregon State University.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
1)Never start coding unless you understand the task! 2)Gather requirements first. This means identify the problem and ask questions about it. Now you kind.
Chapter 5- Even more about objects and methods. Overview n Designing methods n Methods, methods, methods n Overloading methods n Constructor methods n.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
French Territory of St. Pierre CSE 114 – Computer Science I Arrays.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Research Topics in Computational Science. Agenda Survey Overview.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
Newport Robotics Group 1 Tuesdays, 6:30 – 8:30 PM Newport High School Week 4 10/23/2014.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Polymorphism, Virtual Methods and Interfaces Version 1.1.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Written by: Dr. JJ Shepherd
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
int [] scores = new int [10];
CS32 Discussion Section 1B Week 5 TA: Hao Yu (Cody)
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
The need for Programming Languages
The List ADT.
Passing Objects to Methods
Write code to prompt for 5 grades, read them in, print “Thank you”, then reprint the 5 grades and their average. cout >
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Interfaces.
More Object Oriented Programming
CSC 113 Tutorial QUIZ I.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Building Java Programs
Simple Classes in Java CSCI 392 Classes – Part 1.
CS150 Introduction to Computer Science 1
CIS 199 Final Review.
CSC 111 Exam 3 Review Fall 2005.
Variables and Computer Memory
Peer Instruction 4 Control Loops.
True / False Variables.
Corresponds with Chapter 5
Presentation transcript:

Rules Two Teams Questions worth 1-3 points – Entire team can confer to answer the question – Max of 2 minutes per question – You can use a computer on any question except “what does this program output…” Teams switch when either – Three questions have been asked or – A team answers incorrectly three times (three strikes) After three strikes, the opposing team can “steal” the points by answering the question correctly Team with the most points at the end wins

Question 1 of 12 Name at least two ways a List is more flexible than an array.

Answer 1 (2 points) Name at least two ways a List is more flexible than an array. – Don’t have to specify the size of the List, can add items to the end – Can remove items at a specified index – Built-in methods to search the list

Question 2 (3 points) What is the output of this code? int[] a = { 0, 1, 1, 0, 2, 1 }; int[] h = new int[3]; h[0] = 0; h[1] = 0; h[2] = 0; for (int i = 0; i < a.Length; i++) { h[a[i]]++; } Console.WriteLine(h[0]); Console.WriteLine(h[1]); Console.WriteLine(h[2]);

Answer

Question 3 (1 point) If a method is declared to be virtual then what can we do with that method in a derived class?

Answer 3 Override it

Question 4 (1 point) Write code that creates an instance of the Dude class using the constructor (send in any data you like that is valid) class Dude { private string name; private int age; public Dude(string n, int a) { name = n; age = a; }

Answer 4 Dude dude = new Dude("Ben Curtis", 29);

Question 5 (3 point) Write equivalent code that uses two while loops instead of two for loops for (int i = 0; i < 10; i++) { for (int j = 0; j < i; j++) { int temp = ary[j]; ary[j] = ary[i]; ary[i] = temp; }

Answer 5 Code int i = 0; while (i < 10) { int j = 0; while (j < i) { int temp = ary[j]; ary[j] = ary[i]; ary[i] = temp; j++; } i++; }

Question 6 (2 points) What is the difference between a reference type and a primitive type?

Answer 6 Primitive type stores the actual value directly in the memory location for the variable Reference type stores an address in memory, or a reference, to another place in memory that stores the actual value of the data

Question 7 (2 points) Give the code to create a variable named “nums” that is a List of doubles, and then add 3.5 and 10.4 to the list

Answer 7 List nums = new List (); nums.Items.Add(3.5); nums.Items.Add(10.4);

Question 8 (1 point) What is the difference between public, private, and protected?

Answer 8 Public: accessible from outside the class Private: accessible only inside the class Protected: accessible inside the class and in any derived classes

Question 9 (3 points) Write a class named “AfricanGrey” that is derived from Parrot and override description() to return “Grey with red tails” class Parrot { public virtual string description() { return ("Talking Bird"); }

Answer 9 Code class AfricanGrey : Parrot { public override string description() { return ("Grey with Red Tails"); }

Question 10 (1 point) How is it that inheritance helps us eliminate redundant code?

Answer 10 Methods or variables can be defined in parent classes and are “inherited” by any derived class, so we don’t have to write the inherited code again

Question 11 (2 points) Fill in the blanks so the method accepts an array of strings and a target string, and also invokes the method public bool search( __________ ary, string targetname) { for (int i = 0; i < ary.Length; i++) { if (ary[i].Equals(targetname)) return true; } return false; } public void button_click() { string[] ary = { "Joe", "Bob", "Ted" }; if (search( _______, "Ted")) { MessageBox.Show ("Ted is in the array."); }

Answer 11 Code public bool search( string[] ary, string targetname) { for (int i = 0; i < ary.Length; i++) { if (ary[i].Equals(targetname)) return true; } return false; } public void button_click() { string[] ary = { "Joe", "Bob", "Ted" }; if (search( ary, "Ted")) { MessageBox.Show ("Ted is in the array."); }

Question 12 (3 points) Give the output private void question12(string[] a, int count) { a[2] = ""; count--; } private void button6_Click(object sender, EventArgs e) { string[] ary = { "Joe", "Bob", "Ted" }; int count = 3; question12(ary, count); Console.WriteLine("Count: " + count); for (int i = 0; i < count; i++) { Console.WriteLine(ary[i]); }

Answer 12 Count = 3 Joe Bob

The End

Runoff Question Write the Money class so the following code works: Money dinero = new Money(10000, "pesos"); Money cash = new Money(5, "dollars"); // Outputs pesos MessageBox.Show(dinero.Amount + " " + dinero.Currency); // Outputs 5 dollars MessageBox.Show(cash.Amount + " " + cash.Currency);

Answer class Money { private int amount; public int Amount { get { return amount; } set { amount = value; } } private string currency; public string Currency { get { return currency; } set { currency = value; } } public Money(int a, string c) { amount = a; currency = c; }