Arrays In Class - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Arrays In Class

Description:

Write the code to instantiate an array to hold 3 Auto objects. ... Do a bubble sort on the array and show all swaps and iterations. ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 16
Provided by: CSE118
Category:
Tags: arrays | class

less

Transcript and Presenter's Notes

Title: Arrays In Class


1
Arrays In Class
  • Briana Morrison

2
Objectives
  • Determine how much you have retained from CS /
    SWE 1301
  • Remember arrays!

3
Problem 1
  • What is an array?

4
Short Answers
  • Each variable in an array is called a(n)
    _____________________________
  • Use a(n) ___________________ to specify the
    position of an item in an array.

5
Write some code
  • Write a declaration for an array that will hold
    characters.
  • Instantiate the array to hold 15 characters.
  • Declare and initialize an array of integers to
    hold the values 1-5.

6
Array Access
  • Complete this chart with code

Element Syntax
Element 0
Element i
Last element
7
More code
  • Write the code to instantiate an array to hold 3
    Auto objects.
  • Why is this code different than an array that
    holds integers or characters?

8
Problem code
  • Whats wrong with the following code?

double billsBackup new double
6 billsBackup cellBills
9
More short answers
  • How can you compare two arrays for equality?

10
Searching and Sorting
  • List two ways to find an item in an array.
  • List two ways to sort an array.

11
Sorting
  • If I have the following
  • int array 19, 14, 6, 22, 14, 3, 11, 15
  • Do a bubble sort on the array and show all swaps
    and iterations.
  • Do a selection sort on the array and show all
    swaps and iterations.
  • Do an insertion sort on the array and show all
    swaps and iterations.

12
More Code
  • Write the code to print each element in an array
    named cellBills, one element per line (assuming
    that cellBills has been instantiated).

13
More Code
  • Write the code to calculate the total value of
    all elements in an array named cellBills, which
    has previously been instantiated.

14
Arrays and Classes
  • Can a class have an array for an instance
    variable?
  • What things do you have to remember when an array
    contains an array?

15
Problems
  • Whats wrong with the following code?

class Names private String name new
String5 public String getNames( )
return name public void setName( String
name) this.name name
Write a Comment
User Comments (0)
About PowerShow.com