Question

In: Computer Science

I'm looking to calculate grades that allows me to enter a number of grades and allows...

I'm looking to calculate grades that allows me to enter a number of grades and allows me to also calculate the average using java script collections/array list. If possible, can someone lead me in the direction on how to go about doing this with some explanation. Thank you !!!

My code so far;

package com.company;

import java.util.*;
import java.util.ArrayList;

class Main {

    public static void main(String args[]) {

        Set names = new HashSet();
        names.add("Christopher");
        names.add("Pedro");
        names.add("James");
        names.add("Jess");
    }
}

Solutions

Expert Solution


import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;


public class Test {
  
//method to calculate the average of grades in ArrayList
static double calAverage(ArrayList<Integer> a)
{
int n =a.size();
  
int sum =0;//to store sum
for(int i=0;i<n;i++)//calculating sum of all grades
sum=sum+a.get(i);
  
//finding average
double av = sum/(n*(1.0));
return av;//returning average
}

public static void main(String argv[])
{
ArrayList<Integer> R = new ArrayList<Integer>();//creating array list with integer object
  
int n;//to store number of grades
//to read input
Scanner sc = new Scanner(System.in);
  
System.out.print("Enter number of grades you to enter:");
n = sc.nextInt();
  
//reading grades
System.out.println("Enter grades :");
for(int i=0;i<n;i++)
{
int k =sc.nextInt();
R.add(k);//adding to array list
  
}
  
//displaying output
System.out.println("The average of grades :"+calAverage(R));
}
}

output:

run:
Enter number of grades you to enter:5
Enter grades :
80
74
69
55
92
The average of grades :74.0
BUILD SUCCESSFUL (total time: 16 seconds)


Related Solutions

Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
Show: Create an application that allows the user to enter the number of calories and fat...
Show: Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *9 The percentage of...
Develop a rudimentary Java program that will allow anyone to enter any number of grades and...
Develop a rudimentary Java program that will allow anyone to enter any number of grades and then calculate grade point average. For reference, a grade point average is a weighted average of a set of grades based on the relative number of credits. For example, a 1 credit “A” (4.0) should count twice as much as a .5 credit “C” (3.0), and a 1.5 credit “A+”(4.33) should count three times as much as the “C” and 1.5 times as much...
I'm currently looking at this figure, but I'm not sure how to interpret it. If I'm...
I'm currently looking at this figure, but I'm not sure how to interpret it. If I'm not mistaken, the energy loss of the muon (This is a muon that penetrates copper) is on the y-axis. But does that just mean, that if my muon has energy of around 0.5 GeV, then it has a stopping power around 2 MeV cm2/g (Minimum ionization), which means it loses that amount of energy pr. cm2/g? To me that just seems a bit "linear"....
Write an application that allows a user to enter any number of student quiz scores, as...
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT