Question

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 by average (least to greatest) using Bubble Sort OR Selection Sort.

Look at notes to help with the assignment.

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

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();
   }

}

Add a comment
Know the answer?
Add Answer to:
You are to write a program which will ask the user for number of students (dynamic...
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
  • 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....

    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...

    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...

    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...

    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...

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

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    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...

  • C++ There is a class called Person which has name and age as private variables. Another...

    C++ There is a class called Person which has name and age as private variables. Another class called Student, which is derived from person with gpa and id as variables. name is a string, age and id are integers and gpa is a double... All of them are private variables. age, gpa and id should be generated randomly when the object is created with the following ranges: age 20 to 32 gpa 0.0 to 4.0 // this one is tricky...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • In this assignment you are asked to write a python program to maintain the Student enrollment...

    In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...

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