-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
62 lines (49 loc) · 2.28 KB
/
Copy pathProgram.java
File metadata and controls
62 lines (49 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package application;
import entities.Department;
import entities.HourContract;
import entities.Worker;
import entities.enums.WorkerLevel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
public class Program {
public static void main(String[] args) throws ParseException {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.print("Enter department's name: ");
String departmentName = sc.nextLine();
System.out.println("Enter worker data:");
System.out.print("Name: ");
String workerName = sc.nextLine();
System.out.print("Level: ");
String workerLevel = sc.nextLine();
System.out.print("Base salary: ");
double baseSalary = sc.nextDouble();
Worker worker = new Worker(workerName, WorkerLevel.valueOf(workerLevel), baseSalary, new Department(departmentName));
System.out.print("How many contracts to this worker? ");
int n = sc.nextInt();
for (int i=1; i<=n; i++) {
System.out.println("Enter contract#" + i + " data:");
System.out.print("Date (DD/MM/YYYY): ");
Date contractDate = sdf.parse(sc.next());
System.out.print("Value per hour: ");
double valuePerHour = sc.nextDouble();
System.out.print("Duration (hours): ");
int hours = sc.nextInt();
HourContract contract = new HourContract(contractDate, valuePerHour, hours);
worker.addContract(contract);
}
System.out.println();
System.out.print("Enter month and year to calculate income (MM/YYYY): ");
String monthAndYear = sc.next();
int month = Integer.parseInt(monthAndYear.substring(0,2));
int year = Integer.parseInt(monthAndYear.substring(3));
System.out.println("Name: " + worker.getName());
System.out.println("Department: " + worker.getDepartment().getName());
System.out.println("Income for " + monthAndYear + ": " +String.format("%.2f", worker.income(year, month)));
sc.close();
}
}