Java Reference
In-Depth Information
if ((idArray[i].compareTo(id)==0) &&
(passwordArray[i].compareTo(password)==0))
success=true;
7. After the loop, write an if...else statement to test the success of the program.
If it is true, use the setText() method to change the headerLabel to read as
follows: Login Successful. Then use the repaint() method to refresh the
screen. If it is false, display a message in the headerLabel to read as follows:
Invalid. Try Again. Then clear both text fields and reset the focus.
8. Compile and test the program using both valid and invalid ID and password
values.
9. Print a copy for your instructor.
5 Writing External Methods
As an intern at ReTech Incorporated, you have been asked to write a Java exter-
nal class named Employee that creates a programmer-defined employee record
when it is called. As ReTech hires new employees, it will use the Employee class,
along with a driver class, to input data about each employee. The fields should
include last name, first name, position, rate, and hours. You also should include
corresponding get() methods to allow for future searching and sorting.
Using the techniques you learned in creating the Rooms class from the
chapter, create an Employee class by performing the following steps:
1. Start TextPad. Save the file on the Data Disk using the file name, Employee.java.
2. Include a block comment with your name, date, and the class name, Employee.
3. Import the java.io.* package.
4. Write the public class header. Within the block, declare class variables as
shown in Table 5-16.
Table 5-16
Variables for the Employee Class
DATA TYPE
VARIABLE NAME
String
FirstName
String
LastName
String
Position
float
Rate
float
Hours
5. Begin a method constructor called Employee() that accepts the five arguments
— f, l, p, r, and h — which correspond to the variables in Table 5-16.
6. Within the method, assign each of the single letter identifiers to its corre-
sponding declared class variable.
7. Overload the method by creating a second method constructor, also called
Employee(), which overloads the class but accepts only three arguments — l,
f, and p — which correspond to the last name, first name, and position.
 
Search WWH ::




Custom Search