Question

Java Question Method and 1 dimension arrays(20) YouTube ㄨ Electronics, Cars, Fashion, Co × Upload Assignment: Program xy 9 Program3.pdf eduardo C Secure https://blackboard.kean.edu/bbcswebdav/pid-736390-dt-content-rid-2804166 1/courses/18SP CPS 2231 06/Program3.pdf Concepts: Methods and one dimensional Arrays Point value: 45 points Write a Java Class that reads students grades and assigns grades based on the following grading curve .Grade is A if the score is greater than or equal to the highest score - 10 .Grade is B if the score is greater than or equal to the highest score -20 Grade is C if the score is greater than or equal to the highest score 30 Grade is D if the score is greater than or equal to the highest score 40 Grade is F otherwise So, for example, after all grades are entered, if the highest grade entered was a 92, then: A >= 82 B>= 72 .D52 F otherwise The program will do the following: Prompt the user for the number of grades to be entered. The grades will all be integers. .Read in the grades and store them in an array of the correct size. Call the method below (which you will create) to calculate and return the highest value in the Array public static int findMax(int[] theArray) .Call the method below (which you will create) to print a line for each grade in the format displayed in the sample output on next page public static void printGrades (int[] theArray, int highestGrade)

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

Please find my implementation.

import java.util.Scanner;

public class Grade {

  

   public static int findMax(int[] theArray) {

      

       int max = theArray[0];

       for(int i=1; i<theArray.length; i++)

           if(theArray[i] > max)

               max = theArray[i];

       return max;

   }

  

   public static void printGrades(int[] theArray, int higestGrade) {

      

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

          

           char ltr;

          

           if(theArray[i] >= Math.abs(higestGrade- 10))

               ltr = 'A';

           else if(theArray[i] >= Math.abs(higestGrade - 20))

               ltr = 'B';

           else if(theArray[i] >= Math.abs(higestGrade - 30))

               ltr = 'C';

           else if(theArray[i] >= Math.abs(higestGrade - 40))

               ltr = 'D';

           else

               ltr = 'F';

          

           System.out.println("Student "+i+" score is "+theArray[i]+" and grade is "+ltr);

       }

   }

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       System.out.println("Enter the number of grades");

       int n = sc.nextInt();

      

       // creating an array

       int[] grades = new int[n];

      

      

       // reading grades

       System.out.println("Enter 4 grades separated by space");

      

       for(int i=0; i<n; i++)

           grades[i] = sc.nextInt();

      

       sc.close();

      

       int max = findMax(grades);

      

       //System.out.println(max);

      

       printGrades(grades, max);

   }

}

/*

Sample run:

Enter the number of grades

4

Enter 4 grades separated by space

40 55 70 58

Student 0 score is 40 and grade is C

Student 1 score is 55 and grade is B

Student 2 score is 70 and grade is A

Student 3 score is 58 and grade is B

*/

タR Markers Properties悦Servers?Data Source Explorer S snippets R Problems Console X <terminated> Grade (1) [Java Application]

Add a comment
Know the answer?
Add Answer to:
Java Question Method and 1 dimension arrays (20) YouTube ㄨ Electronics, Cars, Fashion, Co × Upload...
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
  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • In Java Main method Your main program will prompt the user for a test name and...

    In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • in java Part 1 In this section, we relook at the main method by examining passing...

    in java Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....

  • 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...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • C# Arrays pne and Look at the code below Notice that the program has one class...

    C# Arrays pne and Look at the code below Notice that the program has one class called Tournament. . It defines an integer array called scores to hold all the scores in the tournament .The constructor for the class then actually creates the array of the required size. class Tournament int[ ] scores; const int MAX = 6; // define scores as an integer array // set a constant size public static void Main() //program starts executing here Tournament myTournament...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

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