You are to write a program which will ask the user for number of students (dynamic array of class Student).
For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student).
**The program should give the student random grades from 0-100**
Find the averages of each student and display the information.
**Display name, grades, and average neatly in a function in the Student class called Display()**
Sort the students by average (least to greatest) using Bubble Sort OR Selection Sort.
Look at notes to help with the assignment.
ANSWER:
GIVEN THAT:
Student.java
import java.util.Arrays;
public class Student {
String firstName;
double[] grades;
public Student() {
}
public Student(String firstName, double[] grades)
{
this.firstName= firstName;
this.grades = grades;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public double[] getGrades() {
return grades;
}
public void setGrades(double[] grades) {
this.grades = grades;
}
public double average() {
double sum=0;
int len = grades.length;
for(int i=0;i<len;i++) {
sum=sum+grades[i];
}
return sum/len;
}
public void display() {
System.out.println("Student Name :
"+this.firstName);
System.out.println("Grades are :
"+Arrays.toString(grades));
System.out.println("Average is :
"+average());
}
}
StudentTester.java
import java.util.Scanner;
public class StudentTester {
public static void main(String[] args) {
// TODO Auto-generated method
stub
String name;
double[] grades;
int studentNum;
int gradeNum;
Scanner scan = new
Scanner(System.in);
System.out.println("Enter number of
students you will enter : ");
studentNum=scan.nextInt();
Student[] students = new
Student[studentNum];
for(int i=0;i<studentNum;i++)
{
System.out.println("Entering student number " + (i+1));
System.out.println("Enter the student Name : ");
name=scan.next();
System.out.println("Enter number of grades : ");
gradeNum=scan.nextInt();
grades = new
double[gradeNum];
System.out.println("Enter the grades one by one");
for(int j=0;
j<gradeNum;j++)
grades[j]=scan.nextDouble();
students[i]=new
Student(name,grades);
}
System.out.println("Displaying
students Information before sorting : ");
for(int
i=0;i<studentNum;i++)
students[i].display();
for (int i = 0; i <
studentNum-1; i++)
for (int j = 0; j < studentNum-i-1; j++)
if (students[j].average() > students[j+1].average())
{
Student temp = students[j];
students[j] = students[j+1];
students[j+1] = temp;
}
System.out.println("Displaying
students Information After sorting : ");
for(int
i=0;i<studentNum;i++)
students[i].display();
}
}
You are to write a program which will ask the user for number of students (dynamic...
You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...
Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....
Visual C#
Homework 2
You are to write a program which will create a class called
Student
Each student has a name age height and weight. These variables
should be declared as private.
Create the correct constructors and functions.
In the main, you will create 5 students.
Input the data for the 5 students from a file which already
has information in it. Name the file “Information.txt”.
After setting up all the data, it is time to sort based on...
using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...
Write a program that performs the following: 1. Presents the user a menu where they choose between: a. Add a new student to the class i. Prompts for first name, last name ii. If assignments already exist, ask user for new student’s scores to assignments b. Assign grades for a new assignment i. If students already exist, prompt user with student name, ask them for score ii. Students created after assignment will need to...
[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:...
You will create a Grade Program that will calculate students’ weighted averages. You are going to have the user enter lab grades, test grades, and project grades. You will then display a grade report of each individual average along with their overall average and letter grade. Ask the user to enter their lab grades. Call the averageGrade function that will allow the user to enter their grades and calculate their average. averageGrade Function: This will pass the average back to...
Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...
For C++ program Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have...
Write a C program that allows a user to enter up to 30 student id’s and 3 grades per student. It will then compute and display a report of the students averages, and then a statement of the class average for those grades. The following is a sample run that demonstrates what your program should look like: Please enter your school name: Cape Tech Welcome to the Cape Tech Grade Calculator Enter the number of students to process (0 -...