Homework Assignments for CIS 263

The programs that you turn in should conform to the style guide contained in the first of the following three links and they will be graded according to the criteria given in the second link. The third link below gives detailed instructions on exactly how you are to turn in your finished assignments.

Java Language Coding Guidelines
Program grading criteria
Turning in your assignments

The style guide is a PDF file; you should print it out and keep it for reference while you are programming. It was written by Cay Horstmann, a well known Java author. Two other style guides that you might also find useful are avoiding style crime, by Gregory Rawlins, and Code Conventions for the Java Programming Language , by Sun.

Below are your Java programming assignments. The due date for each one is contained in the assignment description.

Assignment 8.

This assignment is a modification of Exercise 12.14 from page 622 of the Java textbook. Do Exercise 12.14, and in addition to displaying the area of the rectangle, your application should display the parameters of the rectangle, i.e., the coordinates of its upper left hand corner, its length, and its width. (Be sure to read Section 12.11.) This is due Friday, May 5.

Assignment 7.

This assignment is a modification of Exercise 12.11 from page 622 of the Java textbook. Write a program that creates a JFrame that looks exactly like the picture in the exercise. Implement a listener for each component in the GUI. The listeners should handle an event by just printing the event object to System.out. This is due Thursday, April 20.

Assignment 6.

Write a program that draws 100 randomly chosen graphics objects in random colors in a 500 by 500 pixel window. By graphics object I mean either a line, a rectangle, a rounded rectangle, or an oval. This is due Tuesday, April 11.

Assignment 5.

Write a class Worker and two subclasses HourlyWorker and SalariedWorker. The Worker class has name and salary rate (in dollars per hour) fields. The Worker class has a computePay(int hours) method that multiplies hours worked by the salary rate. The Worker class also has a toString method that returns the name and salary rate in an appropriate String.

The HourlyWorker class has a union field (a String) and the SalariedWorker class has a field for the number of subordinates (a positive integer). The HourlyWorker and SalariedWorker classes both over ride the computePay method. The hourly worker gets paid for the actual number of hours worked, with overtime over 40 hours paid at time and a half. The SalariedWorker gets paid for 40 hours, no matter what the actual hours worked is. Both the HourlyWorker and SalariedWorker classes should over ride the toString method so that they specify if the worker is hourly or salaried.

All three classes should have appropriate constructors, get, and set methods (it is up to you to decide what is appropriate).

Write a test class called TestWorker. It should create an array of 5 Workers, some of them hourly workers and some of them salaried workers. Then the program should use polymorphism to compute the pay and print out all the information for each Worker in the array. The test class should also show that your constructors, get, and set methods work.

When you are done you will have four program files, Worker.java, HourlyWorker.java, SalariedWorker.java and TestWorker.java. Put these four files together into one zip file using WinZip. The zip file should have the name CIS263Ass5Surname.zip. Turn in you assignment by attaching this zip file to your e-mail message. (If you need help using WinZip, please ask me after class one day.) This assignment is due on Friday, March 31.

Assignment 4.

This assignment is a modification of Exercise 8.16 from page 382 of our textbook. Write a class SavingsAccount as describe in Exercise 8.16. Provide appropriate set and get methods. Your set methods should validate their data, so savingsBalance cannot be set negative and annualInterestRate is a number between zero and one. Provide two constructors, one default that sets the balance to zero and another that accepts a balance. Then write a class to test SavingsAccount as described in Exercise 8.16. Your testing class should have the name CIS263Ass4Surname and be in a file CIS263Ass4Surname.java. Put the code for the class SavingsAccount in the file CIS263Ass4Surname.java so this file will contain two classes. The class CIS263Ass4Surname should have a public access modifier and the class SavingsAccount should have no access modifier. This is due Friday, March 10.

Assignment 3.

Write a Java application that creates a 100 element one dimensional array of integers and fills the array with randomly generated integers between 1 and 100 with the additional requirement that there be no numbers that are repeated in the array (so every number between 1 and 100 will appear exactly once in the array). After filling the array, your program should print out the array as a table with ten rows and ten columns. (You do not need to worry about getting all the columns to line up perfectly in your output.) To prove that your array does not contain any repeated numbers, use the bubbleSort method to sort your array and then print out the sorted array as a ten row by ten column table. (You can copy the bubbleSort method out of the textbook, see pages 286-287.) Your program must contain (at least) one user defined method besides the main and bubbleSort methods. This is due Friday, February 25.

NOTE: If you are having trouble getting your homework to attach to your e-mail message, use the Purdue Calumet WebMail server to submit your homework. See Turning in your assignments for more details.

Assignment 2.

This assignment is a modification of Exercises 6.18 and 6.19 from pages 261-262 of our textbook.

First solve Exercise 6.18. Then modify your solution of Exercise 6.18 so that it solves Exercise 6.19. Then modify your solution of Exercise 6.19 in two ways. First, after your applet asks the user to input an integer, it should also ask the user to input a single character (the "fill character" used in Exercise 6.19). Secondly, your applet should continue to prompt the user for an integer and a fill character and draw the appropriate rectangle until the user inputs the sentinel -1 for the integer. Use JOptionPane.showInputDialog for getting the user input.

Turn in just your final solution, not the intermediate solutions to Exercises 6.18 and 6.19. This is due Friday, February 11. (NOTE: If you are having trouble getting your homework to attach to your e-mail message, use the Purdue Calumet WebMail server to submit your homework. See Turning in your assignments for more details.)

Assignment 1.

Write a Java application that reads in an integer n and prints out either n plus signs followed by n if n is positive, or -n-1 minus signs followed by n if n is negative. So for example, if n is 5, then the output would be

+++++5

(that is, five plus signs followed by 5), and if n is -5, then the output would be

-----5

(that is, five minus signs followed by 5). Your program should continue to read in integers and output one line per integer until the input is the number zero; your program should terminate when the input is the number zero. (Using the terminology of Section 4.9 of our textbook, 0 is the sentinel.) Your program should use the JOptionPane.showInputDialog and JOptionPane.showMessageDialog methods to do input and output; this is explained in Chapter 2 of the textbook. You do not need to do any checking of the input to make sure it is an integer; it is OK (at this point in the course) if your program cannot handle non-integer inputs. This is due Friday, January 28.

Return to the main Java page.
Return to the CIS 263 home page.


compliments and criticisms