Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Help, this is to be done in java Summary : In this lab, you will be making a program that collects and stores student

Please Help, this is to be done in java

Summary: In this lab, you will be making a program that collects and stores student information. This information will be stored in parallel arrays. You will then use this information to generate some summary information about the collection of students.

  1. Setting up the Project

Per usual, set up a new Eclipse project.

  1. Name the project Lab_04_Last_First
  2. Make a Java class called Driver
    1. This is a common pattern when the program is going to be showcasing some functionality rather than doing a specific job.
  1. Start Small

Before we start trying to collect information about multiple students, lets start by making sure we can collect information for one student.

  1. Getting the Input

Do all this in the main method

  1. Make three variables, a String variable to hold a first name, a String variable to hold a last name, and a double variable to hold a GPA
    1. Make sure to follow our naming conventions!
  2. Get a value from the user for each variable and validate it
    1. First and last name: shouldnt be blank
    2. GPA: should be a double between 0.0 and 4.0, inclusive
  3. Print out the student information to make sure everything is working
    1. Methodizing our Code

This is a lot of input and validation code. Lets clean up the main method by moving this code to a method and calling it.

  1. Make a method that will get all the students information
  2. Will this method return anything?
  3. Does this method need any data passed into it?
  4. Hint: You made need to move the scanner variable declaration to the class scope and initialize/close it in the main method
    1. This will allow us to use the scanner across methods without remaking the variable every time and running into many potential errors (trust me, I found them when writing this lab)
  5. Move the input code into your method
  6. Call the new method in the main method and verify everything still works
  1. Moving to multiple values

Now that our code works for one students information, lets make a series of parallel arrays to hold multiple students information. We will use the Arrays package to help: https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Arrays.html

  1. Make three arrays in the main method to hold information for 5 students:
    1. A String array to hold 5 first names
    2. A String array to hold 5 last names
    3. A double array to hold 5 GPAs
  2. Use Arrays.fill() from the java.utils.Arrays package to fill the arrays
    1. Fill first names with John
    2. Fill last names with Smith
    3. Fill GPAs with 3.0
  3. Use Arrays.toString() to print out all three arrays and make sure everything works
  4. We can take advantage of the reference nature of arrays to update all three in our info method
    1. Since methods can only return 1 value, we cant return all the student info from our method. Instead, we can use the single-value variables we made in part 2 inside the method and assign them to the correct index in the arrays, updating all three without needed to return anything!
  5. If you did not before, please change your method to take no parameters and create three local variables: String firstName, String lastName, and double gpa. We will use these to get and validate the users input
  6. Change the method signature to be a void return type and accept four parameters: a String array of first names, a String array of last names, double array of gpas, and an index
    1. private static void getStudentInfo(String[] firstNames, String[] lastNames, double[] gpas, int index)
  7. In the get info method, add code after the input collection and validation to assign the validated input to the appropriate array at the index passed in to the method
  8. In the main method, make a for loop that counts from 0 to 4:
    1. for(int i = 0; i < 5; i++)
  9. Inside this loop, call your get info method and pass in the three arrays and the loops counter variable
  10. After the loop, use Arrays.toString() to print out all three arrays and make sure that the contents have changed to the values you entered
  1. Summary Info

Now that have the student information, lets start doing some work with it. Lets find the student with the highest GPA, the student with the lowest GPA, and calculate the average GPA.

  1. Max GPA

We will write a method that will search through the array of GPAs to find the highest GPA and tell the main method the index at which that value was found.

  1. Write a method signature that will accept an array of doubles and return an int
  2. Please provide that signature here:
  3. Iterate over the values in the array, keeping track of which index has the highest value
    1. If multiple students have the same highest GPA, return the index of the last student with the highest GPA
  4. Call this method in the main method and store the index
  5. Print out the information of the student with the highest GPA
    1. Min GPA

We will write a method that will search through the array of GPAs to find the lowest GPA and tell the main method the index at which that value was found.

  1. Write a method signature that will accept an array of doubles and return an int
  2. Please provide that signature here:
  3. Iterate over the values in the array, keeping track of which index has the lowest value
    1. If multiple students have the same lowest GPA, return the index of the last student with the lowest GPA
  4. Call this method in the main method and store the index
  5. Print out the information of the student with the lowest GPA
    1. Average GPA

We will write a method to calculate the average GPA and tell the main method what the average GPA is.

  1. Write a method signature that will accept an array of doubles and return a double
  2. Please provide that signature here:
  3. Iterate over the values in the array to fun the count and sum
  4. Calculate and return the average GPA
  5. Call this method in the main method and print out the average GPA

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago