-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeReportArray.java
More file actions
71 lines (55 loc) · 2.15 KB
/
Copy pathGradeReportArray.java
File metadata and controls
71 lines (55 loc) · 2.15 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
65
66
67
68
69
70
71
/**
* This file reads in assignments names and scores using an Array list. Then, the file sorts the
* data based on assignment name or score of project.
*
* @summary GradeReportArray
* @author Ainsley Pyle
*
* Created at : 2023-09-18 11:53:42
* Last modified : 2023-09-18 13:17:18
*/
import java.util.ArrayList;
import java.util.Scanner;
//Assignment data type class.
class Assignment {
String name;
int score;
}
//GradeReportArray class
public class GradeReportArray {
public static void processAssignments(int numAssignments) {
Scanner scan = new Scanner(System.in);
int scoreSum = 0;
//Collection initialization and filling the collection
ArrayList<Assignment> assignments = new ArrayList<Assignment>();
int collectionSize = 3;
for (int i = 0; i < collectionSize; i++) {
Assignment x = new Assignment();
System.out.print("Enter Assignment Name: ");
x.name = scan.nextLine();
String temp;
System.out.print("Assignment Score: ");
temp = scan.nextLine();
x.score = Integer.parseInt(temp);
assignments.add(x);
}
//Sorting the assignments by name
System.out.println("Sort by name");
assignments
.sort((Assignment assignment1, Assignment assignment2) -> assignment1.name.compareTo(assignment2.name));
for (Assignment assignment : assignments) {
System.out.println("Assignment: " + assignment.name + " Score: " + assignment.score);
}
//Sorting the assignment by score
System.out.println("Sort by score");
assignments.sort((Assignment assignment1, Assignment assignment2) -> Integer.valueOf(assignment1.score)
.compareTo(Integer.valueOf(assignment2.score)));
for (Assignment assignment : assignments) {
System.out.println("Assignment: " + assignment.name + " Score: " + assignment.score);
}
scan.close();
}
public static void main(String args[]) {
processAssignments(3);
}
}