Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package generalPractice1;
- /*
- * Practice Problem:
- * - There are a ton of students and you need to determine what letter grade each student got depending on their
- * percentage.
- * * Design your code as if there were a thousand students, not just the ones provided.
- * - Print out how many of each letter grade there are using a count variable.
- * - print each student's name along with thdeir percentage and grade letter. One student per line.
- *
- * Notes / Recommendations:
- * - Be sure your code is organized.
- * - Keep your coding style constant throughout. This includes bracket placement, spaces, etc.
- * * This makes it easier to read for other people and looks better.
- * - While not required, disabling the auto complete settings will get you into the habit of opening and closing
- * parentheses, brackets, etc. Along with where to place semicolons. This will come in handy down the road when
- * you're taking a Computer Science class and are required to take a written test (meaning no auto-complete).
- */
- public class Main {
- public static void main(String[] args) {
- int[] grades = {30, 60, 85, 50, 90, 40, 90, 75, 99, 54};
- String[] students = {"Harry", "Josh", "Kyle", "Katelyn", "Tommy", "Jackson", "Jane", "Conner", "Paul", "Nancy"};
- int countA = 0, countB = 0, countC = 0, countD = 0, countF = 0;
- String pluralCountA = "", pluralCountB = "", pluralCountC = "", pluralCountD = "", pluralCountF = "";
- String pluralCountA2 = "", pluralCountB2 = "", pluralCountC2 = "", pluralCountD2 = "", pluralCountF2 = "";
- String letterGrade = "";
- // Determines what each student's grade is for the part that is supposed to print student name, %, and letter grade.
- for (int i = 0; i < grades.length; i++) {
- if (grades[i] >= 90) {
- letterGrade = "A";
- }
- else if (grades[i] >= 80) {
- letterGrade = "B";
- }
- else if (grades[i] >= 70) {
- letterGrade = "C";
- }
- else if (grades[i] >= 60) {
- letterGrade = "D";
- }
- else if (grades[i] <= 59) {
- letterGrade = "F";
- }
- // Will go through the loop and each time run it for the corresponding student & their grade.
- System.out.println(students[i] + ", " + grades[i] + ", " + letterGrade);
- // Counts how many of each letter grade there are.
- if (i >= 90) {
- ++countA;
- }
- else if (i >= 80) {
- ++countB;
- }
- else if (i >= 70) {
- ++countC;
- }
- else if (i >= 60) {
- ++countD;
- }
- else if (i <= 59) {
- ++countF;
- }
- } // End of the for loop.
- // Determines what type of grammar to use in the println statement later on, depending on whether it is
- // singular or plural.
- if (countA < 2) {
- pluralCountA = "is ";
- pluralCountA2 = ".";
- }
- else {
- pluralCountA = "are ";
- pluralCountA2 = "s.";
- }
- if (countB < 2) {
- pluralCountB = "is ";
- pluralCountB2 = ".";
- }
- else {
- pluralCountB = "are ";
- pluralCountB2 = "s.";
- }
- if (countC < 2) {
- pluralCountC = "is ";
- pluralCountC2 = ".";
- }
- else {
- pluralCountC = "are ";
- pluralCountC2 = "s.";
- }
- if (countD < 2) {
- pluralCountD = "is ";
- pluralCountD2 = ".";
- }
- else {
- pluralCountD = "are ";
- pluralCountD2 = "s.";
- }
- if (countF < 2) {
- pluralCountF = "is ";
- pluralCountF2 = ".";
- }
- else {
- pluralCountF = "are ";
- pluralCountF2 = "s.";
- }
- System.out.println("There " + pluralCountA + countA + " A grade" + pluralCountA2);
- System.out.println("There " + pluralCountB + countB + " B grade" + pluralCountB2);
- System.out.println("There " + pluralCountC + countC + " C grade" + pluralCountC2);
- System.out.println("There " + pluralCountD + countD + " D grade" + pluralCountD2);
- System.out.println("There " + pluralCountF + countF + " F grade" + pluralCountF2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement