1 / 11

What If?

What If?. Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use. Program for Previous. String empName1, empName2, empName3,… String empLocation1, empLocation2, … System.out.print( “Enter employee name 1:”);

lisbet
Download Presentation

What If?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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: typevariableName[] = new type [size]; • 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; values[i + 1] = 78; i = 2; values[i] = 16; 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(); } for(offset = 0; offset < ARRAY_SIZE; offset++) { sum = sum + numArray[offset]; } average = sum / ARRAY_SIZE;

  9. Project • Posted on blackboard under Tasks • Due Wednesday of Finals week at Noon CDT • 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)

More Related