public class Exercise14
public class Exercise14
There is a method “getYearsOfService()” to calculate years of service between the hire date and
the current date, and returns the number of years as an integer value.
// Main.java
// Import the LocalDate class from the java.time package
import java.time.LocalDate;
// Create a new Employee object named employee2 with name "Loyd Blair",
salary 70000, and hire date "2015-04-01"
Employee employee2 = new Employee("Loyd Blair", 70000,
LocalDate.parse("2015-04-01"));
Java Code:
import java.util.*;
public class Exercise2 {
public static void main(String[] args) {
// Creae a list and add some colors to the list
List<String> list_Strings = new ArrayList<String>();
list_Strings.add("Red");
list_Strings.add("Green");
list_Strings.add("Orange");
list_Strings.add("White");
list_Strings.add("Black");
// Print the list
for (String element : list_Strings) {
System.out.println(element);
}
}
}
Sample Output:
Red
Green
Orange
White
Black
public class Exercise4 {
public static void main(String[] args) {
// Calculate and print the result of the expression: -5 + 8 * 6
System.out.println(-5 + 8 * 6);
Explanation:
The above Java code calculates and prints the results of four different arithmetic expressions: