Question

Need code written for a java eclipse program that will follow the skeleton code.

Exams and assignments are weighted
You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/

Your task: 1. Import/Copy-paste GradeCompute.java into Eclipse. 2. Read the skeleton code carefully and understand the functi

import java.util.Scanner ; This class computes a lettergrade for a user Takes user input of scores in all worksheets, assigne

- ASSIGNMENTS - // Inpot number of assignments System.out.print(Enter number of assignments: ); int nussignmnt - stdin.next

I Caleulate grade String grade computeGrade(wksheet ScoresArr, assignment Scores Arr,exanScoresArr, vksheet Total, assignmnt

You must do this everytime user enters an invalid value 4. When user inputs a valid value, store it in the scores[] array .@p

YOU NEED TO MODIFY THIS METHOD . This method is used to take user input and fill the array created in the main method that st

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/****************************************ComputeGrade.java*********************************/

import java.util.Scanner;

public class ComputeGrade {

   public static void main(String[] args) {

       final int NUM_EXAMS = 3;
       final int MAX_SCORE_EXAM = 100;

       Scanner stdin = new Scanner(System.in);

       System.out.print("Enter number of worksheets: ");
       int numWkSheet = stdin.nextInt();

       System.out.print("Enter MAX possible score for each worksheet: ");
       int maxScoreOfEachWksheet = stdin.nextInt();

       int wksheetTotal = numWkSheet * maxScoreOfEachWksheet;

       System.out.println("Total points on worksheets: " + wksheetTotal);

       int[] wksheetScoresArr = new int[numWkSheet];

       System.out.print("Enter number of assignments: ");
       int numAssignment = stdin.nextInt();

       System.out.print("Enter max possible score for each assignment: ");

       int maxScoresOfEachAssignment = stdin.nextInt();

       int assignmentTotal = numAssignment * maxScoreOfEachWksheet;

       int[] assignmentScoresArr = new int[numAssignment];

       int examTotal = NUM_EXAMS * MAX_SCORE_EXAM;

       System.out.println("Total points on exams: " + examTotal);

       int[] examScoresArr = new int[NUM_EXAMS];

       readWkSheets(wksheetScoresArr, maxScoreOfEachWksheet, stdin);

       System.out.print("Score on worksheets: ");
       printArray(wksheetScoresArr);
       System.out.println();

       readAssignments(assignmentScoresArr, maxScoresOfEachAssignment, stdin);

       System.out.print("Score on Assignments: ");
       printArray(assignmentScoresArr);
       System.out.println();
       readExams(examScoresArr, MAX_SCORE_EXAM, stdin);

       System.out.print("Score on exams: ");

       printArray(examScoresArr);

       System.out.println();
       String grade = computeGrade(wksheetScoresArr, assignmentScoresArr, examScoresArr, wksheetTotal, assignmentTotal,
               examTotal);

       System.out.println("Grade is " + grade);

       stdin.close();
   }

   public static int computeSum(int[] array) {

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

           total += array[i];
       }

       return total;
   }

   public static void printArray(int[] array) {

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

           System.out.print(array[i] + " ");
       }
   }

   public static void readWkSheets(int[] scores, int maxScore, Scanner in) {

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

           System.out.print("Enter score in worksheet " + (i + 1) + ": ");
           scores[i] = in.nextInt();
           while (scores[i] > maxScore) {

               System.out.println("You must enter valid score!");
               System.out.print("Enter valid score: ");
               scores[i] = in.nextInt();
           }
       }
   }

   public static void readAssignments(int[] scores, int maxScore, Scanner in) {

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

           System.out.print("Enter score in assignment " + (i + 1) + ": ");
           scores[i] = in.nextInt();
           while (scores[i] > maxScore) {

               System.out.println("You must enter valid score!");
               System.out.print("Enter valid score: ");
               scores[i] = in.nextInt();
           }
       }

   }

   public static void readExams(int[] scores, int maxScore, Scanner in) {

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

           System.out.print("Enter score in exam " + (i + 1) + ": ");
           scores[i] = in.nextInt();
           while (scores[i] > maxScore) {

               System.out.println("You must enter valid score!");
               System.out.print("Enter valid score: ");
               scores[i] = in.nextInt();
           }
       }
   }

   public static String computeGrade(int[] wkSheetArr, int[] assignmentArr, int[] examArr, int wkSheetTot,
           int assignmentTot, int examTot) {

       String grade = "";
       wkSheetTot = computeSum(wkSheetArr);
       assignmentTot = computeSum(assignmentArr);

       double actualScore = ((double) (wkSheetTot + assignmentTot)) * .4 + ((double) examArr[0]) * .15
               + ((double) examArr[1]) * .20 + ((double) examArr[2]) * .25;

       if (actualScore >= 90) {

           grade = "A";
       } else if (actualScore >= 80 && actualScore < 90) {

           grade = "B";
       } else if (actualScore >= 70 && actualScore < 80) {

           grade = "C";
       } else if (actualScore >= 60 && actualScore < 70) {

           grade = "D";
       } else {

           grade = "F";
       }
       return grade;

   }

}

/*************************output**************************/

Enter number of worksheets: 3
Enter MAX possible score for each worksheet: 50
Total points on worksheets: 150
Enter number of assignments: 3
Enter max possible score for each assignment: 50
Total points on exams: 300
Enter score in worksheet 1: 55
You must enter valid score!
Enter valid score: 45
Enter score in worksheet 2: 48
Enter score in worksheet 3: 30
Score on worksheets: 45 48 30
Enter score in assignment 1: 76
You must enter valid score!
Enter valid score: 75
You must enter valid score!
Enter valid score: 46
Enter score in assignment 2: 48
Enter score in assignment 3: 34
Score on Assignments: 46 48 34
Enter score in exam 1: 109
You must enter valid score!
Enter valid score: 98
Enter score in exam 2: 90
Enter score in exam 3: 87
Score on exams: 98 90 87
Grade is A
2 Console X Search <terminated > ComputeGrade [Java Application] C:\Program Files\Java jre 1.8 Enter number of worksheets: 3

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Answer #2

Screenshot of the Code:

import java.util.Scanner; /** * This class computes a lettergrade for a user. * Takes user input of scores in all worksheets,// create array to store each wksheet score int [] wksheetScoresArr = new int [numwk sheet]; /** ASSIGNMENTS **/ // Input numprintArray(assignmentScoresArr); // Method to input exam scores from user readExams (examScoresArr, MAX_SCORE_EXAM, stdin); /* YOU NEED TO MODIFY THIS METHOD * This method is used to print an array. * It takes any type of array as input and does the// Check for the valid score. while(scores[iter] > maxScore) // Display the message. System.out.println(Score for worksheet// Check for the valid score. while(Scores[iter] > maxScore) System.out.println(Score for assignment cannot be greater than// Check for the valid score. while( scores[iter] > maxScore) System.out.println(Score for exam cannot be greater than +maxdouble el = (double) (examArr[@]*0.15/100); double e2 = (double) (examArr[1]*0.2/100); double e3 = (double) (examArr[2]*0.25/

Sample Output:

Problems Javadoc Declaration Console 3 <terminated > GradeCompute [Java Application) C:\Program Files\Java Enter number of wo

Code to Copy:

