Summer Labs for AP Computer Science

INSTRUCTIONS USING EasyReader [applies to Labs 3 and 4]
  • Create a folder on your home computer called "APCS_Labs"
  • You are to create only ONE Project called "APSummerWork"
  • Make sure that all of your work is done in this ONE PROJECT.
  • In the fall, copy and bring in this folder.
  • Using Easy Reader is very simple
    1. Create class EasyReader and copy in the code from the link
    2. To use it inside of a program use the three lines below:

    EasyReader console = new EasyReader();
    System.out.print("Enter a word: ");
    String enteredWord = console.readLine();

    JAVA 1.5 API

    Lab 1: Using Arrays

    You will COMPLETE THIS application program that will compute a statistical analysis.
    Further information provided inside of the class.

    Lab 2: Sorting

    Go into Lab 1 and create a new class called "Utility". Inside of Utility, create two methods:

    /** prints the given list */
    public static void printList(int[] someList)

    /** returns the given list in the desired order
    * Direction will either be "ASC" or "DESC" written in all caps just how it appears here.
    * ASSUME that there will be no typing errors (user will either write ASC or DESC correctly.)
    */
    public static int[] sort(int[] someList, String direction)

    To test your methods, uncomment the items commented out for lab 2.
    PURPOSE OF THIS LAB: Think how to sort! Use pencil/paper to come up with an algorithm.

    Lab 3: Date Arithmetic
    -->Put your app prog in a class called "Lab3"

    This will take you a while.
    Using EasyReader, create a program that will input two dates from a user. You should ask for a MONTH, DAY, and YEAR for each of the two dates. Your program should then return the number of days between the two dates.

    NOTE:
    *I am leaving the implementation entirely up to you. You may want to create your time classes (like we used in Java 2) and then use some type of date arithmetic.
    *Another option is to use a 2d array that keeps track of the month, number of days that month has, and elapsed days of the year. You can then have two variables for the year of each date and use the 2d array to calculate days elapsed. (Remember leap year!)
    int[][] monthAndDays = { {1, 31, 31}, {2, 28, 59}....... };
    // (note that the 28 could be a 29 some years)

    Lab 4: Palindromes

    This is a fun one!
    Again, using EasyReader, you are to create a program that can accomplish two tasks:
    1. Determine if a given word (String) is a palindrome
    2. Provided a String (or array of char [you need the API here]), produce a palindrome based upon what was input.

    You should do all of this inside of an application program called "Lab 4".

    The program should work as follows:
    It displays to the user "Press 1 to test a word, Press 2 to create your own palindrome"
    If the user enters a 1
    -------Ask for a word, then call a method public boolean isPalindrome(String word) that returns true if it is, false if it is not.
    -------Tell the user if they entered a palindrome.
    If the users a 2
    ------Ask for a sequence of letters.
    -----Then call a method public String createPalindrome(String word) that returns a palindrome with that sequence.

    EXAMPLE
    user enters a 1: types "radar", program prints "Yes, that's a palindrome!"
    user enters a 1: types "salalalad", program prints, "No, that is not a palindrome."
    user enters a 2: types "abcdef", program prints, "Your palindrome is: abcdeffedcba"

    Lab 4 extra credit: ENHANCED CREATE PALINDROME
    If a user enters a 2: THEN ASK if they would like to duplicate the final character in the array
    If they say YES, then it should appear like the example above ("abcdeffedcba")
    If they say NO, then it should appear like ("abcdefedcba")

    ****YOU WILL DEFINITELY NEED TO VISIT THE API FOR HELP WITH STRING MANIPULATION****