Computer Science 225
Advanced Programming
Spring 2020, Siena College
Lecture 3: More Java You Know
Date: Monday, January 27, 2020
Agenda
- Announcements
- Lab 0: Setting Up and Refresher due at the start of your lab this week
- Problem Set 1 due Wednesday night, keep those submissions coming
- More Java You Know
- In-class exercises (5 assignment points)
- Simplify the following using a ternary operator, eliminating the
need for the if statement:
if (numPeople == 1) {
System.out.println("1 person attended the meeting.");
}
else {
System.out.println(numPeople + " people attended the meeting.");
}
- Draw four memory diagrams, one where XXXXXX is each of (i)
an ArrayList, (ii) a singly-linked list with only a head
reference, (iii) a singly-linked circular list with only a tail
reference, and (iv) a doubly-linked list with both head and tail
references. The add method does not take a position at which
to add, and will choose the most efficient position for the given
structure. In cases where it is similarly efficient to add at the
beginning or at the end, it will add at the beginning.
List<Integer> x = new XXXXXX<Integer>();
x.add(1);
x.add(2);
x.add(3);
Examples