In this assignment you will be working with variables, and reading in user data with the Scanner class, and creating methods
Requirements:
- Use
printf. You are not allowed to use any other method for printing output- Every method you created should be tested in the class’s main method.
- Every java file should have a header. However, DO NOT PUT YOUR NAME IN YOUR HEADERS. On gradescope we grade your assignments anonymously so including your name in your Java file will defeat that purpose. However, please include your name in your README.txt
Note, in the examples,
*indicates user input.
Write a program called Dates.java that will print out dates in different formats. The program should ask the user for the following information:
Sunday, Monday, …June, July10, 29, …2023, 1990, 1754Then create the following two methods:
printEuropean: this prints the information in the European formatprintAmerican: this prints the information in the American format.Both methods should have four paramaters. The order of the parameters should match the order listed above.
$ javac Dates.java; java Dates
What is a day of the week? *Thursday*
What is the month? *January*
What is the day of the month? *26*
What is the year? *2023*
European format: Thursday, January 26, 2023
American format: Thursday 26 January 2023
For this problem you will walk through the flow of execution of a program with multiple methods. Read the following code and answer the questions in a file called ControlFlow.txt. We removed public static for stylistic sakes, you can assume every method signature starts with public static
1 int fallOf(int num) {
2 System.out.println("1 fell off and bumped their head");
3 return num - 1;
4 }
5
6 void callDoctor(String animal) {
7 System.out.println("Momma called the doctor and the doctor said\nNo more " + animal + "jumping on the bed");
8 }
9
10 void jumping(int num, String animal) {
11 System.out.printf("There were %d %s jumping on the bed", num, animal);
12 }
13
14 void jumping(String animal, int num) {
15 System.out.printf("There were %d %s jumping on the bed", num, animal);
16 }
17
18 void song(String animal, int num) {
19 jumping(animal, num);
20 num = fallOf(num);
21 callDoctor(animal);
22 jumping(animal, num);
23 num = fallOf(num);
24 callDoctor(animal);
25 jumping(animal, num);
26 num = fallOf(num);
27 callDoctor(animal);
28 }
29
30 void main() {
31 song("monkeys", 4);
32 }
33
34 void main(String[] args) {
35 song("monkeys", 4);
36 }
37 }
Write down the line numbers in the order of which they are executed. For example, if java executed each line one at a time from the top of a file to the bottom, you would write something like 1, 2, 3, 4, ....
What is the value of the parameter num in the void jumping(String animal, int num) method the first time that method is called.
What is the output of this program.
Requirement: make to sure to seperate each line number by a comma (,), otherwise our autograder wont work and you will lose points.
BMC needs a program to calculate how much to pay their hourly employees. The US Department of Labor requires that employees get paid time and a half for any hours over 40 that they work in a single week. For example, if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base pay. BMC employess are paid at $15.00 an hour. Employees are not allowed to work more than 60 hours in a week.
Create a new class called Payments.
Write a method called pay() that takes the base pay and hours worked as parameters, and prints the total pay or an error. Write a main method that calls this method for each of these employees:
| Base Pay | Hours Worked | |
|---|---|---|
| Employee 1 | $22.50 | 48 |
| Employee 2 | $14.90 | 38 |
| Employee 3 | $30.92 | 70 |
| Employee 4 | $16.75 | 29 |
In a text file called README.txt answer the following questions:
Dont forget: make sure to fill in the header in all of your java files.
Submit the following files to the assignment called HW02 on Gradescope:
Dates.javaControlFlow.txtPayments.javaREADME.txtMake sure to name these files exactly what we specify here. Otherwise, our autograders might not work and we might have to take points off.