Question

In: Computer Science

Java Program Suppose a student was taking 5 different courses last semester. Write a program that...

Java Program

Suppose a student was taking 5 different courses last semester. Write a program that

(a) asks the student to input his/her name, student ID, marks for these 5 courses,

(b) calculate the average,

(c) determine the letter grade of each course.

(d) record the number of courses whose final letter grade is A+, A, A-, .... , F+, F, F-.

(e) Output the following information in a nice format: student name, student ID, listing of marks, the average, letter grade for each course, and the number of courses in each letter grade category.

I dont know how to do part ( d )

here is my code:

import java.util.Scanner;

public class Question_2 {

   public String Grade(int mark) {

       String GradeLetter = "";

       if (mark >= 93 && mark <= 100)

           GradeLetter = "A+";

       if (mark >= 86 && mark < 93)

           GradeLetter = "A";

       if (mark >= 80 && mark < 86)

           GradeLetter = "A-";

       if (mark >= 77 && mark < 80)

           GradeLetter = "B+";

       if (mark >= 73 && mark < 77)

           GradeLetter = "B";

       if (mark >= 70 && mark < 73)

           GradeLetter = "B-";

       if (mark >= 67 && mark < 70)

           GradeLetter = "C+";

       if (mark >= 63 && mark < 67)

           GradeLetter = "C";

       if (mark >= 60 && mark < 63)

           GradeLetter = "C-";

       if (mark >= 57 && mark < 60)

           GradeLetter = "D+";

       if (mark >= 53 && mark < 57)

           GradeLetter = "D";

       if (mark >= 50 && mark < 53)

           GradeLetter = "D-";

       if (mark >= 35 && mark < 50)

           GradeLetter = "F";

       if (mark >= 0 && mark < 35)

           GradeLetter = "F-";

       return GradeLetter;

   }

   public static void main(String[] args) {

       Question_2 q2 = new Question_2();

       // declare variables

       String name;// student name

       int studentID;// student ID

       int mark1, mark2, mark3, mark4, mark5;// student marks in each 5 courses

       // asks the student to input his/her name

       System.out.println("Input your first name: ");

       Scanner input = new Scanner(System.in);

       name = input.nextLine();

       // asks the student to input student ID

       System.out.println("Input your StudentID (integer in 5 digits),ex:000000 :");

       studentID = input.nextInt();

       // asks the student to input marks of 5 different courses last semester

       System.out.println("Input your courses grade (0-100)integer number ");

       System.out.println("Your course1's grade: ");

       mark1 = input.nextInt();

       System.out.println("Your course2's grade: ");

       mark2 = input.nextInt();

       System.out.println("Your course3's grade: ");

       mark3 = input.nextInt();

       System.out.println("Your course4's grade: ");

       mark4 = input.nextInt();

       System.out.println("Your course5's grade: ");

       mark5 = input.nextInt();

       // Calculate the average of 5 different courses last semester

       double average = (mark1 + mark2 + mark3 + mark4 + mark5) / 5.0;

       /*

       * Output the following information in a nice format: student name,

       * student ID, listing of marks, the average, letter grade for each

       * course, and the number of courses in each letter grade category.

       */

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

       System.out.println("Student Name: " + name);

       System.out.println("Student ID : " + studentID);

       System.out.println(name + " grade in " + "Course1: " + mark1 + " " + q2.Grade(mark1));

       System.out.println(name + " grade in " + "Course2: " + mark2 + " " + q2.Grade(mark2));

       System.out.println(name + " grade in " + "Course3: " + mark3 + " " + q2.Grade(mark3));

       System.out.println(name + " grade in " + "Course4: " + mark4 + " " + q2.Grade(mark4));

       System.out.println(name + " grade in " + "Course5: " + mark5 + " " + q2.Grade(mark5));

       System.out.println(name + " avaerage grade is: " + average);

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

   }

}

Solutions

Expert Solution

import java.util.Scanner;

public class Question_2 {

