Lab 3

Home Lab 1 Assignment 1 Lab 2 Assignment 2 Lab 3 Assignment 3 Assignment 4 Research Paper

 

Points: 50

Due: 10/18/2000

What to turn in:

Turn in a disk with all the answers to this assignment. Note that all files are to be put in their respective folders. That is, all files for lab x are to put in the folder A:\LABx, where x is the lab # and all files for assignment y are to be put in the folder A:\ASSIGNy, where y is the assignment #. For java applications, turn in the *.java and *.class files. For a question that involves an answer in simple text, turn in a *.txt file. For java applets, turn in the *.java, *.class, and *.html files.

Note: When you turn in the last assignment (not now!), I need you to also turn in the solutions to all the other labs/assignments that you have done since the beginning of the semester. I will keep this disk for record keeping purposes. You ought to also duplicate this disk so that you have a record of all the things that you have done for future reference.

[Simple Java I/O]

1. [10 pts] Using the template file printNames.java, write a Java program that prompts for 5 first names and echoes all the names that start with the character ‘J’ or 'j', have at least 4 characters, and end with "ny", "my", or "ly".

Sample interactions:

Enter a name: Johnny
Johnny satisfies the echoing condition

Enter a name: Mary

Enter a name: Billy

Enter a name: jimmy
jimmy satisfies the echoing condition

Enter a name: Jill

Hint: To check the first condition, note that the String class provides a method called charAt. This method returns the character at the position specified. For example, the following code prints "W".

String s = "HelloWorld"; // Declare an object reference called s, referring to the string "HelloWorld"

System.out.println(s.charAt(5)); // Index for string starts at position 0. So, position 5 gives 'W'

2. [20 pts] Create a class called ACSFaculty. The following are the fields and methods that the class is to support.

Methods

get and set methods for each of the fields 
canSubstituteFor (A can substitute for B if and only if A has the same or more areas of interests when compared to B and they have the same highest degree) 
computeAnnualSalary (returns salary * 12 if one is in an administrativePosition. Otherwise, returns salary * 9)
print  

Fields

name (String) 
salary (int) 
areasOfInterests (may be more than one area; to be implemented as an array) 
phone (String) 
administrativePosition (true or false depending on one’s appointment) 
highestDegree (String)
workAddress (String)

The driver for the above class is given in TestACSFaculty.java.  

Instructions:

  1. Create the ACSFaculty class. Note that this class does not have the main method. The driver is the one that contains the main method. (Check out the Alien sample program (under the Sample Program link) for an additional example of class creation.)

  2. When the above is ready to be tested, copy the TestACSFaculty driver and compile and run the it. If the ACSFaculty class is designed and implemented correctly, the driver (in cooperation with the ACSFaculty class) should display all the needed information.


[Java: General Concept]

3. [5 pts] Refer to the article "Today the Web, Tomorrow the World" for the following question.

In Java, what are peer classes and how are these classes used?

[Java: Applets]

4. [15 pts] Examine the applet given in CoinToss. You are to create a similar applet but yours should have the following additional requirements:

It should have a background color that is other than yellow, white, black, red, blue, and green.

It should compute the percentages of heads and tails and display them together with the number of heads and tails.

Use the template given in the file CoinToss.java. You need to only provide a method called tossACoin to do the simulation. The rest of the applet has already been written for you. Of course, you need to change the background color as well (you should be able to locate this one line that sets the color). 

5. [Bonus: 5 pts] Create an applet, call it DrawBox.java, that enables the user to draw a box in the applet space. The behaviors of the applet should resemble the one in DrawBox. (Hint: In the Graphics class, there is a drawRect method to draw a rectangle. Also, one of the mouse events that you can capture is mouseDragged.)

Check out some of the examples given below to get a feel of event handling on mouse.

http://www.itk.ilstu.edu/faculty/bllim/oo/MouseExampleonserver.html

http://www.itk.ilstu.edu/faculty/bllim/oo/MouseExample.java

http://www.itk.ilstu.edu/faculty/bllim/oo/EraseHDonServer.html

http://www.itk.ilstu.edu/faculty/bllim/oo/EraseHD.java