Question

In: Advanced Math

4) Write a brief reflection of Task 2 and 3 which may include description on data...

4) Write a brief reflection of Task 2 and 3 which may include description on data type used to solve the given task, variable used, and objects created. Reflection should also include justification on logic used to solve the given task along with proper references

Solutions

Expert Solution

Step 1: Task "2"

Program:

File name: “CalculateGPA.java”

import java.util.Scanner;

//Create a class

public class CalculateGPA {

      public static void main(String[] args) {

            // Scanner class object to take user input

            Scanner scan = new Scanner(System.in);

            //Prompt user to enter total number of students to be inserted

            System.out.print("Enter how many Students you want to be insert ");

            int numberOfStudents = Integer.parseInt(scan.nextLine());

            // 5 modules for each student

            int modules = 5;

            // Create array to hold name, ID, marks for each student and gpa

            String name_list[] = new String[numberOfStudents];

            String ID_list[] = new String[numberOfStudents];

            double marks_list[][] = new double[numberOfStudents][modules];

            double gpa_list[] = new double[numberOfStudents];

            System.out.println("Enter details of " + numberOfStudents + " students");

            // Create a for loop to take input for students

            for (int i = 0; i < numberOfStudents; i++) {

                  // Ask to enter name and ID

                  System.out.print("Student name" + (i + 1) + " ");

                  name_list[i] = scan.nextLine();

                  System.out.print("Student ID" + (i + 1) + " ");

                  ID_list[i] = scan.nextLine();

                  // Inner loop to take input for 5 modules

                  System.out.println("Mark of Modules\n********************");

                  for (int j = 0; j < modules; j++) {

                        System.out.print("Module" + (j + 1) + " ");

                        marks_list[i][j] = Double.parseDouble(scan.nextLine());

                  }

                  System.out.println("********************");

            }

            // Call function to calculate gpa for each student and store in gpa_list

            calculate_gpa_score(marks_list, gpa_list);

            // Call function to print details

            display_report(name_list, ID_list, marks_list, gpa_list);

      }

      private static void display_report(String[] name_list, String[] ID_list, double[][] marks_list, double[] gpa_list) {

            int total_students = name_list.length;

            System.out.println("Details of " + total_students + " students");

            // Create loop to print details of each student

            for (int i = 0; i < total_students; i++) {

                  // print name and ID

                  System.out.println("Student name" + (i + 1) + ": " + name_list[i]);

                  System.out.println("Student ID" + (i + 1) + ": " + ID_list[i]);

                  System.out.println("Mark of Modules and Grades\n********************");

                  System.out.printf("%-15s%-15s%-15s%-15s%-15s\n", "Module1", "Module2", "Module3", "Module4", "Module5");

                  // Inner loop to print module marks

                  for (int j = 0; j < marks_list[0].length; j++) {

                        System.out.printf("%-15.2f", marks_list[i][j]);

                  }

                  System.out.println();

                  // Inner loop to print letter grade. Call function to get corresponding letter

                  // to marks

                  for (int j = 0; j < marks_list[0].length; j++) {

                        System.out.printf("%-15s", letter_grade(marks_list[i][j]));

                  }

                  // Print gpa for current student using gpa_list

                  System.out.println("\nGPA - " + String.format("%.2f", gpa_list[i]));

                  System.out.println();

            }

      }

      public static void calculate_gpa_score(double marks_list[][], double gpa_list[]) {

            double gpa = 0;

            double grade = 0;

            for (int i = 0; i < marks_list.length; i++) {

                  for (int j = 0; j < marks_list[0].length; j++) {

                        // Call grade_value function to get grade_value corresponding to marks

                        grade = grade_value(marks_list[i][j]);

                        // Add grade*10 to current gpa

                        gpa += grade * 10;

                  }

                  // Calculate gpa and store in gpa_list at index i

                  gpa_list[i] = gpa / 50;

                  // Re-set gpa to 0 for another student

                  gpa = 0;

            }

      }

      public static String letter_grade(double marks) {

            String letter = "";

            // Use if-else if-else to set letter grade and return it at the end

            if (marks >= 91 && marks <= 100) {

                  letter = "A";

            } else if (marks >= 87 && marks <= 90) {

                  letter = "A-";

            } else if (marks >= 84 && marks <= 86) {

                  letter = "B+";

            } else if (marks >= 80 && marks <= 83) {

                  letter = "B";

            } else if (marks >= 77 && marks <= 79) {

                  letter = "B-";

            } else if (marks >= 74 && marks <= 76) {

                  letter = "C+";

            } else if (marks >= 70 && marks <= 73) {

                  letter = "C";

            } else if (marks >= 66 && marks <= 69) {

                  letter = "C-";

            } else if (marks >= 60 && marks <= 65) {

                  letter = "D+";

            } else if (marks >= 55 && marks <= 59) {

                  letter = "D";

            } else if (marks >= 50 && marks <= 54) {

                  letter = "D-";

            } else {

                  letter = "F";

            }

            return letter;

      }

