CIS 120 Exam 2 Programming Question

Verified

Added on  2019/09/18

|1
|467
|165
Homework Assignment
AI Summary
This is a programming assignment for CIS 120, requiring students to create a Java program that calculates a student's average mark from an array of subject marks and then assigns a letter grade based on the average. The program includes a main method, a calculateAverage method, and a gradeCalculator method. Students are required to submit both the .java file and a .docx file containing their code.
Document Page
CIS 120 Exam 2 Programming Question
Create a new Project and Class called Exam2_YourName. Please write your name in the class name.
Your program will have a main method and two other methods called gradeCalculator and
calculateAverage. Submit all the .java file called Exam2_YourName. Also ,copy and paste your code
into a .docx file and upload the file as well. Please use the exam2 dropbox to submit your code.
Your main method does the following :
1) Create a 5-element array called subjectMarks that will carry numeric marks (double data type)
of a student in five different subjects. Each mark can be a real number such as 40.5, 35.6 etc.
Declare the array appropriately.
2) Fill the array with values: Prompt the user to enter the student’s mark in each subject, one by
one and use those values to fill the elements of the subjectMarks array one by one.
3) Call the calculateAverage method and pass on the subjectMarks array as a parameter. This
method will return the average mark of the student. Print out the average mark of the student
on the console with proper comments. Use any required variable (for example- name it
avgMark) to store the average mark value returned by the method.
4) Call the gradeCalculator method and pass on to this method as a parameter, the variable that
contains the average mark (avgMark as obtained in step 3). This method (gradeCalculator )
calculates the letter grade based on the student’s average and returns a String that will be the
letter grade of the student. Print out this letter grade into the console. You may use a variable
name letterGrade to hold the letter grade returned by the method.
Write the code for the calculateAverage method. The calculateAverage method has the following
features:
1) This method will take in as a parameter/argument the array containing marks of the student (as in
subjectMarks array).
2) This method returns a double value corresponding to the average marks of the student. You may
declare a double variable called avgMark that will contain the average marks.
3) This method calculates the average marks by taking one element of the array at a time, adding
them to find the total marks. You may use a variable called totalMark to hold the total mark. After
adding all the elements (,or marks), divide the total marks with the length of the array ( which gives
the number of subjects), to obtain the average marks. Return the average marks carried by the
variable avgMarks.
Anastasia Declin
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]