   public String Grade(int mark) {

       String GradeLetter = "";

       if (mark >= 93 && mark <= 100)

           GradeLetter = "A+";

       if (mark >= 86 && mark < 93)

           GradeLetter = "A";

       if (mark >= 80 && mark < 86)

           GradeLetter = "A-";

       if (mark >= 77 && mark < 80)

           GradeLetter = "B+";

       if (mark >= 73 && mark < 77)

           GradeLetter = "B";

       if (mark >= 70 && mark < 73)

           GradeLetter = "B-";

       if (mark >= 67 && mark < 70)

           GradeLetter = "C+";

       if (mark >= 63 && mark < 67)

           GradeLetter = "C";

       if (mark >= 60 && mark < 63)

           GradeLetter = "C-";

       if (mark >= 57 && mark < 60)

           GradeLetter = "D+";

       if (mark >= 53 && mark < 57)

           GradeLetter = "D";

       if (mark >= 50 && mark < 53)

           GradeLetter = "D-";

       if (mark >= 35 && mark < 50)

           GradeLetter = "F";

       if (mark >= 0 && mark < 35)

           GradeLetter = "F-";

       return GradeLetter;

   }

   public static void main(String[] args) {

       Question_2 q2 = new Question_2();

       // declare variables

       String name;// student name

       int studentID,i;// student ID

       int[] marks = new int[5];   // student marks in each 5 courses
     
       int countAplus,countA,countAminus,countBplus,countB,countBminus,countCplus,countC,countCminus,countDplus,countD,countDminus,countFplus,countF,countFminus;
       countAplus=countA=countAminus=countBplus=countB=countBminus=countCplus=countC=countCminus=countDplus=countD=countDminus=countFplus=countF=countFminus=0;

       // asks the student to input his/her name

       System.out.println("Input your first name: ");

       Scanner input = new Scanner(System.in);

       name = input.nextLine();

       // asks the student to input student ID

       System.out.println("Input your StudentID (integer in 5 digits),ex:000000 :");

       studentID = input.nextInt();

       // asks the student to input marks of 5 different courses last semester

       System.out.println("Input your courses grade (0-100)integer number ");

       System.out.println("Your course's grade: ");

       for(i=0;i<5;i++)
       marks[i] = input.nextInt();

     

       // Calculate the average of 5 different courses last semester

       double average = (marks[0] + marks[1] + marks[2] + marks[3] + marks[4]) / 5.0;

       /*

       * Output the following information in a nice format: student name,

       * student ID, listing of marks, the average, letter grade for each

       * course, and the number of courses in each letter grade category.

       */

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

       System.out.println("Student Name: " + name);

       System.out.println("Student ID : " + studentID);
     
       for(i=0;i<5;i++)
       {
       String grade = q2.Grade(marks[i]);
       System.out.println(name + " grade in Course " + (i+1) + " "+marks[i] + " " + grade);
     
       //count the number of grades in A+,A,A-,B+,B,B-,C+,C,C-,D,+,D-,F,F+,F-
       if(grade.equals("A+"))
       countAplus++;
       else if(grade.equals("A"))
       countA++;
       else if(grade.equals("A-"))
       countAminus++;
       else if(grade.equals("B+"))
       countBplus++;
       else if(grade.equals("B"))
       countB++;
       else if(grade.equals("B-"))
       countBminus++;
       else if(grade.equals("C+"))
       countCplus++;
       else if(grade.equals("C"))
       countC++;
       else if(grade.equals("C-"))
       countCminus++;
       else if(grade.equals("D+"))
       countDplus++;
       else if(grade.equals("D"))
       countD++;
       else if(grade.equals("D-"))
       countDminus++;
       else if(grade.equals("F+"))
       countFplus++;
       else if(grade.equals("F"))
       countF++;
       else if(grade.equals("F-"))
       countFminus++;
     
    
     

       }

       System.out.println(name + " average grade is: " + average);
     
       System.out.println("Number of courses whose final grade is A+ : "+countAplus);
       System.out.println("Number of courses whose final grade is A : "+countA);
       System.out.println("Number of courses whose final grade is A- : "+countAminus);
     
       System.out.println("Number of courses whose final grade is B+ : "+countBplus);
       System.out.println("Number of courses whose final grade is B : "+countB);
       System.out.println("Number of courses whose final grade is B- : "+countBminus);
     
       System.out.println("Number of courses whose final grade is C+ : "+countCplus);
       System.out.println("Number of courses whose final grade is C : "+countC);
       System.out.println("Number of courses whose final grade is C- : "+countCminus);
     
       System.out.println("Number of courses whose final grade is D+ : "+countDplus);
       System.out.println("Number of courses whose final grade is D : "+countD);
       System.out.println("Number of courses whose final grade is D- : "+countDminus);
     
       System.out.println("Number of courses whose final grade is F+ : "+countFplus);
       System.out.println("Number of courses whose final grade is F : "+countF);
       System.out.println("Number of courses whose final grade is F- : "+countFminus);

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

   }

}


output:

