CST1641 Advanced
Java I
Assignments
Click on this link to turn in
your assignments: \\Rc-hutch-ap\VOL1\HOME\allen_b\CST1641Labs
Note: This link only works if you are connected to the Ridgewater campus network and using Microsoft Internet Explorer. (Netscape cannot be used). If you do not have network access, you may turn your homework in on a floppy disk. You must label the diskette with your name, assignment number, and course number. The diskette must be turned in at the start of class. |
Java Files & Utilites |
Lab 3 |
Exercises |
Exercise 3.1
Using The resulting class file should be an application, NOT an applet. Inputs should be entered through a dialog box. Output results are printed directly to the console. Input and output should be of precision 2.
|
Exercise 3.2
Do the same exercise as above, but without the use of the input dialog box. Instead use input arguments. |
Lab 4 |
Exercises |
Exercise 4.1 In chapter 7 of Java for Students, there is a dice throwing program. Convert the applet to a stand alone program. Chapter 18 in Java for Students describes how to do the conversion from applets to stand alone programs. Use two text fields with appropriate labels to display the dice digits. Also make a separate Die.class that simulates the roll of the die. Each dice should be an object of the class Die. Here is the original program which is an applet that
will run in a browser: Here is the finished result. This is a
standalone program (cannot be run in a browser). |
Lab 5 |
Exercises |
Exercise 5.1 I am providing you with a Java application that has a class called Square. Write a class Cube1 which makes use of the Square class, has a height attribute and has a method which returns the volume of the cube. This class should NOT use inheritance. You should define a suitable constructor method for this class. Add some draw.Strings to test your results. Write a class Cube2 which inherits (extends) from the Square class, adds a height attribute and adds a method which returns the volume of the cube. You should define a suitable constructor method for this class. Add some draw.Strings to test your results. Write a class Rectangle which inherits from the Square class, adds a variable for the length of the rectangle, and overrides the perimeter and area methods in the Square class. You should change the width attribute of the Square class from private to private protected. Here is the Java application source code: Perimeter.java Screen snapshot of the original program. Here is the finished result. This is a
standalone program (cannot be run in a browser). |
Lab 6 Interfaces are even more abstract than classes. Interfaces are a template for a class. Interfaces are descriptions of variables and methods which any class must provide if it implements this interface. A subclass has only one superclass, but can implement many interfaces, providing the subclass defines variables and methods for all its interfaces. |
Exercises |
Exercise 6.1 Using the program 5.1 that you wrote previously, write an interface Prism which provides methods to set the height of the prism, to return the height of the prism, and to return the volume of the prism. Then write a class RectangularPrism which inherits from the Rectangle class, adds a height attribute and which implements the Prism interface. You should define a suitable constructor method for this class. Add some draw.Strings to
test your results. |
Lab 7 |
Exercises |
Exercise 7.1 For this exercise use a previous applet that you wrote in Intro to Java that drew geometric shapes. Ideal programs would come from chapters 3, 4, and 5 in Java for Students. Convert your applet to an application. Use swing. Your frame should use 1/4 of the screen size, regardless of the resolution of the screen. Verify this by setting the resolution of your screen to 640X480, 800X600, and 1024X768 and checking that your application uses only 1/4 of the screen. The frame should be approximately in the center of the monitor screen. Give the window an appropriate title that represents what your program does. Display a small sentence of what your program does in the window. Use a font style, size, and color other than the defaults. Be able to close the window. |
Exercise 7.2 (Extra
Credit) Take the program above, turn it back into an applet, and make it run within a web page, and continue using swing. |
Lab 8 |
Exercises |
Exercise 8.1 In chapter 7 of Java for Students, there is a Digital Combination Safe problem. This is a variation of the problem in the book. Write a program to act as the digital combination lock for a safe. Create ten buttons, representing the numbers 0 through 9. The user clicks on the buttons, attempting to guess the correct numbers (example: 638) The program remains unhelpfully quiet until the correct buttons are pressed consecutively. When the correct sequence in pressed, print a message that the combination is valid. Also have a button that allows the user to change the safe's combination only after they have entered the original combination correctly. This is similar to the way users are allowed to change passwords for other computer applications. Have graphics on the buttons instead of just plain text. The program needs to be a stand alone application written using swing. |
Exercise 8.2 (Extra
Credit) Take the program above, turn it back into an applet, and make it run within a web page, and continue using swing. It must be launched within a web browser (not from the run Java applet menu selection in Textpad). Note: It may be quite difficult to get graphics on the buttons when it is an applet. Extra extra credit if you can use graphics in an applet that runs in a web browser. :-) |
Lab 9 |
Exercises |
Exercise 9.1 For this exercise you are going to build upon the program that you did for Exercise 8.1, the combination safe. Modify your program so that both the try again and the change combination button uses a graphic, a shortcut key, and a pop up tool tip. When entering a new combination, use a formatted input field (JFormattedTextField) such that the user can enter only three numerals 1 through 9. No other characters should be allowed. So the combinations allowed are "111" through "999" with never a zero. Label your components. (Do not use drawString.) So the formatted input field for your new combination should be labeled with something descriptive, like "New Combination", and the the buttons for entering the numerals should be grouped and a label describes them as "Combination Entry Keys" or something similar. Also set up a menu for the application. You should have at least three menu selections. File exit, another that shows your current combination, and a menu selection for help. Create an icon for the help menu selection. Also create keyboard accelerators for your menu selections. When the user clicks on your "help" menu selection, pop up a modal dialog box that provides some basic help information on how to use your program. Have an "OK" button on the bottom of this pop up dialog box that closes this box. This should be similar to the figure 9-48 on page 463 of the text. Use a layout system other than the default flow layout. Create a layout that looks professional. The program needs to be a stand alone application written using swing. |
Exercise 9.2 (Extra
Credit) Take the program above, turn it back into an applet, and make it run within a web page, and continue using swing. It must be launched within a web browser (not from the run Java applet menu selection in Textpad). Note: It may be quite difficult to get graphics on the buttons when it is an applet. Extra extra credit if you can use graphics in an applet that runs in a web browser. :-) |
Exercise 9.3 Take the program that you created for Exercise 9.1 and add two additional control types to it. These can be anything learned from chapter 9 in the textbook. Examples would be Text Areas, Check Boxes, Radio Buttons, Combo Boxes, pop up menus, etc. Use the controls in a fashion that would add additional functionality to your program. |
Lab 10 |
Exercises |
Exercise 10.1 For this exercise you are going to build upon the program that you did for Exercise 9.1, the combination safe. Modify your program so that without any code modifications, it runs as both an applet and an application. Add the ability to pass information to the program if it is run as an applet in a browser. Pass the initial combination to the applet via the <param name="combination" value="123"/> Test this in a browser. Package the entire program (all the class files) and any resources the program needs (all the image files, etc.) into a JAR file. This needs to be a self-running JAR file. You should be able to run this program both stand alone and also be able to launch this program as an applet in a web browser. |
Lab 12 / Final |
Exercises |
Exercise 12.1 / Final For this exercise you are going to make a Java application. Read chapter 12 - Streams and Files in Core Java and chapter 19 - Files in Java for Students. These chapters are extremely important, since the only way most programs have any real usefulness is if they save data and retrieve the data at a later date. Come up with a final project. The final project should be a program that uses many of the concepts that we have learned this semester. In particular you must include the use of random access files in your project. The program itself does not have to be extremely large. Something on the order of complexity of the combination safe program that we had been working on would be sufficient. |