Spring Semester 2004

A201 Web-Based Bulletin Board


  1. One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with389,767 square feet.
  2. Write a program that reads a string of characters and writes back the string with the first and the last characters swapped.
  3. Write a program that asks the user to enter a number per line and prints back the current average of all the numbers entered thus far after every line.
  4. The yearly income for a fictitious profession is anywhere between $4,000 and $10,000. Write a program that calculates the taxes. If the income is between $4,000 and $6,000 the taxes are 10%, if the income is between $6,000 and $8,000 the taxes are 20% otherwise they’re 30%. Your program asks for the income and reports the taxes due.
  5. Write a program that reads two strings and reports the number of letters the two strings have in common.
  6. Write a program that reads a series of words (perhaps passed to it on the command line) and prints them back in alphabetical order.
  7. Write a program that asks you to perform additions between random integers in the range [-100, 100] and keeps track of your good and total answers.
  8. Write a program that asks you for a number of seconds and then reports how many days, hours, minutes and seconds that interval of time is.
  9. Write a program that simulates the passing of days in a non-leap year (essentially simulating the calendar).
  10. Write a program that reads a file and reports the total number of words in it.
  11. Write a program that reads a file and writes back a sorted version of it, sorting the words in alphabetical order.
  12. Write a program that reads a file and prints back a dictionary of it: a list of the words used and the number of times each word occurred (case-sensitive processing).
  13. Write a loop that calculates 1/n + 2/(n-1) + 3/(n-2) + ... + (n-1)/2 + n/1 for n = 30.
  14. Write a program that counts the number of times a character occurs in a string.
  15. Write a program that displays a table of the centigrade temperatures 0 through 20 and their Fahrenheit equivalents.
  16. Write a method that removes all the vowels in a string.
  17. Write a method that sorts an array of strings in lexicographic order.
  18. Write a simple calculator with a single accumulator: you give it commands such as 'add 5' or 'sub 3' and it performs them and reports the resulting value.
  19. Write a simple interpreter for assignment statements involving +, -, * and /, as well as symbolic names for variables (ask for an example).
  20. Write a recursive method that returns the larges value in an array of ints.
  21. Write a program that implements the rule 90 cellular automaton.
    (http://mathworld.wolfram.com/Rule90.html)
  22. Implement a Stack abstract data type (use it to store strings).
  23. Implement a Queue abstract data type (use it to store strings)
  24. Write a recursive routine to draw a line. The extremities of the line are given (two points in the plane).
  25. Write a recursive method to sort an arrays of integers.
  26. Write a program that receives a string and rewrites it with parens around each vowel.
  27. Write a program that converts between binary and decimal representations of integers.
  28. Write a program that places commas in integers.
  29. Write a program that multiplies matrices (two dimensional arrays of ints).
  30. Write a program that calculates set union, difference and intersection of two arrays of ints (which are given).
  31. Write a line that determines if a line (infinite in length) intersects a circle.
  32. Write a program that asks the user to enter a number. If the user enters the valid number (positive integer) the program prints the sum of the cubes of its digits and terminates. Otherwise the program keeps asking for a number until the user provides a number.
  33. Write a method that returns an array of integers in the range of 0-100 of the size specified by the user.
  34. Given a set of points in the plane determine the smallest rectangle that contains them all. The rectangle must have the sides parallel to the axes.
  35. Write a program that determines the center of a rectangle in the plane that has the sides parallel to the axes of the referential.
  36. Given a million points in the plane such that no three points are on the same line how would you draw a line that splits them in half: half a million on one side and the other half on the other side?
  37. Given an array of ints and a number (value) calculate the sum of the elements strictly smaller minus the sum of the elements strictly bigger than the value, in the array.
  38. Define a class of Complex number objects (that have an imaginary and a real part, basically like Fractions and Points). Define the four operations on Complex numbers: add, sub, mul and div.
  39. Write an Eggy-Peggy kind of program (see Wu).
  40. Write a program to add numbers in base 2.
  41. Write a program to add numbers in base n where n is between 2 and 10.
  42. Write a program to add numbers in base 16.
  43. Write a program that receives a String and returns it sorted ("adrian" becomes "aadirn").
  44. Write a program that reads a number (as a String) and tells you how many even digits and how many odd digits the number has.
  45. Write a program that reads a sentence and converts all the uppercase letters in lowercase letters and the other way around.
  46. Write a program that receives an ASCII numeric code and prints the character associated with it. Extend the program so it prints all the characters that have codes in a certain numeric range that is given.
  47. Write a program that calculates tips and total amounts. The user enters the subtotal and the gratuity as a percentage and the program prints the subtotal, the gratuity and the total.
  48. Write a program that computers mortgage payments. User enters interest rate, number of years, and loan amount. Program computes the monthly payment and then shows amortization month by month. The monthly payment is computed with this formula:
    1 - (loanAmount * monthlyInterestRate) / ( 1 / Math.pow(1 + monthlyInterestRate, numOfYears * 12))
    or some such thing.
  49. Write a program that prints the multiplication table of numbers between 1-10.
  50. Write a program that prints the first n lines of the following triangle:
        1
       212
      32123
     4321234
    543212345
  51. Assume f(x) = 4 * x * (1 - x) defined on [0, 1]. Find a minimum, up to two decimals.
  52. Write a program that prints the first 50 prime numbers.
  53. Write a program that determines whether an integer is even or odd without using % and /.
  54. Use nested loops to produce patterns like these:
    1            1 2 3 4 5 6            1   1 2 3 4 5 6   6 5 4 3 2 1
    1 2          1 2 3 4 5            2 1     1 2 3 4 5     6 5 4 3 2
    1 2 3        1 2 3 4            3 2 1       1 2 3 4       6 5 4 3
    1 2 3 4      1 2 3            4 3 2 1         1 2 3         6 5 4
    1 2 3 4 5    1 2            5 4 3 2 1           1 2           6 5
    1 2 3 4 5 6  1            6 5 4 3 2 1             1             6
  55. Approximate Math.PI by calculating:
    4 * ( 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - ...)
    Find out how many terms of the series you need to go through to reach 3.141592
  56. For
    1 + 1/2 + 1/3 + 1/4 + ... + 1/n
    calculate the sum from the left and from the right and compare the results for n = 50000.
  57. Use a while loop to find the smallest n such that n2 < 12000.
  58. Find the smallest n such that 2n is bigger than 10000*n2
  59. Write a program that determines a mortgage monthly payment then calculates the amortization table for a monthly payment that is a bit bigger than the monthly required payment (the excess goes to the principal). The user determines in advance the excess (s)he is planning to pay every month.
  60. Write a program that creates random strings of characters of a certain length.
  61. Write a program that creates a circular permutaion of a given string ("adrian" becomes "driana" or "nadria" depending on if we go left or right)
  62. Implement gcd if you know that:
    1. gcd(m, n) is n if n <= m and n divides m
    2. gcd(m, n) is gcd(n, m) if m < n
    3. gcd(m, n) is gcd(n, m%n) otherwise
  63. Calculate the first 100 iterations of the recurrence given by xn = 3xn-1 mod 1 starting from some x0 (x mod 1 is the fractional part of x for any x).
  64. Write the first m positive integers starting at 1, k on a line; m and k are given by the user.
  65. Write a method that receives two sorted arrays of integers and merges them into one sorted array.
  66. Write a program that generates 100 lowercase letters randomly and counts the occurrence of vowels. What is the chance of randomly choosing a vowel in general?
  67. Write a program to add, subtract, multiply matrices.
  68. Write a program that grades multiple choice tests.
  69. Write a program that calculates letter grades for A201 students when the averages for all categories of assignments are know for all students. Use a two dimensional array with students on the line and assignment categories on the columns.
  70. Write a program that finds the smallest element on the border of a two dimensional array.
  71. Use recursion to implement selection sort.
  72. Write a program that declares, allocates, and populates an array with random circles, prints it, sorts it in ascending order (by circle radius), then prints the array of circles one by one.
  73. Same problem with rectangles. Sorting is with respect to height, width, or area. User chooses.
  74. Same problem only you can put both circles and arrays in it and sorting is by area, ascending.
  75. Define a class Stock. It has a set method, to set the value, and a percentChange method that tells you how much it changed from what it was (as a percent).
  76. Given a string print the longest substring in it that starts with a given letter.
  77. Write a program that reads a string of characters (perhaps a sentence) and prints back the number of times each character occurs.
  78. Write a program that determines if two strings are one the anagram of the other (e.g., "listen" and "silent").
  79. Define a cylinder as an extension of class circle using inheritance.
  80. Define a class matrix of rational numbers with addition, subtraction, multiplication.
  81. Create a LinkedList ADT.
  82. Write a program that uses Fractions to calculate
    1+1/2+1/3+1/4+1/5+...+1/n
    where n is some n specified by the user. This or any code similar like below:
    public class Fraction {
      static int gcd(int a, int b) {
        for (int i = Math.min(a, b); i > 0; i--) {
          if (a % i == 0 && b % i == 0) {
            return i;
          }
        }
        return 1;
      }
      private int num, den;
      public Fraction(int num, int den) {
        int gcd = Fraction.gcd(num, den);
        this.num = num / gcd;
        this.den = den / gcd;
      }
      public String toString() {
        return this.num + "/" + this.den;
      }
      public static void main(String[] args) {
        Fraction a = new Fraction(1, 3);
        Fraction b = new Fraction(1, 3);
        System.out.println((a.add(b)).toString());
      }
      public Fraction add(Fraction other) {
        return new Fraction(
             this.num * other.den + this.den * other.num ,
             this.den * other.den
        );
      }
    }
  83. Define a Vector kind of class. Define a Hashtable class.