Input your first name: Steve James
Input your StudentID (integer in 5 digits),ex:000000 :10067
Input your courses grade (0-100)integer number 
76
45
89
93
66
Your course's grade: 
**********************************************
Student Name: Steve James
Student ID : 10067
Steve James grade in Course 1  76 B
Steve James grade in Course 2  45 F
Steve James grade in Course 3  89 A
Steve James grade in Course 4  93 A+
Steve James grade in Course 5  66 C
Steve James average grade is: 73.8
Number of courses whose final grade is A+ : 1
Number of courses whose final grade is A : 1
Number of courses whose final grade is A- : 0
Number of courses whose final grade is B+ : 0
Number of courses whose final grade is B : 1
Number of courses whose final grade is B- : 0
Number of courses whose final grade is C+ : 0
Number of courses whose final grade is C : 1
Number of courses whose final grade is C- : 0
Number of courses whose final grade is D+ : 0
Number of courses whose final grade is D : 0
Number of courses whose final grade is D- : 0
Number of courses whose final grade is F+ : 0
Number of courses whose final grade is F : 1
Number of courses whose final grade is F- : 0
**********************************************

Related Solutions

Java Program Suppose a student was taking 5 different courses last semester. Write a program that...
Java Program Suppose a student was taking 5 different courses last semester. Write a program that (a) asks the student to input his/her name, student ID, marks for these 5 courses, (b) calculate the average, (c) determine the letter grade of each course. (d) record the number of courses whose final letter grade is A+, A, A-, .... , F+, F, F-. (e) Output the following information in a nice format: student name, student ID, listing of marks, the average,...
As a part-time student, you took three courses last semester. Write, run, and test a C++...
As a part-time student, you took three courses last semester. Write, run, and test a C++ program that calculates and displays the numerical grades, the equivalent letter grades and your grade point average (GPA) for the semester. Your program should prompt the user to enter the numerical grade and credit hours for each course. This information should then be displayed in a tabular format. A warning message should be printed if the GPA is less than 2.0 and a congratulatory...
Write a java program that prompt the user to insert last term’s courses and their individual...
Write a java program that prompt the user to insert last term’s courses and their individual mark and store them in an appropriate multidimensional array.
Write a Java program that sorts an array of “Student” in an aescending order of their...
Write a Java program that sorts an array of “Student” in an aescending order of their “last names”. The program should be able to apply (Insertion sort): Student [] studs = new Student[8]; s[0] = new Student("Saoud", "Mohamed", 3.61); s[1] = new Student("Abdelkader", "Farouk", 2.83); s[2] = new Student("Beshr" , "Alsharqawy", 1.99); s[3] = new Student("Nader", "Salah", 3.02); s[4] = new Student("Basem", "Hawary", 2.65); s[5] = new Student("Abdullah", "Babaker", 2.88); s[6] = new Student("Abdelaal", "Khairy", 3.13); s[7] = new Student("Mohamedain",...
Max is taking two courses this semester Math and Economics. She has 10 hours to study...
Max is taking two courses this semester Math and Economics. She has 10 hours to study and has a mid-term for each class coming up. Both tests are over 100 points. Suppose that if she goes to the Math or Econ tests without studying at all she will get a 0. For every hour that Max studies for the math mid-term her grade goes up by 8 points and for every hour she studies for econ mid-term, her grade goes...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Tracy is in her last semester of nursing school where she is taking a course in...
Tracy is in her last semester of nursing school where she is taking a course in which her class learns about the importance of evidence-based practice. Dr. Minturn, the nursing professor who teaches the course, has asked the students to write a paper about a mock research study of their choosing. The students are to pose a clinical question and then map how they would create a research study around the question. They are not to actually carry out the...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Objective: Write a program in java to give a student directions for whether they should report...
Objective: Write a program in java to give a student directions for whether they should report to school or learn online based on their response to several questions. Your program should model the HNA hybrid requirements of reporting to school for: Mondays, Thursdays: Last name A-K Tuesdays, Fridays: Last name L-Z Odd week Wednesday: A-K Even week Wednesday L-Z Ask the user the day of week, followed by their last name. In the case that the day of the week...
Alex is taking two courses; algebra and U.S. history. Student records indicate that the probability of...
Alex is taking two courses; algebra and U.S. history. Student records indicate that the probability of passing algebra is 0.33, that of failing U.S. history is 0.33, and that of passing at least one of the two courses is 0.85. Find the probability of the following. (a) Alex will pass history. (b) Alex will pass both courses. (c) Alex will fail both courses. (d) Alex will pass exactly one course.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT