CSCI 1321 - Problems



This page contains the small sample problems that you will be presenting at the beginning of class periods as part of your class participation grade. Each of you must present three problems over the course of the semester for full credit and each problem can only be presented once.

(Phil and Cameron) 1. Write a program that prints your name and something about you to the console (using System.out.println).

(Phil) 2. Write a simple class for a bank account and put a main in it. The class should have deposit and withdraw methods and should also allow you to get the current balance. In main create an account and do some transactions on it, printing out information to show that it works.

(Noah) 3. Write a class like the bank account from problem 2 with methods for deposit and withdraw. Now create another class called customer that has a name and an account in it. Put methods in customer that represent transactions from other customers or outside sources.

(Glenn) 4. Write an interface for Car with a method drive. Create several subclasses of Car and have them print out something appropriate in the drive method. Put in a main that creates several of your cars and calls their drive methods to show you they are working.

(Glenn) 5. Write a program that takes a sentence as a string and breaks it into a set of words. You can make the original string a literal and use whatever parts of java.lang and java.util that you want.

(Glenn) 6. Write a program that creates an array of ints. Then pass that array to a method that returns their sum and print out the sum.

(Phil) 7. Write a program that creates an array of Integers. Pass that array to a method that returns the sum of the Integers.

(Andy) 8. Write a program that includes your own code to sort an array of values.

(Laura) 9. Write a program that uses an anonymous inner class and Arrays.sort to sort an array of Integers.

(Travis) 10. Write an array based stack and a "reverse polish calculator" that uses it. Such a calculator uses postfix notation so the operator comes after the operands "3 2 +" instead of "3 + 2". Now have it so that your program can take a string that represents a potentially complex formula in reverse polish and evalutate it.

(Laura) 11. Write a class that represents complex numbers. Provide methods to access the parts of it as well as standard operations on it (+, -, *, /, and anything else you want). Write a main that shows the use of this class.

(Andy) 12. Create a class that has something in it you could sort by (like a student by name, a bank account by value, or a complex number by magnitude). Then create an array of them in unsorted order and use Arrays.sort to sort them.

(Alex) 13. Imagine a word processor. You can probably see that keeping the text for such an application in a String in Java would be very inefficient. In fact, because you can so easily insert characters into the middle of the text, even a StringBuffer is less than ideal since it inevitably uses an array of characters. Write a class called WPText that keeps a linked list if characters. Give it a constructor that will build it from a String, a toString method that converts it back to a string, a setCursor method that takes an index where characters would be inserted, and an addCharacter method that adds characters at the cursor location. Write a main to demonstrate these working.

14. Java 1.5 (now called Java 5) has a new type of for loop that iterates through the elements of a container without forcing you to use an iterator. We don't have access to that yet though. Write a function void visitAll(java.util.Collection collection,Visitor visitor). The collection can be any Java collection in the java.util package. The interface Collection has an iterator function that returns an iterator. Visitor is an interface you creata that should have one method void visit(Object o). What your function should to is loop through all the elements in the collection and call visit with each of them. Demonstrate the use of this function on two different collection types in a main function.

(Travis) 15. Write a linked list based stack and a "reverse polish calculator" that uses it. Such a calculator uses postfix notation so the operator comes after the operands "3 2 +" instead of "3 + 2". Now have it so that your program can take a string that represents a potentially complex formula in reverse polish and evalutate it.

(Camron) 16. Write a program that has something like the bank account from one of the earlier programs with a name and balance. Add a function to it so that it can return a JComponent (possibly a JPanel) that shows the information for the account and has buttons for deposit and withdraw. The buttons don't have to do anything. Now make a main that creates a JFrame and creates three accounts then displays them in the JFrame.

(Camron) 17. Write a little progam that has a GUI with a textfield and two buttons. The text field should display a number and the buttons should have +1 and -1 on them. If you clikc the first, the number should go up one. If you click the second it should go down one.

(Alex) 18. Write a program that brings up a window and shows a shape drawn in the middle of it. When the user hits a key, make something change, either the shape or the colors.

(Laura) 19. Write a program that brings up a window and shows a ball bouncing around in it. The ball should bounce off the walls. "Gravity" is optional. You should be able to resize the window though and have the ball behave accordingly.

20. Write a program to show how the number of possible routes from one corner to another grows for an empty maze as the size of the maze grows. To do this, write a function to finding all possible paths in a maze and try it with mazes that range in size from 2x2 to 8x8 with no walls in them.

21. Take the function parsing code that we did in class and extend it so that the string can have a variable x in it. Make it so when the user calls valueOf they have to pass in a double that will be the value of x.

(Noah, Andy) 22. Using a binary search tree that was written in class and a sorted linked list, add 10000 random Doubles to each and time how long it takes for each to finish. You can time using System.currentTimeInMillis.