Repository navigation
Expand file tree
/
Copy pathReportCard.java
More file actions
55 lines (47 loc) · 1.94 KB
/
Copy pathReportCard.java
File metadata and controls
55 lines (47 loc) · 1.94 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
// Name: Ayush Kumar
// Partner: None
// Instructor: Mr. Virak
// Course: AP Computer Science A
// Assignment: 1.16.1 — Formatted Report Card
// Date: September 30th, 2026
/**
* Assignment 1.16.1 — Formatted Report Card
* Prints an aligned Name/Score/Grade report using String.format().
* Scale: standard 90/80/70/60 cutoffs (A/B/C/D, below 60 is F).
*/
public class ReportCard {
// Shared column widths: Name 15, Score 6, Grade 5
static final String HEADER_FORMAT = "%-15s %6s %5s";
static final String ROW_FORMAT = "%-15s %6.1f %5s";
public static void main(String[] args) {
// Parallel arrays; short and long names test alignment
String[] names = {"Al", "Christopher", "Beatrix", "Sam", "Priya", "Maximilian", "Jo"};
// Boundary tests: 90.0 = A, 89.9 = B, 60.0 = D, 59.9 = F
double[] scores = {92.5, 78.3, 89.9, 60.0, 95.0, 90.0, 59.9};
// Header uses same widths as data rows
System.out.println(String.format(HEADER_FORMAT, "Name", "Score", "Grade"));
// Separator dashes sized to each column (15, 6, and 5 dashes)
System.out.println(String.format(HEADER_FORMAT,
"---------------", "------", "-----"));
for (int i = 0; i < names.length; i++) {
String grade = letterGrade(scores[i]);
// Left-align names: shared left edge makes text easy to scan
// Right-align scores: decimal points and place values line up
System.out.println(String.format(ROW_FORMAT, names[i], scores[i], grade));
}
}
// Highest to lowest; >= so exact cutoffs earn the higher grade
public static String letterGrade(double score) {
if (score >= 90.0) {
return "A";
} else if (score >= 80.0) {
return "B";
} else if (score >= 70.0) {
return "C";
} else if (score >= 60.0) {
return "D";
} else {
return "F";
}
}
}