Presentation is loading. Please wait.

Presentation is loading. Please wait.

What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

Similar presentations


Presentation on theme: "What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use."— Presentation transcript:

1 What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

2 Program for Previous String empName1, empName2, empName3,…
String empLocation1, empLocation2, … System.out.print( “Enter employee name 1:”); empName1 = scan.next(); System.out.print(“Enter employee name 2:”); empName2 = scan.next(); //Can we use a loop?

3 Arrays Syntax: type variableName[] = new type [size];
Memory Is Set Aside for size Items of type Each Variable Location in Array Is Accessed by Offsetting into the Array with an Integer Expression Legitimate Offsets Are 0 to size-1

4 Array Example char [] lastname = new char[100]; lastname[0] = ‘H’;
lastname[1] = ‘a’; lastname[2] = ‘\0’; System.out.println( lastname[0]);

5 Array Example int [] values = new int[15]; int i = 0; values[i] = 150;
System.out.println( values[0]); values[3] = values[0] + 6;

6 Array Example final int ARRAY_SIZE = 100; int offset;
int [] numArray = new int [ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { numArray[offset] = 0; } for(offset = 0; offset < numArray.length; offset++) numArray[offset] = offset;

7 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();

8 Array Example final int ARRAY_SIZE = 10; int offset, sum = 0, average;
int [] numArray = new int[ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { System.out.print( “Enter Score ” + offset + “ : “); numArray[offset] = scan.nextInt(); } sum = sum + numArray[offset]; average = sum / ARRAY_SIZE;

9 Project Posted on blackboard under Tasks Hand in to your TA (NOT me!)
.java for Client Program (source code), .java for Class (source code), .txt (Data file runwaycs115.txt), .doc (Analysis) Pseudocode!!!!! Design before Coding!!!! Start *TODAY*!!!!

10 Project Do’s Start this week (read project at least)
Write Pseudocode/Design FIRST Start Small, Test Often, Add Little by Little Backup Versions Often Review All cs115 Concepts – Do Well on Final Exam

11 Don’t’s No Working Together Write your own Code
Checked by Supercomputer May be Called in to Discuss Program Last Term – 10 Investigated, 7 0s, 1 probation Eleven terms (94 investigated, 64 received 0s)


Download ppt "What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use."

Similar presentations


Ads by Google