Header

divider
Links
• Home
• Webgrades
• Contact Me

• Royal High School
• Simi Valley USD


divider

AP Statistics

• Homework Log
• Test Schedule
• Chapter Reviews
• Practice Tests
• Research Project
• Statistics Links

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

divider

Geometry
• Homework Log
• Test Schedule
• Chapter Reviews
• Practice Tests
• Geometry Links


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

   

WORKING WITH THE ARRAYLIST CLASS

  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:  

·   Steven joins the end of the line

·        Evelyn gets out of the line

·        Samantha cuts in line in and gets in position #1 (positions start with 0)

·        Display the current position # for Will*

·        Jessica joins the end of the line

·        Will gets out of the line and rejoins it at the end, behind Jessica

·        Display the name of the person currently in the next to last position in line**

·        The first and last people in line switch places

·        Display a message declaring whether or not a person named David is in the line.***

·        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.

·        All people whose names start with the letter “S” get out of line

·        Display the final order of the people in the line.****

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

                  * 3

                  **Jessica

                  *** YES or TRUE

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

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


2.  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.

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

3.  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 OR 4 random groups of 5, to be determined by the user. Be sure to error-check the user input (they must enter 4 or 5). The program should work something like this:

Would you like 4 groups or 5 groups? 3
BAD INPUT! Must be 4 or 5

Would you like 4 groups or 5 groups? 5

Group #1: Walin, Bell, Gomez-Benito, Coote

Group #2: Jitmetta, Di Rubio, Gordon, Sasaki

etc...

Group #5: Bornacin, Portugal, To, Matter


4. 
5. 

 

 

 

 

Home  •  About Me  •  Webgrades  •  Contact Me
© DanShuster.com