APCSA Q4 Programming Projects

Recommended Activities

Watch (and/or read the transcripts of):

  1. https://www.webofstories.com/play/donald.knuth/21
  2. https://www.webofstories.com/play/donald.knuth/22

Read:

Programming Project No. 1

Compose a Java program that takes inputs and produces output as described in the following subsections.

Inputs

Inputs to your program will be provided as command-line arguments.

  • The first argument should be one of "Bubble", "Selection", "Insertion", "Quick", "Arrays", "Collections".
  • The second argument should be a numeric value; if there are fewer than three command-line arguments, the second argument should be a positive integer.
  • Additional optional arguments, if present, should be numeric.

What Your Program Should Do

If the first command-line argument is "Bubble", "Section", "Insertion", or "Quick", then your program should arrange a list of values in sorted order, from smallest to largest, using your own implementation of bubble sort, selection sort, insertion sort, or quick sort respectively. If the first command-line argument is "Arrays" or "Collections", then your program should sort the aforementioned list of values (from smallest to largest) using Java's Arrays.sort or Collections.sort method respectively.

If there are only two command-line arguments, then the second argument should be a positive number of numeric values that your program should randomly generate and sort.

If there are more than two command-line arguments, then the second through the last arguments should be a sequence of numeric values that your program should sort.

If command-line arguments are not of the expected number or type, then your program should print an appropriate, helpful message and should exit gracefully. Your program should never throw an exception.

Output

  • Your program should output the values in their original order and in sorted order.
  • Your program should output the total number of comparisons that were made during sorting.
  • Your program should output the time, in milliseconds, that it took to sort the values.

Programming Project No. 2

Compose a Java program that takes as input a single positive number, N, followed by an optional name of a sorting algorithm (see Programming Project No. 1 above). Your program should find all positive integers less than or equal to N that have only "right prime" or "left prime" factors in their prime factorizations. Your program should print, in sorted order, each number and its prime factorization on a single line. Using the specified sorting algorithm (or a default algorithm if none is specified) your program should sort the integers (before outputting them) from largest number of factors to smallest number of factors. (Print the factors themselves from smallest to largest.) If integers have the same number of factors, your program should print larger integers before smaller ones.

Your program should output the time, in milliseconds, that it takes your program to produce the expected output. Your program should record the current system time when it begins; after the last number and its prime factorization is printed, your program should subtract the previously recorded time from the current system time and output the difference in milliseconds.

Note: Your program must compute the answer to the problem. Although it would be fast and somewhat clever, you are not allowed to build a database of previously computed values and then use the database to produce an answer for a given value of N. That's the sort of thing you might do if you were working for the NSA, but it's called cheating in the context of this assignment. Once your program has computed a value, however, it may remember it; that's called Memoization and is encouraged. (Were there to be a competition, correct programs would be considered better than incorrect ones, and faster correct programs would be judged better than slower ones.)

Acknowledgement and Additional Important Information

From: Kipp Johnson
Sent: Tuesday, April 09, 2019 3:39 PM
To: John Spurgeon
Subject: Perhaps a problem for your class

OLD CHALLENGE. Justin Smith calls 5939 a "right" prime because it remains prime after dropping any number of digits
from the right: 5939, 593, 59, and 5 are all prime. How many right primes are there less than 1000? Is there a largest right
prime?

[...]
 
From Frank Morgan’s “Math Chat” web page, which unfortunately isn’t maintained by him anymore.