Announcements - PowerPoint PPT Presentation

About This Presentation
Title:

Announcements

Description:

Lecture 14: Arrays. Announcements & Review. Announcements. Lab 4: FlightReservation ... Problem: We want to track apple inventories. ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 9
Provided by: CSCF
Category:

less

Transcript and Presenter's Notes

Title: Announcements


1
Announcements Review
  • Last Time Lots of objects
  • Array example
  • Shapes shapes
  • shapes new Shapes2
  • shapes0 new Shapes(4,4,)
  • shapes1 new Shapes(14,4,lt3)
  • Today Simpler array usages
  • Boolean choices new Boolean5
  • for (i 0 i lt choices.length i)
  • choicesi true
  • Announcements
  • Lab 4 FlightReservation
  • Defining classes
  • Due
  • Thursday 10pm

2
Arrays are like strings Visualizing strings
  • String myApples new String("apples")
  • String myApples -gt

a p p l e s
0 1 2 3 4 5
3
Visualizing Arrays
  • int appleInventory 3, 10, 99
  • appleInventory -gt

3 10 99
0 1 2
4
Visualizing Arrays
  • String appleNames "McIntosh", "Golden
    Delicious", "Granny Smith"
  • appleNames -gt

0 1 2
G r a n n y S m i t h
G o l d e n D e l i c i o u s
M c I n t o s h
5
BlueJ Examples
  • Problem We want to track apple inventories. We
    want to track apple names and amounts in
    inventory.
  • one array stores apple names
  • one stores integer amounts in inventory

6
Limitations of Arrays
  • You cannot change the size of an array once you
    create it, i.e.,
  • String names new String70
  • To make a bigger array, first allocate a larger
    array, and then copy the first array to it
  • String moreNames new String100
  • for (int i 0 i lt names.length i)
  • moreNamesi namesi
  • // if needed you can names moreNames

7
Limitations of Arrays
  • You cannot compare arrays with
  • for (int i 0
  • (i lt names.length) (i lt
    moreNames.length) i)
  • if (!moreNamesi.equals(namesi))
  • return false
  • return true
  • Similarly, you have to iterate over the array to
    print it
  • for (int i 0 i lt names.length i)
  • System.out.println(namesi)

8
More Questions?
Write a Comment
User Comments (0)
About PowerShow.com