have a java application need to create an application which is able to do some analysis on temperature data stored in a data file. You will be given the “temperatures.dat” data file which contains the data you must analyze. The analysis you’ll need to do is:
Total number of data points
Find coldest temperature
Find warmest temperature
Find average temperature
Find the frequency of each temperature
Find the most frequent temperature
Find the least frequent temperature
All classes must be in a package following these rules:
The package name is your last name plus the first letter of your first name. For example, if you name is Rita Red, her package is “ford.j”
Package names are all lowercase letters
All class names must start with an UPPERCASE letter then camel-cased after that.
All property names must start with a lowercase letter then came-cased after that.
All method names must start with a lowercase letter then came-cased after that.
Output must match the examples. Watch out for spaces and punctuationthe data file for the temps is
73
93
77
49
81
36
77
44
89
77
74
61
85
88
93
75
83
57
83
37
80
94
86
75
80
77
74
63
39
84
73
93
68
105
91
80
84
48
84
82
79
86
66
99
43
53
77
73
90
54
76
95
92
85
84
73
77
77
35
78
34
75
86
93
83
93
48
69
81
43
73
50
92
57
93
66
63
86
66
47
75
69
104
48
16
47
38
82
38
98
73
85
82
101
84
92
41
93
78
91
87
74
82
71
85
54
94
92
81
77
49
63
44
74
105
32
40
83
95
71
81
40
49
73
62
43
50
85
37
37
51
60
75
76
73
90
68
89
79
75
35
95
86
41
85
76
93
79
37
89
72
94
88
75
37
87
72
72
104
80
72
47
89
76
80
92
95
41
72
90
71
94
35
85
47
74
75
76
87
77
78
52
45
55
36
71
105
84
88
94
79
55
79
92
83
53
52
95
72
73
86
62
74
77
86
85
55
49
77
105
47
45
36
74
73
74
102
36
79
63
90
52
45
57
93
57
89
74
95
94
93
73
87
72
93
78
37
93
94
82
97
85
84
33
89
71
74
86
36
77
87
80
74
88
95
32
90
83
99
94
74
92
90
90
48
87
95
94
75
67
91
83
86
40
85
78
34
85
73
81
88
38
61
93
75
80
50
76
89
41
78
73
89
36
84
85
78
76
93
84
88
76
76
89
69
45
95
60
83
87
32
93
89
63
65
93
69
89
93
39
71
71
91
35
72
83
35
64
92
90
90
44
75
78
91
34
83
85
36
37
33
58
78
61
34
71
67
33
75
85
76
91
84
81
86
75
59
80
66
77
61
76
85
94
79
67
73
78
94
87
91
83
80
82
86
36
86
77
71
84
84
58
56
85
93
82
82
41
90
82
95
87
74
92
94
79
78
94
84
66
92
91
53
71
32
73
83
39
75
72
77
70
58
88
61
48
84
86
91
82
71
70
49
86
34
99
92
82
85
80
71
86
95
49
31
62
72
73
77
74
76
72
63
77
75
42
73
79
42
60
80
91
71
61
67
33
45
97
62
41
37
73
88
83
73
83
79
77
87
48
83
56
50
95
35
87
84
90
80
33
85
80
95
75
77
33
43
86
98
83
49
92
89
59
54
71
72
80
82
39
50
94
82
55
36
88
52
95
67
58
54
94
31
40
88
75
72
35
90
94
93
59
73
88
98
50
61
48
92
86
78
80
72
75
93
77
89
46
58
51
31
84
85
39
93
86
90
68
54
70
76
93
84
91
84
75
68
87
82
88
73
71
88
31
64
79
79
48
88
91
45
72
79
57
91
82
90
80
74
99
80
92
75
87
85
94
103
70
76
51
83
50
79
52
92
87
88
82
71
83
88
84
71
74
61
77
92
37
90
53
72
87
38
85
92
74
67
71
82
89
85
94
80
94
79
47
49
49
82
95
87
41
70
91
102
53
89
83
75
81
86
95
97
71
95
67
67
47
35
77
91
77
77
47
72
72
89
83
86
74
84
92
85
89
34
72
77
45
88
56
91
97
87
82
95
46
81
95
42
57
49
105
85
33
77
77
80
90
98
79
84
73
36
54
93
81
39
89
73
82
35
77
31
71
71
89
71
73
74
57
68
76
31
87
82
91
71
83
82
77
79
78
90
73
89
79
83
89
81
75
63
73
82
76
75
76
31
91
90
73
84
73
94
99
61
61
103
62
37
62
37
44
49
88
89
80
60
95
73
34
84
41
50
67
73
96
64
76
86
67
66
38
36
65
82
78
75
68
92
70
66
53
88
86
37
71
88
75
37
77
48
88
95
83
90
66
80
88
90
84
65
77
84
66
59
73
78
77
44
68
70
79
84
66
57
75
47
78
88
79
32
31
73
70
34
92
72
67
78
78
93
74
90
88
86
47
39
70
88
55
55
94
76
70
56
62
82
88
83
87
33
45
87
72
41
95
71
95
55
99
76
90
64
58
69
80
87
90
77
86
39
102
82
90
56
92
53
85
93
51
58
50
42
72
82
72
49
38
92
47
85
41
83
66
103
77
37
83
84
69
89
94
58
77
82
39
78
87
81
83
92
95
61
70
45
95
80
45
48
51
66
94
78
81
103
51
43
94
97
80
40
51
40
65
95
89
35
88
99
52
91
77
87
95
75
91
91
92
77
79
94
69
36
79
51
67
67
76
92
64
72
80
80
72
93
76
45
76
72
85
38
79
60
93
71
72
82
62
93
88
71
90
79
88
87
88
61
56
81
88
95
86
77
60
78
82
99
91
82
41
43
77
55
75
89
41
78
95
56
72
88
70
49
74
72
75
77
82
93
75
71
93
89
100
58
75
87
55
77
73
80
37
68
85
67
79
89
86
34
95
75
49
49
57
84
46
54
85
35
83
76
87
34
36
86
99
87
78
72
94
92
36
85
44
90
90
47
72
76
66
42
46
76
83
82
64
81
87
31
87
94
82
79
59
53
67
89
78
37
77
72
86
93
87
67
72
86
95
77
87
93
75
36
85
43
55
89
50
92
85
92
82
92
80
74
77
51
81
51
93
34
78
95
82
50
93
81
77
90
77
90
74
66
58
81
53
82
72
76
86
35
103
84
94
74
84
87
17
83
60
51
54
92
72
38
89
92
95
78
86
39
87
105
94
95
80
82
63
35
42
49
80
39
91
72
45
72
32
84
55
57
102
81
78
60
87
41
77
80
93
75
93
83
50
94
79
93
33
75
80
79
49
71
80
58
63
77
40
78
94
88
92
44
74
78
38
42
82
65
88
75
84
87
75
43
81
78
42
79
99
35
94
84
58
60
74
82
88
35
63
50
77
76
73
82
33
95
82
39
71
54
80
73
56
92
84
35
52
79
81
100
53
91
94
82
81
87
89
88
52
34
92
74
88
95
72
82
86
49
90
95
55
74
35
53
75
80
89
76
53
68
89
94
71
87
31
84
77
34
95
72
88
86
51
85
94
73
95
48
90
74
72
95
31
83
79
84
73
49
77
88
79
85
80
89
72
75
59
67
96
79
34
80
36
76
73
79
88
71
91
36
84
95
75
51
41
71
50
65
37
71
31
54
94
67
53
87
73
82
82
81
73
79
49
46
76
56
90
77
34
72
41
100
77
75
88
78
53
90
82
85
92
90
33
57
89
80
71
38
73
39
59
81
73
89
83
73
85
83
85
82
95
55
42
81
57
45
60
86
43
68
47
78
84
85
87
31
94
87
77
94
90
63
79
51
83
89
95
86
86
75
43
61
63
81
62
52
34
75
87
91
69
82
85
79
76
86
42
92
81
95
70
84
88
49
61
39
87
79
95
79
77
75
62
79
71
83
31
79
80
65
72
95
73
79
83
69
44
86
67
73
89
40
88
51
86
71
103
82
84
79
38
61
43
50
83
91
59
82
79
57
69
91
62
94
79
85
88
76
91
74
76
74
71
38
92
63
71
39
33
66
79
61
42
81
86
101
80
104
31
71
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class TemperatureAnalysis {
public static int getTotalTemperatureCount(HashMap<Integer, Integer> tempMap){
int totalCount = 0;
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
totalCount = totalCount + entry.getValue(); // adding the count of current temperature
}
return totalCount;
}
public static int coolestTemperatur(HashMap<Integer, Integer> tempMap){
int min = 0;
boolean isFirst = true;
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
if(isFirst){ // if this is the first temperature point thn initialize min value
min = entry.getKey();
isFirst = false;
}
else{
if(min > entry.getKey())
min = entry.getKey();
}
}
return min;
}
public static int warmestTemperatur(HashMap<Integer, Integer> tempMap){
int max = 0;
boolean isFirst = true;
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
if(isFirst){ // if this is the first temperature point thn initialize min value
max = entry.getKey();
isFirst = false;
}
else{
if(max < entry.getKey())
max = entry.getKey();
}
}
return max;
}
public static double averageTemperatur(HashMap<Integer, Integer> tempMap){
double total = 0; // sum of all temperature data points
int count = 0; // to store total number of temperature points
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
total = total + entry.getValue()*entry.getKey();
count = count + entry.getValue();
}
return total/count;
}
public static void frequency(HashMap<Integer, Integer> tempMap){
System.out.println("Temperature\tFrequency");
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
System.out.println(entry.getKey()+"\t\t"+entry.getValue());
}
}
public static int mostFrequentTemp(HashMap<Integer, Integer> tempMap){
int maxTemp = 0;
int maxCount = 0;
boolean isFirst = true;
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
if(isFirst){ // if this is the first temperature point then initialize maxTemp and maxCount value
maxTemp = entry.getKey();
maxCount = entry.getValue();
isFirst = false;
}
else{
if(maxCount < entry.getValue()){
maxTemp = entry.getKey();
maxCount = entry.getValue();
}
}
}
return maxTemp;
}
public static int lessFrequentTemp(HashMap<Integer, Integer> tempMap){
int minTemp = 0;
int minCount = 0;
boolean isFirst = true;
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
if(isFirst){ // if this is the first temperature point thn initialize min value
minTemp = entry.getKey();
minCount = entry.getValue();
isFirst = false;
}
else{
if(minCount > entry.getValue()){
minTemp = entry.getKey();
minCount = entry.getValue();
}
}
}
return minTemp;
}
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("temperatures.dat"));
// creating a HashMap to store each temperature and its frequency
HashMap<Integer, Integer> tempMap = new HashMap<>();
// reading temperature and storing in its hasmap
while(sc.hasNextInt()){
int temp = sc.nextInt();
// if current temperature is already in map, then increment the count value
if(tempMap.containsKey(temp)){
tempMap.put(temp, tempMap.get(temp)+1);
}else{
tempMap.put(temp, 1); // new temperature, then store with count 1
}
}
System.out.println("Total number of data points: "+getTotalTemperatureCount(tempMap));
System.out.println("Coldest temperature: "+coolestTemperatur(tempMap));
System.out.println("Warmest temperature: "+warmestTemperatur(tempMap));
System.out.println("Average temperature: "+averageTemperatur(tempMap));
System.out.println("Frequency of each temperature" );
frequency(tempMap);
System.out.println("Most frequent temperature: "+mostFrequentTemp(tempMap));
System.out.println("Least frequent temperature: "+lessFrequentTemp(tempMap));
}
}
/*
Sample run:
Total number of data points: 1531
Coldest temperature: 16
Warmest temperature: 105
Average temperature: 72.73546701502286
Frequency of each temperature
Temperature Frequency
16 1
17 1
31 15
32 6
33 12
34 16
35 17
36 17
37 17
38 12
39 15
40 8
41 15
42 11
43 11
44 8
45 13
46 5
47 13
48 11
49 21
50 15
51 15
52 9
53 14
54 10
55 13
56 9
57 13
58 12
59 8
60 10
61 16
62 11
63 13
64 6
65 7
66 15
67 19
68 10
69 10
70 13
71 40
72 43
73 45
74 31
75 44
76 34
77 55
78 32
79 46
80 40
81 27
82 51
83 38
84 40
85 40
86 40
87 42
88 44
89 38
90 35
91 29
92 37
93 37
94 39
95 46
96 2
97 5
98 4
99 10
100 3
101 2
102 4
103 6
104 3
105 6
Most frequent temperature: 77
Least frequent temperature: 16
*/
Get Answers For Free
Most questions answered within 1 hours.