LP1, 11 November 2021

Directions

Download the shell file on the left. Once class begins, I will display it on this page as well. Complete specs are in the Javadoc living in the doc folder.

It is a smart idea to test your code as you go but don't get too hung up on it. You can copy functions to another file so you can run them by themselves and minimize output. However, allow a couple of minutes to assemble the solutions back into the shell file. To submit, you will upload this file to Canvas.

It is smart strategy to get the first two questions first. They are "basic competency" questions and are pretty easy. The middle two deonstrate good competence. The fifth one has some tricky elements, and the sixth is quite challenging.

Most students solve 3-5 of the problems.

The file will be accessible five minutes prior to the start of class so you can start work immediately.

Allowable and Non-Allowable Items


import java.util.ArrayList;
import java.util.Arrays;
import java.math.BigInteger;
import java.time.LocalDate;
/**
*  Glorious Lab Practical on Java
*/
public class LP1
{
    /** 
     * This computes  the sum of a list of BigIntegers
     * @param a an array list of BigIntegers
     * @return the sum of the BigIntegers in a
     */
    public static BigInteger sum(ArrayList<BigInteger> a)
    {   
        return BigInteger.ZERO;
    }   
	/**
	* This plucks out entries of a string at indices divisible by p.
    * in a string.  
    * @param s a string
    * @param p a nonnegative integer.  
    * @return a string that has entries p, 2p, 3p,   etc of the
    * string s.
    *  Examples:
    * aerate("aardwolf" 2) -&gt; "arwl"
    * aerate("bacchanalia" 3) -&gt; "bcni"
    */    
	public static String aerate(String s, int p)
	{
        return "";
	}
    /**
     * This makes a string echoy.  See the example
     * @param s is a string
     * @return a string with the nth character repeated n times.  
     * example:  echoy("cowpie") &rarr; coowwwppppiiiiieeeeee
     * if the string passed is empty, return an empty string
     */
    public static String echoy(String s)
    {
        return "";
    }
    /** 
     * This computes the product of the non-zero elements of
     * a and returns the sum of its digits.
     * @param a an array list
     * @return the sum of the digits in the product of the 
     * non-zero entries in a
     */
    public static int  finger(ArrayList<BigInteger>  a)  
    {   
        return 0;
    }   
    /**
     * This filters strings for a specified substring
     * @param al is an array list of strings.
     * @param s is a search string
     * @return an array list of striings containing all those strings
     * in the array list <code>al</code> having <code>s</code> as a substring.
     */
     public static ArrayList<String> pseudoGrep(ArrayList<String> al, String s)
     {
         return new ArrayList<String>();
     }
    /**
    *  This finds the date n days from today.  If n is negative
    *  find the date -n days ago.
    *  @param n the number of days from today
    *  @return the date n days from today.  
    *  Sample:  10000 days from this lab prac is 29 March 2049.
    *  Today is 11 November 2021
    *  Sample:  10000 days ago is 1994-06-26
    */
    public static LocalDate daysFromNow(int n)
    {
        return LocalDate.EPOCH;
    }
    /** 
    *  Here is your testing ground.
    *  @param args command-line arguments. You won't have any.
    */
    public static void main(String[] args)
    {
        System.out.println(daysFromNow(0));        
    }
}