Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Sample Quiz - Introduction to Programming in Java | CSIS 110, Study notes of Javascript programming

Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Fall 2005;

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-lji-1
koofers-user-lji-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 110 - Lecture 12
Announcements
Quiz – Friday, Oct 7
Any homework questions?
Last time: Collections
We continued looking at the ArrayList class, and began looking at the remove method.
So, say that we had these ArrayLists:
private ArrayList<String> notes;
private ArrayList<Student> studentBody;
private ArrayList<Book> library;
notes = new ArrayList<String>();
studentBody = new ArrayList<Student>();
library = new ArrayList<Book>();
Assuming that these lists have items in them, how would we remove the first item from
our notebook? The 4th student from the student body? Or the last Book from the Library?
Weíve seen how to add and access items in collections - what about removing items?
ArrayList provides a remove method: remove the item at a given index from the array.
Again, index must be in the range 0 through listSize - 1.
So, to remove the first note, we would do this:
notes.remove( 0 );
How would we remove the second note in our notebook? How about the last note in the
notebook?
[Draw a notebook ArrayList with four notes, and then ask what happens after we call
remove(1) ]
Discuss how the indices of the elements change after we do a remove.
Look at notebook-j5-Brian project – it has a remove method. Show how the numbers in
the list change.
pf2

Partial preview of the text

Download Sample Quiz - Introduction to Programming in Java | CSIS 110 and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 - Lecture 12

Announcements Quiz – Friday, Oct 7 Any homework questions? Last time : Collections We continued looking at the ArrayList class, and began looking at the remove method. So, say that we had these ArrayLists: private ArrayList notes; private ArrayList studentBody; private ArrayList library; notes = new ArrayList(); studentBody = new ArrayList(); library = new ArrayList(); Assuming that these lists have items in them, how would we remove the first item from our notebook? The 4th^ student from the student body? Or the last Book from the Library? Weíve seen how to add and access items in collections - what about removing items? ArrayList provides a remove method: remove the item at a given index from the array. Again, index must be in the range 0 through listSize - 1. So, to remove the first note, we would do this: notes.remove( 0 ); How would we remove the second note in our notebook? How about the last note in the notebook? [Draw a notebook ArrayList with four notes, and then ask what happens after we call remove(1) ] Discuss how the indices of the elements change after we do a remove. Look at notebook-j5-Brian project – it has a remove method. Show how the numbers in the list change.

Removing all items from a list Load the student2 project Note that in this version  Students have a studentID  I have added a buildStudentBody method that creates a bunch of students  There is a printAllStudents method that prints all of the students in the studentBody Try to write a method that removes all of the elements in a list. [Copy the printStudents method an modify it to call remove instead – Analyze why this doesn’t work] Look at alternative options

  1. delete from the rear
  2. always delete the front item – discuss why this version doesn’t have an obvious ‘prepare for next iteration’ part of the loop Finding a particular student Let’s write a method public void printStudent( String studentID ) that uses the studentID to find a student’s record an print it. [Write pseudo-code first. Then try to write loop. What if student not found? What should we do when we find the student?]