Name __________________________ Date:
AP CS Java - Mr. Merlis Block 4 ACE
Day 26 – SECOND QUARTER
à Monday, 11/28, we’ll go over the Vehicle project.
à LET’S DO LABS!
TODAY’S AGENDA
-
Go over questions 11-20 from Practice Exam A1.
-
Continue Lab 1 – See below
[should be 100% complete by class #27]
-
Start Lab 2 [due at end of
class #28]
LAB 1 – “20,000 Lights” (20 points)
A
room has 20,000 light bulbs, each with its own pull-string. Twenty-thousand people walk into the room,
one at a time. The first person pulls
each string, turning all the lights on.
The second person pulls every second light bulb’s string (the 2nd, 4th,
etc.) The third person pulls every third
string, the fourth every fourth, and so on.
Eventually the twenty-thousandth person pulls
the string on the twenty-thousandth light.
A)
How many light bulbs are on?
B) Which light bulbs are they?
WHAT
I EXPECT
-
Create a new folder called “Labs”
-
Create a new project called “Lab1Lights”
-
Create an application program called
“Lab1Lights”
-
All you will need is a main method.
LAB 2 – Working with
Arraylist and Random
èOverview, Fill, print and sort an ArrayList with 50
random integers in the range 100 to 1000.
WHAT
I EXPECT
-
YOU SHOULD ALREADY HAVE A FOLDER called
“Labs” (from last class)
-
Create a new project called “Lab2List”
-
Create the classes ListWorks and an
application program called “Lab2”
-
All methods should be static.
MAIN
METHOD SHOULD LOOK LIKE:
ArrayList list = ListWorks.createList(50,100,1000);
//
number of numbers, low, high à uses
Java.util.Random to generate numbers.
ListWorks.print (list);
//
5 per line using EasyFormat and a for loop.
ArrayList sequence = ListWorks.createListWithMath(50,
100,1000);
//number
of numbers, low, high, uses Math.random to generate numbers.
ListWorks.print (sequence,10);
//
Overloaded method, 10 per line using an iterator and
EasyFormat.
sequence = ListWorks.sort(sequence);
//
sort will sort its parameter using a selection sort and return the sorted list
ListWorks.print(sequence);
Concepts and Classes
ArrayList,
Integer, EasyFormat, Iterator, compareTo, Java.util.Random, Math.random(),
overloading, selection sort, cast operator