Reference no: EM132287965
QUESTIONS
Note: In each question, assume that the user enters correct inputs. You can drag and drop components.
UPLOAD
• AccountSavings.java
• Person.java
• PersonTest.java
• YourFirstNameYourLastName.zip / YourFirstNameYourLastName.rar
1. Create a class AccountSavings. The class has two instance variables: a double variable to keep annual interest rate and a double variable to keep savings balance. The annual interest rate is 5.3 and savings balance is $100.
• Create a method to calculate monthly interest.
• Create a method to run two threads. Use anonymous classes to create these threads. The first thread calls the monthly interest calculation method 12 times, and then displays the savings balance (the balance in 12nd month). After that, this thread sleeps 5
seconds.
The second thread calls the monthly interest calculation method 12 times, and then displays the savings balance (the balance in 12nd month). Before the main thread ends, these two threads must be completed.
• Add your main method into the same class and test your threads. After these two threads are executed, the savings balance must remain same.
2. Create a class Person. A person has a first name and a last name. Create a constructor for the person. Use the interface Runnable to create a thread from the class Person. This thread displays a message that the given person is started to work (display his/her first name and last name). Then, the thread sleeps 5 seconds. And then, the thread displays that the given person is completed its job (display his/her first name and last name).
Then, create a class PersonTest. Use executor services to create a thread pool with a size of 3. Then, submit 4 Person threads. In the main thread, display a message that the all tasks are submitted, and display that all tasks are done.