Based on lecture notes from Dr. Deepak Kumar of Brynmawr

Slides:



Advertisements
Similar presentations
Months of the year December January November October February
Advertisements

2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Review Objects – data fields – constructors – Methods Classes.
Mnemonics Using letters to make up phrases that help you remember.
CALENDAR YEAR PLAN JANUARY FEBRUARY MARCH APRIL MAY JUNE.
September 1 st Sunny Monday Date 日期 Weather 天氣 Days of the Week 星期 Year 年.
Sophie Rogers School for Early Learning Closure Dates
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own.
January 2014 Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Calendar.
Calendar 2017.
Array Data Structure and Processing Arrays
Before and After.
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Spelling this week!
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
Calendar of 2012 ESL Lesson on Months.
A Class Calendar in PowerPoint
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Calendar 2012 Example text here.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
JANUARY 2008 Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Number of visitors to the library.
13-block rotation schedule
Good day class! Good ________ Ms. A!.
Weekly Sight Words List 13.
CS-161 Computer Programming Lecture 14: Arrays I
McDonald’s Kalender 2009.
Starting Out with Programming Logic & Design
MY FUNDAY.
2300 (11PM) September 21 Blue line is meridian..
SEPTEMBER ½ Day Start Unit 1
SEPTEMBER 2014 Unit 1 Unit 1 Continued Unit 1 Continued
McDonald’s calendar 2007.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own.
Unit 1: Quick Quizzes After 5,13
Capitalization of Months and Days
Teacher name August phone: Enter text here.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
What’s the date today?.
SEPTEMBER 2014 Unit 1 Unit 1 Unit 1 Unit 1 Quick Quiz 9,16, 21 Unit 1
SEPTEMBER ½ Day Unit PLC
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
January 2015 Sunday Monday Tuesday Wednesday Thursday Friday Saturday
WHEN IS YOUR BIRTHDAY? IT’S ON THE 5TH (FIFTH) OF MAY.
| January Sunday Monday Tuesday Wednesday Thursday Friday
JUNE 2010 CALENDAR PROJECT PLANNING 1 Month MONDAY TUESDAY WEDNESDAY
WELCOME.
MONTHS OF THE YEAR January February April March June May July August
What’s the date today?.
2011年 5月 2011年 6月 2011年 7月 2011年 8月 Sunday Monday Tuesday Wednesday
McDonald’s calendar 2007.
Write the date in English
Reviewing Abbreviations
WHEN IS YOUR BIRTHDAY? IT’S ON THE 5TH (FIFTH) OF MAY.
JANUARY M T W T F S S Monday 1st semester Unit 2.
January Monday Tuesday Wednesday Thursday Friday Saturday Sunday 30 31
2015 January February March April May June July August September
Specials Calendar Time Day 1 Day 2 Day 3 Day 4 Day 5 Day 6
Presentation transcript:

Based on lecture notes from Dr. Deepak Kumar of Brynmawr Arrays Based on lecture notes from Dr. Deepak Kumar of Brynmawr Book pages 301-312

Variables int x = 0; float delta = 0.483; color darkOliveGreen = color(85, 107, 47); String colorName = "Dark Olive Green"; PImage castle = loadImage("myCastle.jpg"); 11/13/2018

A Set of Sample Values float petroleum = 40.0; float coal = 23.0; Natural Gas Nuclear Renewable Hydropower 40.0 23.0 22.0 8.0 4.0 3.0 Declaration float petroleum = 40.0; float coal = 23.0; float naturalGas = 22.0; float nuclear = 8.0; float renewable = 4.0; float hydropower = 3.0; float[] consumption; consumption = new float[6]; Creation index 1 2 3 4 5 44.0 23.0 22.0 8.0 4.0 3.0 consumption 11/13/2018

A Set of Sample Values //Declare and create an array with size 6 float[] consumption = new float[6]; //store values consumption[0] = 40.0; consumption[1] = 23.0; consumption[2] = 22.0; consumption[3] = 8.0; consumption[4] = 4.0; consumption[5] = 3.0; Fixed size 11/13/2018

A Set of Sample Values //Define, create and initialize the data in an array float[] consumption = {40.0, 23.0, 22.0, 8.0, 4.0, 3.0}; 11/13/2018

