COM212: Programming Assignments

The programming assignments can be done in groups of up to two, but both members of the team need to be familiar with all aspects of the code and ready to answer questions from the professor / TAs during demos. Discussions between teams on methods to solve the problems are also permissible. It is also fine if you look up Java commands in books or online. However, the use of online services (such as ChatGPT and Stack Overflow) to write your code or find any part of it is not permissable. Assignments are due before the start of class - submit online. In order to submit online, go to the Google drive folder with your name on it shared by Alexia (abalentin@conncoll.edu). You should upload your assignments as a folder (i.e instead of uploading test.java and test2.java, upload a folder called "TestAssignment" containing the two java files). Make sure that you have the .java files uploaded in the folder. Also make sure that you submit every java file needed. If for some reason you don't have access/can't upload to your folder, email abalentin@conncoll.edu.


Program JavaA: Write the class HelloPrinter as shown in class.
Using a for loop, write the method printCount() that when called prints 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Now modify it so that it takes in an int parameter n and prints the same numbers with n added to each. So if it was called printCount(5) it would print 5, 6, 7, 8, 9, 10, 11, 12, 13, 14. Modify it once more so that if the number n is being added to is divisible by 2, the output is 1/2 the number plus n, if it's divisible by 3, the output is 0, and if it's anything else, the output is the number. For example printCount(5) would print 5, 1, 6, 0, 7, 5, 8, 7, 9, 0. Submit this final for loop for the assignment. Write a while loop that will do the same thing -- call the method printCountWhile(n). Submit this while loop method as well.
So your submission should be a single file called HelloPrinter.java that is a class HelloPrinter with a main that runs two methods [printCount(int n) and printCountWhile(int n)], which are also defined in the file HelloPrinter.java. You should be able to edit HelloPrinter.java and use whatever integers desired in the calls to the methods printCount and printCountWhile. Setting up user input for printCount and printCountWhile is not required.
Your call and output should be:
> java HelloPrinter
5 1 6 0 7 5 8 7 9 0
5 1 6 0 7 5 8 7 9 0
when you call both printCount and printCountWhile with an input parameter of 5.
This assignment is due 29 Feb before class.

Program JavaB: Write the class Student as shown in class. It should have the instance variables name and grade. They should both be private. There should be a constructor and public methods to get the name and grade and a method to set the grade.
Write a program that creates an array of 5 students (this should be done in main). Write a method fillArray() that uses a for loop or while loop to fill the array with students input from the user. This method should be called after the array is declared in main. After the fillArray() method in main, write 5 or 6 other commands in main to convince yourself that your array is filled and you can use methods from the Student class to access / alter the contents of the objects.
This assignment is due 7 Mar before class.

Program Zero: Implement a node class using Java. Make up some fields; at least include name, include ssn (as an integer), plus a Node pointer called next. The class name should be Node and to make a pointer just delare an instance variable of type Node called next.
private Node next;
Write methods to get and set the different fields. Write a method that returns a key which will return the last 4 digits of the ssn.
A test program that checks to make sure the methods work is as follows:
TestNode.java
This assignment is due 26 Mar before class.
Submit your Node class description. Make sure it is documented properly (program name, date, your name, and a description of what the program does).

Program One: Implement an unordered linked list with the following methods:
length(L) -- returns n
isEmptyList(L) -- returns true if the list is empty and false if it is not
searchReturn(L, key) -- returns a pointer to the node x where the key of x = key
searchRemove(L, key) -- returns a pointer to the node x where the key of x = key and removes x from the list
insert(L, x) -- inserts x into the list
printList(L) -- prints the keys of each of the nodes of the list in the order they are in the list
A test program that adds a few nodes and then tests each of the list functions is a follows: TestList.java
If you implement your list such that new nodes are added to the front of the list and you have the method printList() first print n and then the keys of the list, the output should be: TestListOutput.txt
This assignment is due 2 Apr before class.
Submit your class description.

Program Two: Implement a stack class using both a linked list and an array (assume a max size of 100 nodes). A test program that adds a few nodes and then tests each of the stack functions follows:
TestStackA.java
TestStackLL.java
The output should be:
StackAOutput.txt
StackLLOutput.txt
In addition, the printStack method for both stacks follows:
printStack.txt
This assignment is due 4 Apr before class.
Submit your class description.

Program Three: Implement a queue class using both a linked list and an array (assume a max size of 100 nodes). A test program that adds a few nodes and then tests each of the queue functions follows:
TestQueueA.java
TestQueueLL.java
The output should be:
QueueAOutput.txt
QueueLLOutput.txt
In addition, the printQueue method for both queues follows:
printQueue.txt
This assignment is due 9 Apr before class.
Submit your class description.

Program Four: Implement a binary search tree class using linked nodes. Remember to make some changes (add right and left pointers) to your Node class definition. Do not add a parent pointer to your Node class. This level of complexity is not needed for this implementation of the BST. A test program that tests each of the BST functions follows:
TestBST.java
In addition, a printTree method and the expected output are provided:
BSTOutput.txt
printTree.txt
This assignment is due 16 Apr before class.
Submit your class description.

Program Five: Implement a priority queue (heap) class using an array of nodes (you can assume a max size of 120 or so). Write your own test program that tests each of the heap functions. Make sure that the test program handles all of the possibilities; you will be graded on your test program as well as your class definition.
This assignment is due 18 Apr before class.
Submit your class description for Heap and Node, and your test program.

Program Six: Implement a dictionary (hash table) using double hashing or separate chaining (assume a max size of 7 so that you can show how it handles collisions). Write a test program that tests your hash functions. Make sure that you have enough cases to cover multiple collisions and deletions of nodes on the path to other nodes. Make sure your program can deal with multiple insertions and deletions.
This assignment is due 23 Apr before class.
Submit your class description for Hash and Node, and your test program. For extra credit, implement hash tables using both double hashing or separate chaining.

Program Seven: Copy Test0.java for use in doing Files and Exceptions.
This assignment is due 25 Apr before class.
Submit Test7.java. To help with this execise, read Chapter 11 of the Java Concepts book or check online for Java exception handling and text I/O.

Program Eight: Complete this introduction to serialization.
This assignment is due 25 Apr before class.
Nothing needs to be submitted.

 

 

Return to the COM212 Home Page