Question

In: Computer Science

in java Jimmy wants to store course grades and corresponding student last names using two parallel...

in java Jimmy wants to store course grades and corresponding student last names
using two parallel arraylists (Double and String).

She also wants to identify the average of all the grades.

Use a while loop.
Prompt the user for each grade and use -1 as the sentinel.

Ask for the student name if -1 has not been entered for the grade.

Be sure to output the average of the grades. (**Hint: You will need to figure out the sum first)

Use a for loop to output the name and grade for each student to look like this:

Grade: 99 Name: Billy

Grade: 98 Name: Sandy

etc..

Solutions

Expert Solution

  • Below is the detailed implementation of the above problem in JAVA with code and output shown.
  • For better understanding please read the comments mentioned in the code.
  • In the code below input is taken until grade is entered as -1(using a while loop) then we print all the names and grades(using a for loop) and at last prints the average, for details check the code below.
  • CODE:

import java.util.*;
public class Solution{
//driver function
public static void main(String []args){
//scanner object
Scanner sc = new Scanner(System.in);
//array list to store grades
ArrayList<Double> grades= new ArrayList<Double>();
//array list to store names
ArrayList<String> names= new ArrayList<String>();
//to store total sum of grades
double sum=0;
//to count total inputs
int tot=0;
//loop until user enters -1
while(true){
//ask user to input grade
System.out.print("Enter grade: ");
//input grade
double grade=sc.nextDouble();
sc.nextLine();
//if grade is -1 then end
if(grade==-1){
break;
}
//otherwise
else{
//increment total count
tot++;
//add it to sum
sum+=grade;
//add to array list
grades.add(grade);
//ask user to enter name
System.out.print("Enter name: ");
//input name
String name=sc.nextLine();
//add it to list
names.add(name);
}
}
//calculate average
double avg=sum/tot;
//for each entry, print name and grade
for(int i=0;i<tot;i++){
System.out.println("Grade: "+grades.get(i)+" Name: "+names.get(i));
}
//print average
System.out.println("Average of all grades is: "+avg);
}
}

  • INPUT/OUTPUT:

Enter grade: 99
Enter name: Billy
Enter grade: 98
Enter name: Sandy
Enter grade: -1
Grade: 99.0 Name: Billy
Grade: 98.0 Name: Sandy
Average of all grades is: 98.5

  • Below are the screenshot attached for the code and input/output for better clarity and understanding.

CODE

INPUT/OUTPUT

So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.


Related Solutions

JAVA In this PoD you will use an ArrayList to store different pet names (there are...
JAVA In this PoD you will use an ArrayList to store different pet names (there are no repeats in this list). This PoD can be done in your demo program (where your main method is) – you don’t have to create a separate class for today. Details Create an arraylist of Strings, then using a Scanner object you will first read in a number that will tell you how many pet names (one word) you will add to the arraylist....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Using the MORAL model, decide the best course of action for Jimmy from an ethical perspective...
Using the MORAL model, decide the best course of action for Jimmy from an ethical perspective rather than a legal perspective. Did you come to the same conclusion using both an ethical and a legal approach? N520- Legal and Ethical Issues in Health Care
Write a JAVA program to display your complete names, your matric number and your course of...
Write a JAVA program to display your complete names, your matric number and your course of study, using the two access modifiers stated in (a) and (b) (a) Use static access modifier for the method declaration of the program class, also use class name Eee532MakeUp. Use any method name of your choice. (b) Use public access modifier for the method declaration of the program class, also use class name EceCourseJava. (2) Which of the programs in (a) or (b) is...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades and add a linear trendline. What is the​ model? If a student scores 70 on the​ midterm, what would you predict her grade on the final exam to​ be? Student Midterm Final Exam 1 7575 6464 2 8585 9090 3 8080 6969 4 8989 8484 5 7676 6161 6 6666 7878 7 7878 7272 8 9494 9494 9 6767 5959 10 9393 8686 11...
The class Contact, shown below, which hold first names, last names, and mobile numbers. Using the...
The class Contact, shown below, which hold first names, last names, and mobile numbers. Using the built-in Java ArrayList<Contact> contacts Write a method     public static boolean contains(ArrayList<Contact> list, String firstOrLastName) public class Contact { private int mobileNumber; private String firstName; private String lastName; public int getMobileNumber() { return mobileNumber; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Contact(int mobile, String first, String last) { mobileNumber = mobile; firstName = first; lastName...
By looking at two linear equations, how can you tell that the corresponding lines are parallel,...
By looking at two linear equations, how can you tell that the corresponding lines are parallel, the same graph, or intersecting lines? How many solutions does each possibility have and why is that? Show examples for each possible situation.
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT