Question

In: Computer Science

Write a java code snippet that allows a teacher to track her students’ grades. Use a...

Write a java code snippet that allows a teacher to track her students’ grades. Use a loop to prompt the user for each student’s name and the grade they received. Add these values to two separate parallel ArrayLists. Use a sentinel to stop. Output a table listing each of the student’s names in one column and their associated grades in the second column.

Solutions

Expert Solution

Here I use two separate List for store name and grade.

names is use for store name.

grades is use for store grade.

For creating list in java

import java.util.List;

List<String> names = new ArrayList<String>(); //use for store name 
List<String> grades = new ArrayList<String>();//use for store grade 

Here string is a type of list.

Printf() is use for formatting the output in table form.

code:

import java.util.*;



public class studentGrades{
    
    public static void main(String[] args) {
        
        String f = "y"; //Flag for next Entry 
        
        Scanner sc = new Scanner(System.in);//use for taking input
        
        List<String> names = new ArrayList<String>(); //use for store name 
        List<String> grades = new ArrayList<String>();//use for store grade 
        
        while(f.equals("y")){//check condition for continue
            String name,grade;
            
            System.out.print("\nEnter Student name: ");
            //taking name from user
            name = sc.next();
            System.out.print("Enter Student grade: ");
            //taking grade from user
            grade = sc.next();
            
            //add name into list
            names.add(name);
            
            //add grade into list
            grades.add(grade);
            
            //ask user for continue enter name and grade or not
            System.out.print("\nAre you want to continue?(y/n): ");
            f = sc.next();
        }
        
        //formating table 
        System.out.println("\n-------------------------------------");
        System.out.printf("%10s %20s", "NAME", "GRADE");
        System.out.println();
        System.out.println("-------------------------------------");
        
        for(int i = 0; i < names.size();i++){
            //print name and grade from the list
            System.out.printf("%10s %20s\n", names.get(i), grades.get(i));
        }
    }
    
}

Output:

I hope this solution will help you.

If you have any doubts about this, then do comment below.

Do you feel it is helpful to you?

Then please up vote me.  

Thank You :)


Related Solutions

Code in java, A class allows students to drop their lowest of 7 quiz grades at...
Code in java, A class allows students to drop their lowest of 7 quiz grades at the end of the semester. Prompt the user for these values and add them to an array of integer type. Sort the array using the sort method from the standard Java library. Output the student’s average with the lowest score dropped
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that...
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that generates a sequence of 20 random die tosses in an array and that prints the die values, marking the runs by including them in parentheses, like this: 1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 (3 3) Use the following pseudocode: inRun = false for each valid index i in the array If inRun...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then prints the following output: a. every element (on a single line) b. every element at an even index (on a single line) c. every even element (on a single line) d. all elements in reverse order (on a single line) e. only the first and last elements (on a single line)
(JAVA) A class allows students to drop their lowest of 7 quiz grades at the end...
(JAVA) A class allows students to drop their lowest of 7 quiz grades at the end of the semester. Prompt the user for these values and add them to an array of integer type. Sort the array using the sort method from the standard Java library. Output the student’s average with the lowest score dropped.
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Using JAVA 2. A run is a sequence of adjacent repeated values. Write a code snippet...
Using JAVA 2. A run is a sequence of adjacent repeated values. Write a code snippet that generates a sequence of 20 random die tosses in an array and that prints the die values, marking the runs by including them in parentheses, like this: 1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 (3 3) Use the following pseudocode: inRun = false for each valid index i in the array If...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
In java Q2. Write a program that reads grades of type double of eight students that...
In java Q2. Write a program that reads grades of type double of eight students that the user provides. The grades lie between 0 and 10. These grades should be written to a binary file and read from it. The program outputs the highest and lowest grades achieved by students on the screen. The file contains nothing but numbers of type double written to the file with writeDouble.
A teacher hypothesizes that the final grades in her class (N = 54) are distributed as...
A teacher hypothesizes that the final grades in her class (N = 54) are distributed as 10% A's, 23% B's, 45% C's, 14% D's, and 8% F's. At the end of the semester, she has the following grades: A B C D F 6 14 22 8 4 Considering the statement above, what are the expected frequencies for grades A and F respectively?
An anatomy teacher hypothesizes that the final grades in her class are distributed as 10% A's,...
An anatomy teacher hypothesizes that the final grades in her class are distributed as 10% A's, 23% B's, 45% C's, 14% D's, and 8% F's. At the end of the semester, she has the following grades. A 12B 20C 25D 13F 5 Test her claim at 1% significance level.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT