March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The project assignment, againThe project assignment, again Arrays.

Slides:



Advertisements
Similar presentations
March R. Smith - University of St Thomas - Minnesota Today’s Class Quiz RecapQuiz Recap Exam ReviewExam Review C MaterialC Material Matlab MaterialMatlab.
Advertisements

March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Tomorrow’s ExamTomorrow’s Exam Today’s LabToday’s Lab SortingSorting.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class ProjectsProjects 2 dimensional arrays2 dimensional arrays Higher dimensionsHigher.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class AdministrativeAdministrative –Project proposals –This week’s lab Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab 16Lab 16 Filling in an arrayFilling in an array Searching for a.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class More about FunctionsMore about Functions RecursionRecursion.
March R. Smith - University of St Thomas - Minnesota Today’s Class Recap of a simple programRecap of a simple program A “history” of CA “history”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class IF StatementIF Statement Revisiting assignment statementsRevisiting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam TopicsExam Topics.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Functions and Array ArgumentsFunctions and Array Arguments ExamExam.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Where we areWhere we are Strings and TextStrings and Text ConditionalsConditionals.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam ReviewFinal Exam Review –Assessment –Exam Format –C –Matlab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class I/O ObjectsI/O Objects Lab 12Lab 12.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Young Scholars GrantsYoung Scholars Grants Exam Next TuesdayExam Next.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Today’s LabToday’s Lab SortingSorting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The ProjectThe Project PointersPointers.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Class projectsClass projects Lab 13: Use the method documentation.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Getting Homework BackGetting Homework Back DecimalFormat class.
6/22/2015 1R. Smith - University of St Thomas - Minnesota QMCS Class Today St. Lukes Case StudySt. Lukes Case Study.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Return HomeworkReturn Homework Class ScheduleClass Schedule Functions:
Loops – While, Do, For Repetition Statements Introduction to Arrays
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Exam ReviewExam Review Arithmetic - I think everyone gets thisArithmetic.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Cryptography – introductory termsCryptography – introductory terms “Enigma”
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class RecapRecap Functions and CFunctions and C Using FunctionsUsing Functions.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class MethodsMethods Problem solving by decompositionProblem solving by.
March R. Smith - University of St Thomas - Minnesota Today’s Class Lab 1 commentsLab 1 comments Data Types in Chapter 4Data Types in Chapter 4 Lab.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Nested IFNested IF “Boolean” Logical Operations“Boolean” Logical.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class More “Clarifications” ?More “Clarifications” ? Interrupts – integrating.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Lab Status, Paper StatusLab Status, Paper Status Comments on Ints vs.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Random NumbersRandom Numbers Output filesOutput files Input filesInput.
6/28/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper recapHistory Paper recap Finish the movieFinish the movie.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Buttons: Radio and Check BoxButtons: Radio and Check Box Lab 20Lab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class StatusStatus –Survey –Returning homework ArraysArrays –What are they?
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Finish up Lab 13Finish up Lab 13 Lab 14 – DetailsLab 14 – Details.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam –Open book, no notes, like last time Exam TopicsExam.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Administrative: do you want another lab?Administrative: do you want.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class About HomeworkAbout Homework Increment/DecrementIncrement/Decrement.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Homework & GradesHomework & Grades Multiple DimensionsMultiple Dimensions.
March R. Smith - University of St Thomas - Minnesota Today’s Class Homework NotesHomework Notes –Always try to match the printed output if I give.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class More LoopsMore Loops Do While – a ‘trailing decision’ loopDo While.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The ExamThe Exam Homework NotesHomework Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Peek at Lab 16Peek at Lab 16 Side effects and arraysSide effects and.
CS0007: Introduction to Computer Programming Introduction to Arrays.
9/21/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Files, writing filesFiles, writing files 1D Array Recap1D.
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.
5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures.
Homework due Test the random number generator Create a 1D array of n ints Fill the array with random numbers between 0 and 100 Compute and report the average.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class A note on methodsA note on methods ObjectsObjects Creating your.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
1/28/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Assignments 7 and 8Assignments 7 and 8 ExamExam History Paper AssignmentHistory.
2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class What’s on the Exam Next Week?What’s on the Exam Next Week? Lab 8Lab.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:
Chapter VII: Arrays.
Chapter 7 Part 1 Edited by JJ Shepherd
Presentation transcript:

March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The project assignment, againThe project assignment, again Arrays - Chapter 8Arrays - Chapter 8 –Declaring, initializing, special ‘for’ statement –Sample with Random –Sizing issues –Using typed-in input

