Finishing up project, and adding in comments

This commit is contained in:
Frank
2025-09-28 00:01:45 -06:00
parent 7c6a3615f7
commit a6c10dfcf1
2 changed files with 68 additions and 0 deletions

6
cs-115-project/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -1,5 +1,67 @@
/**
* This program lets the user enter up to 10 grades.
* It also provides:
* - Average Grade
* - Count of grades
* - Grade letter equivalent
*/
import java.util.ArrayList;
import java.util.Scanner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int userInput;
ArrayList<Integer> grades = new ArrayList<>();
int sum = 0;
// Loop the user input until 10
for (int i = 0; i < 10; i++) {
System.out.print("Please enter your grade: ");
userInput = scanner.nextInt();
// If '999' is detected it will end the program
if (userInput == 999) {
break;
}
// Add the user input to a sum
sum += userInput;
// Add the user input grade to the grades ArrayList
grades.add(userInput);
}
System.out.println();
System.out.println("Average Grade: " + sum / grades.size());
System.out.println("Amount of Grades: " + grades.size());
System.out.print("Grade List: ");
for (int grade:grades) {
System.out.print(grade + ", ");
}
System.out.println();
System.out.print("Converted To Grade Letter: ");
for (int grade:grades) {
System.out.print(calculateGrade(grade) + ", ");
}
}
// This method calculates and returns a letter grade based on the passed in score.
private static char calculateGrade(int grade) {
if (grade >= 90 && grade <= 100) {
return 'A';
} else if (grade >= 80 && grade <= 89) {
return 'B';
} else if (grade >= 70 && grade <= 79) {
return 'C';
} else if (grade >= 60 && grade <= 69) {
return 'D';
} else {
return 'F';
}
} }
} }