Task 6: Arrays

Updated On: Oct. 31, 2020

6.1: Make an array of n elements and initialize it from user input. Get n from user. Print all the numbers, find and print the minimum number and its index in the array, find maximum number and its index in the array, find the average of all numbers.

6.2: Roll a 6 faces dice 1 million times, print how many times each face appear along with its percentage? Use arrays to store each face count e.g. face[3] shall store how many times 4 appeared during random rolls. See figure 7.7 of book for detail (Java How to Program, By Dietel. 10th Edition).

6.3: Make a program that shuffle cards. Print the deck before shuffling and after shuffling. See Figure 7.9, 7.10 and 7.11 from reference book.

6.4. Update Task 5 such that PhoneNumber shall be an instance attribute of Student. To let user store multiple phone numbers, define phoneNumbers attribute of type PhoneNumber[]. Encapsulate phoneNumbers field. When creating a Student object, let user enter how many numbers a student has. And then get each phone number from user input to store in Student type object. At the end, just print all the data i.e. student attributes (including all phone numbers).

6.5. Assume below basic skeleton of Student and GradeBook class:
public class GradeBook {
    private String courseName;
    private Student[] students;
// ... other methods .... 
public class Student{
    private int id;
    private String name;
    int marks[];   // marks in different tests
Encapsulate fields and defined needed constructors. Then, make a GradeBook object and fully initialize it based on user input. Get number of students from user input. As number of tests each student given may be different, so your program shall take number of tests and marks in each test, form user input too. You can also generate and use random number to quickly initialize whole data, instead of getting from user, but choose decent ranges e.g. maximum marks 100, maximum students 50 and maximum number of test each student may give shall be less or equal to 10. After fully initializing the GradeBook object, print following information:
  1. Which student given maximum number of test, print student id
  2. Who got maximum average marks, print student id.
  3. Average marks of the class
  4. Average marks of each student in the class
  5. Minimum marks of each student, print marks and student id
  6. Maximum marks of each student,  print marks and student id
  7. Average, minimum and maximum marks of the student (get student from user)
Some methods shall be written in Student class and some inside the GradeBook class, decide the best place for a method based on what it does. Perform all listed tasks in different methods and call those methods from the main method in GradeBook test class.