Arrays // An array to hold the names of all the days in a week String[] weekDays = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; // two arrays, each containing high and low temperature values float[] highTemps, lowTemps; int[] count; // an array of integers PImage[] photos; // an array of photos // An array to hold the names of months in a year String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; // The colors in a rainbow color[] rainbow = {color(255, 0, 0), color(255, 127, 0), color(255, 255, 0), color (0, 255, 0), color (0, 0, 255), color (111, 0, 255), color (143, 0, 255)}; 11/13/2018

Indexing, Size and Loops int[] n = new int[1000]; for (int i=0; i < n.length; i++) { n[i] = i; } int[] n = new int[1000]; for (int i= n.length-1; i>=0; i--) { n[i] = i; } 11/13/2018

for-each Loop Syntax Example for (variable : arrayName) { // do something with the value of variable } Example String[] energySource = {"Petroleum", "Coal", "Natural Gas", "Nuclear", "Renewable", "Hydropower"}; for(String str : energySource) { println(str); } 11/13/2018

Example: A Simple Bar Graph String[] energySource = {"Petroleum", "Coal", "Natural Gas", "Nuclear", "Renewable", "Hydropower"}; float[] consumption = {40.0, 23.0, 22.0, 8.0, 4.0, 3.0}; void setup() { size(400, 400); smooth(); } // setup() void draw() { // set up plot dimensions relative to screen size float x = width*0.1; float y = height*0.9; float delta = width*0.8/consumption.length; float w = delta*0.8; background(255); for (float value : consumption) { // draw the bar for value // first compute the height of the bar relative to sketch window float h = map(value, 0, 100, 0, height); fill(0); rect(x, y-h, w, h); x = x + delta; } } // draw() 11/13/2018

Array Operations String[] energySource = {"Petroleum", "Coal", "Natural Gas", "Nuclear", "Renewable", "Hydropower"}; float[] consumption = {40.0, 23.0, 22.0, 8.0, 4.0, 3.0}; 11/13/2018

Printing println(consumption.length); println(consumption); println(energySource); [0] Petroleum [1] Coal [2] Natural Gas [3] Nuclear [4] Renewable [5] Hydropower 6 [0] 40.0 [1] 23.0 [2] 22.0 [3] 8.0 [4] 4.0 [5] 3.0 11/13/2018

Try it Given the following arrays, String[] energySource = {"Petroleum", "Coal", "Natural Gas", "Nuclear", "Renewable", "Hydropower"}; float[] consumption = {40.0, 23.0, 22.0, 8.0, 4.0, 3.0}; write commands to print the values from energySource and consumption in the format shown here: Petroleum, 40.0 Coal, 23.0 Natural Gas, 22.0 Nuclear, 8.0 Renewable, 4.0 Hydropower, 3.0 11/13/2018

Min, Max and Soring float smallest = min(consumption); float largest = max(consumption); println(sort(consumption)); println(sort(energySource)); 11/13/2018

Other Array Operation Reverse the ordering of elements in an array Expand the size of the array append(), expand() Shorten it shorten() Concatenate or split arrays concat(), subset(), splice() Copy the contents of an array arrayCopy() 11/13/2018

Analysis and Design Lets analyze the problem Need to display blank board Initialize board to some representation of the pictures: lets use number pairs (0,0), (1,1), (2,2)…(7,7) in the case where n = 4, number of tiles = 16, there are 8 pairs of pictures Let the pictures be pic0, pic1, pci2,..pic7 Lets identify the data structures and design the algorithm before development of the code. 11/13/2018

Abstraction of the board Random placement Initialize -1 2 1 7 5 6 4 3 Abstraction of the board Random placement 11/13/2018

Algorithm Initialize board Display blank board Setup random number for the tiles for the pictures User selects tile 1: openTile1  row1, col1, tileNum1 User selects tile 2: openTile2row2, col2, tileNum2 Match the pair of tiles opened: matchPair() If match, Increment number of correct, If all tiles done, display number of tries Else no match, close tiles. 11/13/2018

Functional Decomposition Processing functions: setup, draw, mousePressed void initializeBoard(int n) void findRandomPair(int j) void openTile1() void openTile2() void matchPair() Void closeTiles() 11/13/2018