-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleDataStructure.java
More file actions
64 lines (49 loc) · 2.1 KB
/
SampleDataStructure.java
File metadata and controls
64 lines (49 loc) · 2.1 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
63
64
import java.util.*;
import java.io.*;
public class SampleDataStructure {
public static void main(String[] args) {
try {
FileWriter writer = new FileWriter("ListOfStudents.txt");
HashMap<String,String> studentList = new HashMap<String,String>();
HashMap<Double,String> studentGrade = new HashMap<Double,String>();
ArrayList<String> studentLastName = new ArrayList<String>();
ArrayList<Double> aveGrade = new ArrayList<Double>();
Scanner input = new Scanner(System.in);
System.out.print("Number of Students: ");
int numOfStds = input.nextInt();
writer.write("Number of Students: " + numOfStds + "\n");
for (int num = 1 ; num <= numOfStds ; num++) {
System.out.println("\nStudent No." + num);
System.out.print("First Name: ");
String firstName = input.next().trim();
System.out.print("Last Name: ");
String lastName = input.next().trim();
studentList.put(lastName,firstName);
System.out.print("GPA: ");
studentGrade.put(input.nextDouble(),lastName);
}
for (String lname : studentList.keySet())
studentLastName.add(lname);
for (double ave : studentGrade.keySet())
aveGrade.add(ave);
Collections.sort(studentLastName);
Collections.sort(aveGrade);
writer.write("\nList of Students:\n");
for (String lname : studentLastName) {
writer.write(lname + ", " + studentList.get(lname));
writer.write("\n");
}
writer.write("\nDean's Lister:\n");
for (double ave : aveGrade) {
if (ave <= 1.5) {
writer.write(ave + " " + studentGrade.get(ave) + ", " + studentList.get(studentGrade.get(ave)));
writer.write("\n");
}
}
writer.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}