import java.util.Scanner;
/**
* This class computes a lettergrade for a user.
* Takes user input of scores in all worksheets, assignemnts and exams during a
semester.
* Outputs a letter grade based on a scale.
* @author spal
*
*/
public class GradeCompute {
  
/**
* This Main method calls on several other methods to compute lettergrade for
a user.
* Instruction for students:
* 1. DO NOT MODIFY THIS METHOD. It should be exactly the same as provided.
* 2. READ this main method carefully, then write code for the associated
methods.
* @param args
*/

public static void main(String[] args) {
  
/** DO NOT MODIFY THE CODE IN THIS METHOD **/

// The number of exams and its total score is fixed.
final int NUM_EXAMS = 3;
final int MAX_SCORE_EXAM = 100;

// Create scanner to take input from user
Scanner stdin = new Scanner (System.in);

/** WORKSHEETS **/

// Input number of worksheets
System.out.print("Enter number of worksheets: ");

int numWksheet = stdin.nextInt();

// Input total points for a worksheet. All worksheets
//will have the same max value.
System.out.print("Enter max possible score for each worksheet: ");

int maxScoreOfEachWksheet = stdin.nextInt();

// Calculate total points for all worksheets and print it out
int wksheetTotal = numWksheet*maxScoreOfEachWksheet;

System.out.println ("Total points on Worksheets: "+ wksheetTotal);

// create array to store each wksheet score
int [] wksheetScoresArr = new int [numWksheet];

/** ASSIGNMENTS **/

// Input number of assignments
System.out.print("Enter number of assignments: ");

int numAssignmnt = stdin.nextInt();

// Input total points for an assignment.
//All assignments will have the same max value.
System.out.print("Enter max possible score for each assignment: ");

int maxScoreOfEachAssignmnt = stdin.nextInt();

// Calculate total points for all assignments and print it out
int assignmntTotal = numAssignmnt*maxScoreOfEachAssignmnt;

System.out.println ("Total points on Assignments: "+ assignmntTotal);

// create array to store each assignment score
int [] assignmentScoresArr = new int [numAssignmnt];

/** EXAMS **/

// calculate total points for all exams
int examTotal = NUM_EXAMS*MAX_SCORE_EXAM;

System.out.println ("Total points on Exams: "+ examTotal);

// array to store each exam score
int [] examScoresArr = new int[NUM_EXAMS];

/** Read values into arrays that store scores **/

// Method to input worksheet scores from user
readWkSheets(wksheetScoresArr, maxScoreOfEachWksheet, stdin);

// Print worksheet scores from array
System.out.print("Score on worksheets: ");

// Method to print the worksheet score array
printArray(wksheetScoresArr);

// Method to input assignment scores from user
readAssignments(assignmentScoresArr, maxScoreOfEachAssignmnt, stdin);

// Print assignment scores from array
System.out.print("Score on assignments: ");

printArray(assignmentScoresArr);

// Method to input exam scores from user
readExams(examScoresArr, MAX_SCORE_EXAM, stdin);

// Print assignment scores from array
System.out.print("Score on exams: ");

printArray(examScoresArr);

// Calculate grade
String grade =
computeGrade(wksheetScoresArr,assignmentScoresArr,examScoresArr,
                          wksheetTotal,assignmntTotal,examTotal);

// Print grade
System.out.println("Grade is "+grade);

stdin.close();

}// end main
  
/**
* YOU NEED TO MODIFY THIS METHOD
* This method computes and returns sum of all values in an integer array.
* It takes an int[] array as input and does the following,
* 1. computes the sum of all values stored in the array.
* 2. returns the sum
* @param array - integer array[]
* @return sum of all values in the int array[]
*/
public static int computeSum(int[] array) {
     
   // Define the variable.
int sum= 0;

// Iterate through the array
// Evaluate the sum.
for(int i=0;i<array.length;i++)
sum += array[i];
// System.out.println(sum);
// Return the sum.
return sum;
}

/**
* YOU NEED TO MODIFY THIS METHOD
* This method is used to print an array.
* It takes any type of array as input and does the following,
* 1. prints all the values in the same line, with one space between
them
* Example output on console: 5 4 3 2 1
* @param array - int[] array
*/
public static void printArray (int[] array) {
     
   // Iterate through the array
   // Print the sum.
for(int iter=0;iter<array.length;iter++)
System.out.print(array[iter]+" ");
System.out.println();
}

/**
* YOU NEED TO MODIFY THIS METHOD
* This method is used to take user input and fill the array created in the
main method
* that stores worksheet scores.
* You must write code to do the following,
* 1. Ask user to input obtained score for all the worksheets
* 2. Check if user has entered a valid value (<= maxScore);
* example: say the worksheet is worth 20 points total, you
must check
* that the user input score <= 20
* 3. If the user inputs a value > maxScore, it is an invalid value
* DO NOT STORE AN INVALID VALUE IN THE ARRAY. Instead, ask
the user to enter a valid value.
* You must do this everytime user enters an invalid value
* 4. When user inputs a valid value, store it in the scores[] array
*
* @param scores - array that stores points obtained on each wksheet
* @param maxScore - max possible points for a worksheet (total points in one
worksheet)
* @param in - scanner object to input scores
*/
public static void readWkSheets(int [] scores, int maxScore, Scanner in) {
     
   // Display the message.
System.out.println("Input the score for "+scores.length+" worksheets : ");

// Iterate through the length of scores array.
for(int iter=0;iter<scores.length;iter++)
{
   // Prompt the user for input.
System.out.print("Worksheet "+(iter+1)+" : ");
scores[iter] = in.nextInt();
  
// Check for the valid score.
while(scores[iter] > maxScore)
{   
   // Display the message.
System.out.println("Score for worksheet cannot be greater than "+maxScore);

//Prompt the user to input again.
System.out.print("Worksheet "+(iter+1)+" : ");
scores[iter] = in.nextInt();
}
}
}// end readWkSheets

/**
* YOU NEED TO MODIFY THIS METHOD
* This method is used to take user input and fill the array created in the
main method
* that stores assignment scores.
* You must write code to do the following,
* 1. Ask user to input obtained score for all the assignment
* 2. Check if user has entered a valid value (<= maxScore);
* example: say the assignment is worth 50 points total, you
must check
* that the user input score <= 50
* 3. If the user inputs a value > maxScore, it is an invalid value
* DO NOT STORE AN INVALID VALUE IN THE ARRAY. Instead, ask
the user to enter a valid value.
* You must do this everytime user enters an invalid value
* 4. When user inputs a valid value, store it in the scores[] array
*
* @param scores - integer array that stores scores obtained in each
assignment
* @param maxScore - max possible score for an assignment
* @param in - scanner object to input scores
*/
public static void readAssignments(int[] scores, int maxScore, Scanner in) {
     
   // Display the message.
System.out.println("Input the score for "+scores.length+" assignments : ");

// Iterate through the scores.
for(int iter=0;iter<scores.length;iter++)
{   
   // Prompt the user to enter the assignment score.
System.out.print("Assignment "+(iter+1)+" : ");
scores[iter] = in.nextInt();

// Check for the valid score.
while(scores[iter] > maxScore)
{
System.out.println("Score for assignment cannot be greater than "+maxScore);
System.out.print("Assignment "+(iter+1)+" : ");
scores[iter] = in.nextInt();
  
}
}
}// end readAssignments

/**
* YOU NEED TO MODIFY THIS METHOD
* This method is used to take user input and fill the array created in the
main method
* that stores exam scores.
* You must write code to do the following,
* 1. Ask user to input obtained score for all the exam
* 2. Check if user has entered a valid value (<= maxScore);
* example: say the assignment is worth 100 points total, you
must check
* that the user input score <= 100
* 3. If the user inputs a value > maxScore, it is an invalid value
* DO NOT STORE AN INVALID VALUE IN THE ARRAY. Instead, ask
the user to enter a valid value.
* You must do this everytime user enters an invalid value
* 4. When user inputs a valid value, store it in the scores[] array
*
* @param scores - integer array that stores scores obtained in each exam
* @param maxScore - max possible score for an exam
* @param in - scanner object to input scores
*/
public static void readExams(int[] scores, int maxScore, Scanner in) {
     
   // Display the message.
System.out.println("Input the score for "+scores.length+" exams : ");

// Iterate through the scores.
for(int iter=0;iter<scores.length;iter++)
{   
   // Prompt the user to enter the exam score.
System.out.print("Exam "+(iter+1)+" : ");
scores[iter] = in.nextInt();

// Check for the valid score.
while(scores[iter] > maxScore)
{
System.out.println("Score for exam cannot be greater than "+maxScore);
System.out.print("Exam "+(iter+1)+" : ");
scores[iter] = in.nextInt();
}
}
}// end readExams

/**
* YOU NEED TO MODIFY THIS METHOD
* This method calculates a letter grade from score obtained by student/user
* @param wksheetArr - array to store worksheet scores
* @param assignmentArr - array to store assignment scores
* @param examArr - array to score exam scores
* @param wksheetTot - sum of total possible points for all worksheets
* @param assignmntTot -sum of total possible points for all assignments
* @param examTot - sum of total possible points for all exams
* @return - a letter grade
*/
public static String computeGrade(int[] wksheetArr,int[] assignmentArr,
       int[] examArr, int wksheetTot,int assignmntTot,int examTot) {
     
   // Compute the work sheet total.
int wrkSheetSum = computeSum(wksheetArr);
  
// Compute the assignment total.
int assignmentSum = computeSum(assignmentArr);

// Check if the student fails.
// Return F if student fails.
double t1 = (wrkSheetSum + assignmentSum);
double t2 = (wksheetTot+assignmntTot);
double wkas = t1/t2;

if( wkas< 0.5)
return "F";

// Compute the exam total.
int examTotal = computeSum(examArr);

double es = (double)examTotal/300;

// Check if the student fails.
// Return F if student fails.
if(es < (0.50))
return "F";
  
double e1 = (double)(examArr[0]*0.15/100);
double e2 = (double)(examArr[1]*0.2/100);
double e3 = (double)(examArr[2]*0.25/100);
double t3 = ((t1)/40)*0.4;

// Compute the overall score.
double s = t3 + e1 + e2 + e3;

s= s*100;
  
// Compute the grade.
// Return the grade.
if(s >= 90)
return "A";
else if(s >= 80)
return "B";
else if(s >= 70)
return "C";
else if(s >= 60)
return "D";
else
return "F";
}
}// end class GradeCompute