      public static double grade_value(double marks) {

            double grade = 0;

            // Use if-else if-else to set numeric grade and return it at the end

            if (marks >= 91 && marks <= 100) {

                  grade = 4;

            } else if (marks >= 87 && marks <= 90) {

                  grade = 3.67;

            } else if (marks >= 84 && marks <= 86) {

                  grade = 3.33;

            } else if (marks >= 80 && marks <= 83) {

                  grade = 3.0;

            } else if (marks >= 77 && marks <= 79) {

                  grade = 2.67;

            } else if (marks >= 74 && marks <= 76) {

                  grade = 2.33;

            } else if (marks >= 70 && marks <= 73) {

                  grade = 2.0;

            } else if (marks >= 66 && marks <= 69) {

                  grade = 1.67;

            } else if (marks >= 60 && marks <= 65) {

                  grade = 1.33;

            } else if (marks >= 55 && marks <= 59) {

                  grade = 1.0;

            } else if (marks >= 50 && marks <= 54) {

                  grade = 0.7;

            } else {

                  grade = 0;

            }

            return grade;

      }

}


Related Solutions

Write brief notes on bacterial endospores. Include in your answer a description of how spore staining...
Write brief notes on bacterial endospores. Include in your answer a description of how spore staining is carried out. (Word limit 200)
Learning Task 18-02: Genetic Disorders Research and write a brief description of each genetic disorder. 1-...
Learning Task 18-02: Genetic Disorders Research and write a brief description of each genetic disorder. 1- Huntington Disease 2- Tay-Sachs Disease 3-Marfan Syndrome 4- Cystic Fibrosis 5-Duchenne Muscular Dystrophy For each disease, state the chances that a child would be born with the disease: if one parent carries the gene; and if both parents carry the gene. Explain how you arrived at your answers. Use Punnett squares to help justify your response for each disease.
In this task you will write a reflection about one of the key messages of the...
In this task you will write a reflection about one of the key messages of the unit: Biased treatment matters in health care. Reflective writing should demonstrate critical reading and thinking skills. The use of ‘I’ is expected in this assessment task (‘I think, I do not agree, I agree’, etc). Your essay should follow the following format: Introduction: Briefly identify the main points that you will explore in the essay (approximately 150 words) 1. Define intersectionality and use this...
In this task you will write a reflection about one of the key messages of the...
In this task you will write a reflection about one of the key messages of the unit: Biased treatment matters in health care. Reflective writing should demonstrate critical reading and thinking skills. The use of ‘I’ is expected in this assessment task (‘I think, I do not agree, I agree’, etc). Your essay should follow the following format: Introduction: Briefly identify the main points that you will explore in the essay (approximately 150 words) 1. Define intersectionality and use this...
In this task you will write a reflection about one of the key messages of the...
In this task you will write a reflection about one of the key messages of the unit: Biased treatment matters in health care. Reflective writing should demonstrate critical reading and thinking skills. The use of ‘I’ is expected in this assessment task (‘I think, I do not agree, I agree’, etc). Your essay should follow the following format: Introduction: Briefly identify the main points that you will explore in the essay (approximately 150 words) 2. Reflect on how your cultural...
Provide a brief introduction/background of the molecule Oseltamivir (Tamiflu) and include a brief description of what...
Provide a brief introduction/background of the molecule Oseltamivir (Tamiflu) and include a brief description of what the molecule is and how the molecule is used. Discuss how does the structure plays a role in its function and why is the shape of the molecule important to its function?
write a brief reflection about the experience of using CiscoPacket Tracer. This should be a...
write a brief reflection about the experience of using Cisco Packet Tracer. This should be a paragraph or two in which you reflect on your lab experience. Discuss items such as the following: What was the most valuable feature of the lab? How did you prepare for this lab? What changes are you considering in preparing for your next lab? What did you learn from this experience? What advice would you give someone who was preparing for this lab for...
Write a brief description of the emotions in the central nervous system
Write a brief description of the emotions in the central nervous system
Why is taxonomy important and useful? Include a brief description of the three Cs.
Why is taxonomy important and useful? Include a brief description of the three Cs.
Give a brief description of Medicaid or Medicare (no more than 2 sentences). Then discuss 3...
Give a brief description of Medicaid or Medicare (no more than 2 sentences). Then discuss 3 specific (non-age; non-financial) criteria for services from the program, for an older adult client. Be sure to cover service, length of time, provider types that may provide the service, the channels through which the patient may obtain each service.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT