|
The programs that you turn in will be graded according to the criteria given in the first of the following three links. The second link gives detailed instructions on exactly how you are to turn in your finished assignments. The programs that you turn in should conform to the style guide contained in the third link (it was written by Cay Horstmann, a well known Java author).
Program grading criteria
Turning in your assignments
Java Language Coding Guidelines
Below are your Java programming assignments. The due date for each one is contained in the assignment description.
- Assignment 12.
- The details of this assignment are in these instructions. This assignment is due on Friday, December 10.
- Assignment 11.
- This assignment is based on the material from Chapter 7 about inheritance, abstract classes, and polymorphism. The details of this assignment are in these instructions. This assignment is due on Wednesday, December 1.
- Assignment 10.
- This assignment is a modification of Programming Project 2 on page 471 at the end of Chapter 7. Define a derived class
Arrow of the class Figure in Display 7.10 from the textbook, and then define two derived classes LeftArrow and RightArrow of class Arrow . The classes LeftArrow and RightArrow should implement the left and right arrow figures described in the textbook's assignment, but you should put in the Arrow class as much data (i.e., fields) and code (i.e. methods) as possible that is common to both the right and left arrow figures. In addition, the Arrow class should have a field called symbol that is of type char that holds the character used to draw the arrow (the default value for symbol should be '*' ). Provide appropriate constructors for class Arrow and the constructors for classes LeftArrow and RightArrow should make use of the super class constructor. Notice that your Arrow class will end up being a class that it does not make much sense to instantiate (you really can't draw an "arrow" without saying which way it points) but do not worry about that. The purpose of the Arrow class is to "factor out" of the LeftArrow and RightArrow classes as much common data and code as possible. This assignment is due on Wednesday, November 24.
- Assignment 9.
- This assignment is a modification of Programming Project 7 on page 412 at the end of Chapter 6. Instead of writing a program so that two users can play tic-tac-toe, write a program so that one user can play tic-tac-toe against the computer. So you will need to implement a tic-tac-toe strategy in your program. I will not grade you on how well your strategy plays tic-tac-toe, so you can implement as trivial a strategy (or strategies, see below) as you wish. But whatever your strategy is, be sure to clearly document it. Your program should display the tic-tac-toe board after each player makes its move (including the computer player). Your program should not allow the human player to make an illegal move. Your program should automatically detect when one of the players has won or the game has tied.
Write your program in as modular a form as you can. For example, you might want to implement parts of your program as additional classes (besides the required TicTacToe class). Write your program so that it would be easy to make the following kinds of modifications. Design your program so that it is easy to "swap in" a new strategy for the computer player (at compile time, not at run time). Try to make it easy to modify the program so that the computer would play against itself (with the same or different strategies for each computer player). Try to make it easy to modify the program so that two humans players can play against each other. Also, try to make it easy to modify the way the program prints out a tic-tac-toe board. This assignment is due on Monday, November 15.
- Assignment 8.
- Do Programming Project 2 on page 410 at the end of Chapter 6 of the textbook. Make the following modifications. Your program should read in lines of text (using
SavitchIn.realLine() ) until it finds five empty lines in a row (that is the sentinel that marks the end of the input, not a period as given in the textbook). For each line your program reads in it should scan through the line and count the occurrences of letters and ignore all non alphabetic characters. After the sentinel has been found, output some summary information. Your summary information should include the number of times each letter occurred in the input text and, more importantly, the relative frequency of the letter in the text as a percentage (this is the statistical data that should be fairly constant over different long pieces of English text). Try to format your data in a neat, informative way. Write your program as a "one shot" program, that is, after finding the sentinel and printing the summary information, terminate the program. Test your program, using I/O redirection, on some large text files downloaded from the following two locations, books by Lewis Carrol, or books by Edgar Allen Poe (or, if you want to go after something really big, try Tolstoy's War and Peace). You will need to use a text editor (e.g. JCreator) to add five blank lines to the end of these files in order to have a sentinel (these files use several blank lines to denote the end of chapters, so I'm making five blank lines the "end of file" sentinel). This assignment is due on Wednesday, November 3.
- Assignment 7.
- Do Programming Project 4 on page 338 at the end of Chapter 5 of the textbook. Since your new class will have constructors, your class should not contain the method
readInput() , and the single set mutator method should be replaced with setName and setAge mutator methods. This assignment is due on Monday, October 25.
- Assignment 6.
- Do Programming Project 5 on page 258 at the end of Chapter 4 of the textbook. Call the class described in the assignment
GradeDistribution.java . Your class should have the following methods.
setNumberOfAs()
setNumberOfBs()
setNumberOfCs()
setNumberOfDs()
setNumberOfFs()
getNumberOfAs()
getNumberOfBs()
getNumberOfCs()
getNumberOfDs()
getNumberOfFs()
getTotalNumberOfGrades()
getPerCentA()
getPerCentB()
getPerCentC()
getPerCentD()
getPerCentF()
drawGraph()
Write a program TestGradeDistribution.java that creates an instance of GradeDistribution and tests all of the methods from your implementation of the GradeDistribution class. None of the methods from the GradeDistribution class should prompt a user for input. All prompting of a user should be done by the TestGradeDistribution.java program which should use the set methods from the GradeDistribution class to put data into a GradeDistribution object. Put your two Java files, along with a copy of SavitchIn, in a single zip file and turn in the zip file. This assignment is due on Monday, October 18.
- Assignment 5.
- This assignment is based on the material from Chapter 4 about writing classes and methods. The details of this assignment are in these instructions. This assignment is due on Monday, October 11.
- Assignment 4.
- Do Programming Project 4 on page 178 at the end of Chapter 3 of the textbook. Write your program in such a way that your program does not prompt the user in any way for the input values! Your program should read exactly one integer per line of input from the user, but not ever prompt the user for the input. Now why would you want to write a program that reads in data from a user but does not prompt the user in any way? The answer is a very important idea called "I/O redirection". A program like this assignment is meant to process data, but it can be very tedious and error prone to enter a lot of data into a program like this. It is better to first enter the data into a data file, like this one called
data.txt , and then have the program process the data contained in the file. And here is how you can get a Java program to read its input from a data file. First we need to create a JCreator tool to do this.
Click on JCreator's "Configure -> Options..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "New" button and choose the item "Program" from the drop down list that appears. In the file dialog box that comes up, navigate to the directory C:\Windows\system32 and then in that directory double click on the program cmd.exe (this assumes that you are using Windows XP). Now you should be back to JCreator's "Options" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "CMD". Click on the item "CMD". This brings up a window where we can configure the "CMD" tool. In the text box labeled "Arguments:" enter the following text. (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
/k $[JavaHome]\bin\java.exe -classpath "$[ClassPath]" $[FileBase]
In the text box labeled "Initial directory:" enter the following text:
$[FileDir]
Make sure that the check boxes labeled "Prompt for arguments" and "Show command line" are checked and all of the other check boxes are unchecked. Now click on the button "OK" at the bottom of the window. This completes the creation of the tool. (You can check at this point and look in JCreator's "Tools" menu to see if the tool "CMD" is in the menu list.)
Here is how to use this tool. When you want to run your program and test it using the data file (that you should download and put in the same directory as your Java program), click on the "CMD" item in JCreator's "Tools" menu. A small dialog box pops up with a text box in it. At the end of the text in the text box, add this text
< data.txt
Be sure to add this to the end of what is in the text box and not obliterate the text that is already there. Click on the "OK" button and your program will run, reading its input from the data file and printing its output in the console window. If you want to get fancy, you can even have your program save its output in a new data file. When you run your program, put the following text in the text box
< data.txt > output.txt
When you click "OK", your program will seem to silently run, but it will read its input from "data.txt " and write its output in a new file called "output.txt " (look for it in the directory holding your program). Here is a program, TestIORedirection.java, that you can use to test this tool. This assignment is due on Wednesday, September 29.
- Assignment 3.
- Do Programming Project 1 on page 177 at the end of Chapter 3 of the textbook. This assignment is due on Wednesday, September 22.
- Assignment 2.
- Do Programming Project 5 on page 100 at the end of Chapter 2 of the textbook. When you write your program, be sure that the output of your program does not include any leading spaces. So for example, if the input to your program is the following line of text
This line is spaced funny
then the output of your program should be
line is spaced funny This
and not this
line is spaced funny This
For this assignment you will need to be familiar with Java's String class, which is described in Section 2.2. In particular, be sure to look carefully at Display 2.6 (pages 71-74) which lists methods from the String class that you can use for this assignment.
This assignment is due on Wednesday, September 15.
- Assignment 1.
- Write a Java program that prints the following picture.
***************
* *
* *
* Hello *
* *
* *
***************
The output of your program should exactly match this picture. Your program will consist of a sequence of print statements, one for each line of the picture. Don't print any unneeded characters. The main purpose of this assignment is to get you started using the editor and the compiler. This assignment is due on Wednesday, September 8.
|
|