Professional Documents
Culture Documents
1. Fill in the blank in each question. The blank's answer is a single word. (5 points)
a. In Java, the _______ operator is used to allocate memory for an object.
b. In Java, the _______ class is used to read input from the keyboard.
c. The _______ keyword is used to declare a variable whose value cannot be changed.
d. A _______ is a special type of method that is called automatically when an object is created.
e. The _______ keyword is used to prevent a class from being inherited.
4. Write a program that asks the user’s name, and then greets the user by name. Before outputting the
user’s name, convert it to upper case letters. For example, if the user’s name is Ingrid, then the program
should respond “Hello, INGRID, nice to meet you!” (5 points).
6. Write a method named ArrayAverage() that takes an array as a parameter and returns the average of the
array elements (the average of all elements of the array is the sum of all elements of the array divided by
the number of elements). (10 points)
8. Write a program that uses nested for loops to print the following pattern:
1
23
456
7 8 9 10
9. Write a Java program that prompts the user to input an integer number and determines if the number is a
perfect number or not. If the number is perfect, the program should display the message 'The number is
perfect'. If the number is not perfect, the program should display the message 'The number is not perfect'.
(15 points)
10. Create two classes named Employee and PartTimeEmployee. The Employee class should have the
following properties:
• firstName: a string representing the employee's first name.
• lastName: a string representing the employee's last name.
• empID: an integer representing the employee's unique identifier.
• salary: a double representing the employee's salary.
The Employee class should have a constructor that takes all data fields as parameters to initialize them.
Additionally, the Employee class should have a calculatePay() method to return the salary of the employee.
The PartTimeEmployee class should inherit from the Employee class and should have the following
additional properties:
• hourlyRate: a double representing the employee's hourly rate.
• hoursWorked: an integer representing the number of hours the employee has worked.
The PartTimeEmployee class should have a constructor that takes in values for all its data fields and should
validate the hourlyRate and hoursWorked data fields to ensure that they are greater than zero. Additionally,
the hoursWorked field should be validated to ensure that it is less than or equal to 40 (since this is the
maximum number of hours that a part-time employee can work per week).
The calculatePay () method in the PartTimeEmployee class should override the calculatePay () method in
the Employee class. The calculatePay () method should calculate the payment based on the hourlyRate and
hoursWorked properties.
Create a test class with a main method and create one object of PartTimeEmployee. Display the payment
using the calculatePay () method. (20 points)