-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse12_25.java
101 lines (82 loc) · 2.98 KB
/
course12_25.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class course12_25 {
public static void main(String[] args) throws FileNotFoundException {
String[] work = {"assistant" , "associate" , "full"};
double assistantPrice = 0;
int assistantNum = 0;
double associatePrice = 0;
int associateNum = 0;
double fullPrice = 0;
int fullNum = 0;
createSalary createTxt = new createSalary();
createTxt.getSalary();
File file = new File("Salary.txt");
Scanner input = new Scanner(file);
while (input.hasNext()) {
String firstName = input.next();
String lastName = input.next();
String s = input.next();
double price = input.nextDouble();
if (s.equals(work[0])) {
assistantNum++;
assistantPrice += price;
}
if (s.equals(work[1])) {
associateNum++;
associatePrice += price;
}
if (s.equals(work[2])) {
fullNum++;
fullPrice += price;
}
}
System.out.println("The price of assistant is : " + assistantPrice / assistantNum);
System.out.println("The price of associate is : " + associatePrice / associateNum);
System.out.println("The price of full is : " + fullPrice / fullNum);
input.close();
}
}
class createSalary {
private int n = 1000;
private double price = 0;
private String firstName = "FirstName";
private String lastName = "LastName";
public void getSalary() {
File file = new File("Salary.txt");
if (file.exists()) {
System.out.println("The file had existed.");
}else {
try {
file.createNewFile();
}catch (IOException ex) {
ex.printStackTrace();
}
}
try (PrintWriter output = new PrintWriter(file);) {
int j = 0;
for (int i = 1 ; i <= n ; i ++ ) {
output.print(firstName + i + " ");
output.print(lastName + i + " ");
j = (int)( Math.random() * 3);
if (j == 0) {
output.print("assistant ");
output.printf("%.2f\n" , (Math.random() * 30000 + 50000));
}
if (j == 1) {
output.print("associate ");
output.printf("%.2f\n" , (Math.random() * 50000 + 60000));
}
if (j == 2) {
output.print("full ");
output.printf("%.2f\n" , (Math.random() * 55000 + 75000));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}