• Home
• Contact Me
Aeries Portal
• Royal High School
• Simi Valley USD


AP Statistics

• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links

AP Comp-Sci
 Course Content
• Programs
• Practice Tests
• Comp-Sci Links


CP Statistics
• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links


• Table of Contents
• Table of Contents

Math Power
• Table of Contents

AP Computer Science Unit 4 Programs
Data Structures: Arrays, Strings and ArrayLists



  1. GET IN LINE – Write a program that uses an ArrayList to store a list of names for people who are standing in a line. Initially, the list should contain (in the order given): Andrew, Sarah, Will, Evelyn and David. The program should then carry out the following activities:  
    1. Steven joins the end of the line
    2. Evelyn gets out of the line
    3. Display the current position # for Will*
    4. Jessica joins the end of the line
    5. Will gets out of the line and rejoins it at the end, behind Jessica
    6. Display the name of the person currently in the next to last position in line**
    7. The first and last people in line switch places
    8. Display a message declaring whether or not a person named David is in the line.***
    9. The user enters the name of a new person (use “Chris”) and a position for them to enter the line (use 3). Be sure to error-check the position #, as the line may not contain enough people to make that position possible.
    10. All people whose names start with the letter “S” get out of line
    11. Display the final order of the people in the line.****

          The displayed results should be as follows (use the *’s for reference):

                  * 3


                  *** YES or TRUE

                  **** [Will, Chris, David, Jessica, Andrew].

            NOTE: You will likely use every ArrayList method at least once in this program.

2.  RANDOM GROUPS - Write a program that will read a list of 20 names out of the textfile NAMEFILE2.TXT and place them into 5 random groups of 4 The program output should look something like this:

Group #1: Walin   Bell   Gomez-Benito   Coote

Group #2: Jitmetta   Di Rubio   Gordon   Sasaki


Group #5: Bornacin   Portugal   To  Matter

3.  ALPHABETIMALS - Write a program to read a list of 12 words out of the file alphawords.txt in which the words are in alphabetical order. You will then ask the user for a new word which will be added to the list and put into its appropriate place, alphabetically. This requires the use of the compareTo() method of the String class. Read about it on my website. The list should be displayed before and after the addition of the new word.

Try each of the following words to test your program: lion, aardvark, zebra

4. STATES - Read the list of state names from statenames.txt. Allow the user to enter two different letters from the alphabet. Remove all states that begin with those letters and all states between them. For example, if the input letters are ‘C’ and ‘H’, all states beginning with letters C through H should be removed from the list. Redisplay the list after the removal takes place. Also, the order of the letters should work either way. By that, it is meant that entering ‘H’ first and ‘C’ second should work the same as entering the ‘C’ first and the ‘H’ second (this requires some work on your part). Lastly, the program should work whether you enter upper or lower case letters.

5. DISTINCT WORDS – Write a program that will read a list of words out of a file and display all words (without duplications), in alphabetical order. As it reads each word, it should determine whether that word is already in the list. If it is, disregard it - if not, put in place in its correct position for alphabetization. Display the words at the end, as shown below - which is the correct answer. All words in the text file are lowercase. There are 20 total words in the file. The file is words.txt. Once again, you will need the compareTo() method of the String class.

[a, boy, dog, fast, good, is, run, runs, see, spot]


6. STUDENTS – Read the file students.txt into an ArrayList of type Student (recall the Student Class from 1st semester). Then allow the user to display any of the following (using a menu of choices):

  1. The name of each student along with their highest test score.
  2. The names and averages of all students whose average is above a given value.
  3. The average of a student chosen by the user (also try some students who are not in the list).
  4. Sort the students by average, display the results (descending)   





Home  •  About Me  •  Aeries Portal  •  Contact Me
© DanShuster.com