You will create the pseudo-code and Java Script program which will prompt the us
ID: 3859332 • Letter: Y
Question
You will create the pseudo-code and Java Script program which will prompt the user for four (4) numeric grades. Requirements: • Use an array to store the grades. • Use a looping structure to populate the array. • Calculate the numeric average based upon the 4 equally-weighted numeric grades. • Display each of the 4 numeric grades from the array on the screen using a looping structure. • Display the numeric average. • Create a function that will convert the numeric average to a letter grade average using the grading scale: o A = 90 to100 o B = 80 to 89 o C = 70 to 79 o D = 60 to 69 o F = 0 to 59 • The function must return the value of the letter grade average. • Display the letter grade average. • Include comments o At the top of the program to include: Your name Class name and number Instructor name Overall Description of program o Comment each section of code Describe what the section accomplishes
Explanation / Answer
Psuedocode:
//Function to get letter_grade
letter_grade(Numeric):
if (Numeric >= 90 and Numeric <= 100):
return 'A'
elseif (Numeric >= 80 and Numeric <= 89):
return 'B'
elseif (Numeric >= 70 and Numeric <= 79):
return 'C'
elseif (Numeric >= 60 and Numeric <= 69):
return 'D'
else:
return 'F'
grades = [] //initialise grades array
summ = 0;
for i in range(1,4):
print "Enter grade of ith student"
inp = input();
grades[i] = inp
summ = summ + inp
avr = summ/4;
for i in range(1,4):
print "Numeric grade of ith student is ", grades[i]
print "Average grade = ", avr
Java code: Create a file named Final.java, and paste given code into it.(Note the file name must be Final.java).
import java.util.Scanner;
public class Final {
public static String Letter_grade(int Numeric)
{
if(Numeric >= 90 && Numeric <= 100)
{
return "A";
}
else if (Numeric >= 80 && Numeric <= 89)
{
return "B";
}
else if (Numeric >= 70 && Numeric <= 79)
{
return "C";
}
else if (Numeric >= 60 && Numeric <= 69)
{
return "D";
}
else
{
return "F";
}
}
public static void main(String[] args) {
int a1,a2;
Scanner scanner = new Scanner(System.in);
int grades[] = new int[4];
int summ = 0;
for(int i = 1; i<=4; i++)
{
System.out.println("Enter numeric grade of student" + i );
grades[i-1] = scanner.nextInt();
summ = summ + grades[i-1];
}
int avr = summ/4;
System.out.println("Average numeric grade = " + avr);
for(int i = 1; i<=4; i++)
{
System.out.println("Numeric grade of student " + i + " = " + grades[i-1]);
String g = Letter_grade(grades[i-1]);
System.out.println("Letter grade of student " + i + " = " + g );
}
}
}
Sample Output:
Enter numeric grade of student1
95
Enter numeric grade of student2
85
Enter numeric grade of student3
75
Enter numeric grade of student4
55
Average numeric grade = 77
Numeric grade of student 1 = 95
Letter grade of student 1 = A
Numeric grade of student 2 = 85
Letter grade of student 2 = B
Numeric grade of student 3 = 75
Letter grade of student 3 = C
Numeric grade of student 4 = 55
Letter grade of student 4 = F
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.