March /18R. Smith - University of St Thomas - Minnesota Class Projects Something I can ‘run’Something I can ‘run’ Does something visibleDoes something visible –Graphics and/or file processing Class definitions in multiple files (2 or more)Class definitions in multiple files (2 or more) May be solo, or teams of 2 or 3May be solo, or teams of 2 or 3 –One separate file/class per team member Project ideas?Project ideas? –Text-based game –Tax return: maybe just a simple 1040 form –A “complete” payroll implementation Correct taxes, multiple employeesCorrect taxes, multiple employees –House design/costing (extension of the rug problem)

March /18R. Smith - University of St Thomas - Minnesota Arrays A collection of ‘things’ of the same typeA collection of ‘things’ of the same type –May be numbers (primitive types) –Strings (reference types) –Objects (reference types) Each array has a size, fixed when createdEach array has a size, fixed when created Use brackets: [, and ], to indicate an arrayUse brackets: [, and ], to indicate an array int myArray[] = new int[20];int myArray[] = new int[20]; –An array of 20 integers myArray[10] = 5; // initialize the 10th elementmyArray[10] = 5; // initialize the 10th element

March /18R. Smith - University of St Thomas - Minnesota Declaring, creating an Array To define: type name, variable name, “[]”To define: type name, variable name, “[]” –You don’t have to initialize it but you can ExamplesExamples –double daysWages[]; –daysWages = new double[7]; – - or - –double daysWages[] = new double[7]; – - or - –final int DAYS = 7; –double daysWages[] = new double[DAYS];

March /18R. Smith - University of St Thomas - Minnesota Alternate array declarations int[] numbers;int[] numbers; int numbers[];int numbers[]; int[] numbers, codes, scores;int[] numbers, codes, scores; int numbers[], codes[], scores[];int numbers[], codes[], scores[]; What about…What about… int numbers[], codes, scores;int numbers[], codes, scores; Initializing an array:Initializing an array: –int numbers[] = {1, 3, 5, 7, 9};

March /18R. Smith - University of St Thomas - Minnesota Using an array (an “array reference”) In the array with 7 intsIn the array with 7 ints –Elements are numbered 0 to 6 –First is daysWages[0] –Last is daysWages[6] Treat an array reference like any other variableTreat an array reference like any other variable –You can assign to it –You can use it in arithmetic calculations –You can pass its contents to a method

March /18R. Smith - University of St Thomas - Minnesota Working through an array int numbers[] = {1, 3, 5, 7, 9};int numbers[] = {1, 3, 5, 7, 9}; int sum = 0;int sum = 0; for (i=0; i<numbers.length; i++)for (i=0; i<numbers.length; i++) –sum = sum + numbers[i]; “Special version” of for statement“Special version” of for statement –for (int val : numbers) sum = sum + val;sum = sum + val;

March /18R. Smith - University of St Thomas - Minnesota The “special” for statement “Special version” of for statement“Special version” of for statement –for (int val : numbers) sum = sum + val;sum = sum + val; Creates a variable that’s “local” to the loopCreates a variable that’s “local” to the loop –Each time through the loop, the variable gets the value –You can’t change values in the array –You can only “look” at array values

March /18R. Smith - University of St Thomas - Minnesota An array exercise Use ‘random’ to generate integersUse ‘random’ to generate integers –Fill up a small array using a ‘for’ loop –Import java.util.Random –Method nextInt(num) returns int from 0 to num Use a regular ‘for’ loop to fill up the arrayUse a regular ‘for’ loop to fill up the array Find the ‘min’ or ‘max’ or ‘average’ or ‘sum’Find the ‘min’ or ‘max’ or ‘average’ or ‘sum’ –Use the special ‘for’ loop for this

March /18R. Smith - University of St Thomas - Minnesota Picking the size If you know it ahead of time, perfectIf you know it ahead of time, perfect If user knows it, ask for itIf user knows it, ask for it –Example: number of days of pay –Double check what the user says, of course If you’re reading a file, you can read it twiceIf you’re reading a file, you can read it twice –First time, count the number of lines, or of whatever –Create an array with the right number of elements –Next, read the file again and copy the data into the array

March /18R. Smith - University of St Thomas - Minnesota What if you don’t know the size? Pick a ‘worst case’ sizePick a ‘worst case’ size –I.e. bigger that it ever needs to be –Be sure you check for attempted overflow! The.length attributeThe.length attribute –Use it with the array name to get the array size –daysWages.length == 7 What happens to a bad array reference?What happens to a bad array reference? –For example, j = daysWages[8] –It doesn’t work! Java detects it. If it’s a constant, then the compiler finds itIf it’s a constant, then the compiler finds it If it’s calculated during execution, the runtime finds itIf it’s calculated during execution, the runtime finds it

March /18R. Smith - University of St Thomas - Minnesota User input example Calculate from numbers typed inCalculate from numbers typed in –Use a ‘sentinel’ to mark the end –Check for the sentinel or end of array Once the numbers are in the array, go to workOnce the numbers are in the array, go to work

March /18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions? Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.