Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class Gradebook { // main method public static void main(String [] args) { Scanner input= new Scanner(System.in); // Create 2 String arrays


imageimageimage


import java.util.Scanner; public class Gradebook {

// main method public static void main(String [] args) { Scanner input= new Scanner(System.in); // Create 2 String arrays for stud ID and names String [] studID = {"G001", "G002", "G003", "G004", "G005"}; String [] studName = {"Mary", "Abby", "Joe", "Mark", "Julie"}; // Create 2 double arrays for grades double [] mGrade = new double[5]; double [] fGrade = new double[5]; // Enter grades System.out.printf("please enter midterm exam grade for %d students. ", mGrade.length); for(int i = 0; i < mGrade.length; i++){ System.out.print(studName[i] + ":"); mGrade[i] = input.nextDouble(); } System.out.printf("please enter final exam grade for %d students. ", fGrade.length); for(int i = 0; i < fGrade.length; i++){ System.out.print(studName[i] + ":"); fGrade[i] = input.nextDouble(); }

// Display the grade tablel // Table head and separating line System.out.println("|ttStud IDtt|ttStud Namestt|ttMidtermtt|ttFinaltt|"); System.out.println("-------------------------------------------------------------------------"); //Student records for (int i = 0; i < studID.length; i ++) { System.out.printf("|tt%-7stt|tt%-10stt|tt%7.1ftt|tt%5.1ftt| ", studID[i], studName[i], mGrade[i], fGrade[i]); } // Ending line and average System.out.println("-------------------------------------------------------------------------"); // Call the average method to get the averages System.out.printf("|ttAverage:ttttttttt|tt%7.1ftt|tt%5.1ftt| ", gradeAvg(mGrade), gradeAvg(fGrade)); } //average method public static double gradeAvg(double [] g){ double total = 0; for (int i = 0; i < g.length; i++){ total += g[i]; // total = total + g[i]; } return total / g.length; } }

Search with a student name to know the student total grade Make the search method first. . Input / parameter: the user provided name (String), the array for names (String []) Process: Use a FOR loop, to read each element in the name array and compare with the user provided name: if (name[i].equals (userInputName)) //or using equalsIgnoreCase() Output: When the above if condition is true, return the i value for the element index. If after you go through the entire name array and cannot find a matching name, after the loop block, return -1 (an invalid / meaningless value for the index number)

Step by Step Solution

3.50 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

java import javautilScanner public class GradeBookHW public static void mainString args Scanner input new ScannerSystemin Create 2 String arrays for s... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions

Question

1. Avoid listening to tattle tale stories about students.

Answered: 1 week ago

Question

How is the economic production quantity different from EOQ?

Answered: 1 week ago