Arrays of Objects // The following does NOT create memory for

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Objects. Strings String x = “abc”; String is a class, not a primitive x.charAt(2) is ‘b’ use name and ‘.’ and name.
Announcements Final Exam: Project Due on Wednesday at noon Central Time.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
CS 121 – Intro to Programming:Java - Lecture 3 Announcements Course home page: Owl due Friday;
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Constructors and Encapsulation reading: self-checks: #10-17.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Mixing integer and floating point numbers in an arithmetic operation.
Announcements Final Exam:TBD. public static void main(String [] args) { final int ASIZE = 5; int [] intArray= new int[ASIZE]; for(int i = 0; i < ASIZE;
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
CSCI S-1 Section 4. Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST.
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
Lab 3. Why Compressed Row Storage –A sparse matrix has a lot of elements of value zero. –Using a two dimensional array to store a sparse matrix wastes.
Classes - Intermediate
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
An Example to Show Command-Line Arguments and Wrapper Class
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Peer Instruction 6 Java Arrays.
Classes Variables That Are Not of a Built-in Type Are Objects
Object-Oriented Programming (OOP) Lecture No. 36
An Introduction to Java – Part I, language basics
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
AP Java Warm-up Boolean Array.
160 Exam 2 Prep.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
File Review Declare the File Stream Object Name
Arrays Syntax: type variableName[size];
Self study.
class PrintOnetoTen { public static void main(String args[]) {
Basics of OOP A class is the blueprint of an object.
Java Programming with Multiple Classes
Announcements Final Exam: Project Due on Monday at noon Central Time.
OBJECT ORIENTED PROGRAMMING II LECTURE 13_2 GEORGE KOUTSOGIANNAKIS
Building Java Programs
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
JAVA An Introduction to Java OOP Basics
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Arrays in Java.
Arrays review.
Building Java Programs
Peer Instruction 4 Control Loops.
Names of variables, functions, classes
Dr. R Z Khan Handout-3 Classes
Generic Programming.
Building Java Programs
Agenda Remarks about last homeworks Class methods(static methods)
What to expect this week
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Review for Midterm 3.
Announcements Exam 2 Lecture Grades Posted on blackboard
Presentation transcript:

Arrays of Objects // The following does NOT create memory for // objects, it only makes a blueprint array Employee [] employees = new Employee [MAXEMP]; // Must create memory and call constructor for // each single member of aray of objects for (i = 0; i < MAXEMP; i++) employees[i] = new Employee();

Passing Arrays to Methods Pass Array Name into Method int [] intArray = new int[100]; loadArray(intArray); Accept into Method as an Array with No Set Size void loadArray( int [] passedArray ) Changes to Array in Method *will* Update Original Array

public static void main(String [] args) { final int ASIZE = 5; int [] intArray= new int[ASIZE]; for(int i = 0; i < ASIZE; i++) intArray[i] = i; System.out.println( intArray[0]); changeZero(intArray); } static void changeZero(int [] passedArray) passedArray[0] = 1000;

Initializing Arrays char [] cArray3 = {'a', 'b', 'c'}; int [] iArray = {1, 2, 3, 4}; double [] dArray = {3.4, 5.67e4};

Two Dimensional Arrays char [][] cArray = new char[10][20]; int [][] iArray = new int[100][50]; cArray[0][0] = ‘a’; cArray[0][1] = ‘b’; cArray[9][19] = ‘x’; iArray[0][0] = 99; iArray[1][5] = 135; iArray[99][49] = 0;

Employee Class Review Create a Class Employee Employee.java Employee Attributes (data members) Constructor Accessor Methods Mutator Methods tryEmployee.java (Client Test Program)

Final Exam 2 Hours 200 Points 35% of Grade Must Take to Pass Course

Need to Know for Final Everything Through Exam 2 Plus: Arrays Methods Classes Constructors Accessor Methods Mutator Methods

Final Exam 200 Points Total – 35% of Final Grade 90 points Matching or Short Answer or Multiple Choice (Terminology, Operators, JAVA Basics) 30 Points Program Output 80 Points Programming (Full Programs)