Add a comment
Know the answer?
Add Answer to:
Need code written for a java eclipse program that will follow the skeleton code. Exams and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • this code is not working for me.. if enter 100 it is not showing the grades...

    this code is not working for me.. if enter 100 it is not showing the grades insted asking for score again.. #Python program that prompts user to enter the valuesof grddes . Then calculate the total scores , #then find average of total score. Then find the letter grade of the average score. Display the #results on python console. #grades.py def main(): #declare a list to store grade values grades=[] repeat=True #Set variables to zero total=0 counter=0 average=0 gradeLetter='' #Repeat...

  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Your code should contain appropriate validations and must focus on code optimization. Briefly, explain (150-200 words)...

    Your code should contain appropriate validations and must focus on code optimization. Briefly, explain (150-200 words) the logic of the program and how the code can be   optimized. Modify the code to repeat the program until the user enters “no”. (*I need the logical write out on how the program behaves when there is an input from the user. (I don't need the //comments). import java.util.Scanner; public class Q2 {     public static void main(String[] args)     {         Scanner...

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • Given java code is below, please use it! import java.util.Scanner; public class LA2a {      ...

    Given java code is below, please use it! import java.util.Scanner; public class LA2a {       /**    * Number of digits in a valid value sequence    */    public static final int SEQ_DIGITS = 10;       /**    * Error for an invalid sequence    * (not correct number of characters    * or not made only of digits)    */    public static final String ERR_SEQ = "Invalid sequence";       /**    * Error for...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • The following code skeleton contains a number of uncompleted methods. With a partner, work to complete...

    The following code skeleton contains a number of uncompleted methods. With a partner, work to complete the method implementations so that the main method runs correctly: /** * DESCRIPTION OF PROGRAM HERE * @author YOUR NAME HERE * @author PARTNER NAME HERE * @version DATE HERE * */ import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class ArrayExercises { /** * Given a random number generator and a length, create a new array of that * length and fill it from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT