Question

[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:

A – when score is >= best score -10

B – when score is >= best score -20

C – when score is >= best score -30

D – when score is >= best score -40

F – Otherwise.

•Calculate and display the average of test scores.

•Use any sorting algorithm such as Bubble Sort or Selection Sort (DO NOT use pre-defined sort methods)

to sort the data by name. Make sure the test scores are also sorted,

accordingly.

•Allow the user to enter a student name and displaythe corresponding test score. Issue

an error message if the name is not in the list of students. Use a loop to allow the user to

enter as many names as the user wishes to enter. Use the sentinel value “done” to exit the

search process.

//

Minimal number of methods to define for this program:

1.A method to return a valid number of students

2.A method to return the name and test scores of the students

3.A method to return the best score

4.A method to display the letter grade along with the score information

5.A method to sort the data

6.A method to display the array of names and test scores

7.A method to search for a given name. This method should return the test score for the

given name or -1 if the name is not found. You can use the returned value in the main

method to display the score or to display an error message.

//

SAMPLE RUN:

Number of students:

-1

Error – try gain

Number of students:

0 Error – try gain

Number of students: 4

Assume the entered values are: bill, joe, mary, bob

Assume the entered values are: 40 55 70 58   <<<< Note the best score is calculated to be 70

*** Grade Report ***

bill scored 40, grade is: C

joe scored 55, grade is: B

mary scored 70, grade is: A

bob scored 58, grade is: B

Average = 55.75

*** The sorted List ***

bill 40

bob58

joe55

mary   70

Enter a student’s name: joe

joe received a score of 55

Enter a student’s name: nancy

nancy is not a student

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

import java.util.Scanner;
public class JavaExample {

    public static void main(String[] args) {
        System.out.println("Enter number of students: ");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        /* Declaring array of n elements, the value
         * of n is provided by the user
         */
        double[] namesofStudents = new double[n];
        double total = 0;

        for(int i=0; i<namesofStudents.length; i++){
           System.out.print("Enter name of the student "+(i+1)+": ");
           namesofStudents[i] = scanner.nextDouble();
        }
        scanner.close();
        for(int i=0; i<arr.length; i++){
           total = total + arr[i];
        }


      
        double average = total / arr.length;
      
        System.out.format("The average is: %.3f", average);
    }
}

program takes the input for number of friends, then stores each name in the array and then display them one by one from array.

    import java.util.Scanner;
    public class FriendsName {
   
   
       public static void main(String[] args){
           Scanner scan = new Scanner(System.in);
   
           //Decide the number of students
           System.out.print("Enter how many Students: ");
           int numOfStudents = Integer.parseInt(scan.nextLine());
   
           if(numOfStudents > 0){
       //Create a arrays to store the names and marks of the Students
           String arrayOfNames[] = new String[numOfStudents];
       double[] arrayofMarks = new double[numOfStudents];

           for (int i = 0; i < numOfStudents; i++) {
               System.out.print("Enter the name of Student " + (i+1) + " : ");
                    arrayOfNames[i] = scan.nextLine();
           System.out.print("Enter the Student " + (i+1) + " marks : ");
           arrayOfMarks[i] = scan.nextLine();
           }
       //Find Best value
       int bestValue = 0
       for(int i = 0; i < arrayOfMarks.length;i++)
       {  

           if(arrayOfMarks[i] > bestValue)
           {
               bestValue = arrayOfMarks[i];
              
           }
       }
             
       System.out.print("Best Value is :" + bestValue);
       System.out.print("\n ****Grade Report**** \n ");
           //Now Display Students names and Grades
           for (int i = 0; i < arrayOfMarks.length; i++) {
           int flag=0;
           flag = bestValue - arrayOfMarks[i];
           if( flag <= 10){
               System.out.print(arrayOfNames[i] + " scored "+arrayOfMarks[i]+", Grade is: A");
           }else if( flag > 10 && flag <= 20){
               System.out.print(arrayOfNames[i] + " scored "+arrayOfMarks[i]+", Grade is: B");
           }else if( flag > 20 && flag <=30){
               System.out.print(arrayOfNames[i] + " scored "+arrayOfMarks[i]+", Grade is: C");
           }else if( flag > 30 && flag <= 40){
               System.out.print(arrayOfNames[i] + " scored "+arrayOfMarks[i]+", Grade is: D");
           }else {
               System.out.print(arrayOfNames[i] + " scored "+arrayOfMarks[i]+", Grade is: F");
           }
              
           }
          
       int average = 0;
       for(int i = 0; i < arrayOfMarks.length;i++)
       {  
           average = average + arrayOfMarks[i];
          
        }
       System.out.print("\n Average Score is " + average / numOfStudents);
   
           } else { System.out.print("Error – try gain "); }
   
       }
   
    }


Output:

Enter how many Students: 4
Enter the name of Student 1 : Joe
Enter the Student 1 marks : 40
Enter the name of Student 2 : Jolly
Enter the Student 2 marks : 50
Enter the name of Student 3 : Josef
Enter the Student 3 marks : 90
Enter the name of Student 4 : Jonny
Enter the Student 4 marks : 80


Best Value is : 90
****Grade Report****
Joe scored 40 , Grade is : F
Jolly scored 50 , Grade is : D
Josef scored 90 , Grade is : A
Jonny scored 80 , Grade is : A

Add a comment
Know the answer?
Add Answer to:
[JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays 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
  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • in C++ Create a program that will calculate a student’s grade average of 5 test scores...

    in C++ Create a program that will calculate a student’s grade average of 5 test scores and assign a letter grade for a student. The program should use a class to store the student’s data including the student’s name and score on each of 5 tests. The program should include member functions to 1) get the student’s test scores, 2) calculate the average of the test scores, and 3) display the results as follows: Test scores for Mary: 100 90...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • Create a C++ program to calculate grades as well as descriptive statistics for a set of...

    Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name      Test Score    ...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Score Letter Grade...

  • ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public...

    ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public static void Main (string[] args)        {            int test1,test2,test3;            double average,average2;            char letterGrade;            Console.WriteLine("Enter test score1");            test1=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score2");            test2=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score3");            test3=Convert.ToInt32(Console.ReadLine());            average=(test1+test2+test3)/3.0;            average=(int)(average+0.5);           ...

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