Question

In: Computer Science

Create a program in java using the following information: Trainers at Tom's Athletic Club are encouraged...

Create a program in java using the following information:

Trainers at Tom's Athletic Club are encouraged to enroll new members. Write an application that extracts the names of Trainers and groups them based on the number of new members each trainer has enrolled this year. Output is the number of trainers who have enrolled 0 to 5 members, 6 to 12 members, 13 to 20 members, and more than 20 members. Give their names as well as the number of members they have enrolled.   

Use this list of trainers:

{"Jake Butt", "Ziggy Hood", "Hroniss Grasu", "Vontaze Burfict", "Jaquiski Tartt",
"Ndamukong Suh", "Thurston Armbrister", "Captain Munnerlyn", "Barkevious Mingo", "Ha Ha Clinton-Dix",
"Mister Alexander", "BenJarvus Green-Ellis", "Richie Incognito", "Champ Bailey", "Captain Munnerlyn",
"Mike Kafka", "Ras-I Dowling", "Bryan Anger", "D'Brickashaw Ferguson", "Rex Hadnot",
"Sage Rosenfels", "Robert Griffin III", "Sav Rocca", "Chad Ochocinco", "Brett Rypien"
}

Use this list of the number of members each trainer has enrolled:

{3, 9, 13, 26, 23,
19, 15, 13, 17, 8,
2, 3, 5, 7, 11,
18, 12, 14, 20, 16,
4, 6, 10, 1, 0
}

example output:

This program grades the trainer's enrollment.
Those who enrolled from,...
0 to 5 - 7 trainers
Jake Butt(3), Mister Alexander(2), BenJarvus Green-Ellis(3), Richie Incognito(5), Sage Rosenfels(4), Chad Ochocinco(1), Brett Rypien(0)
6 to 12 - 7 trainers
Ziggy Hood(9), Ha Ha Clinton-Dix(8), Champ Bailey(7), Captain Munnerlyn(11), Ras-I Dowling(12), Robert Griffin III(6), Sav Rocca(10)
13 to 20 - 9 trainers
Hroniss Grasu(13), Ndamukong Suh(19), Thurston Armbrister(15), Captain Munnerlyn(13), Barkevious Mingo(17), Mike Kafka(18), Bryan Anger(14), D'Brickashaw Ferguson(20), Rex Hadnot(16)
...over 20 - 2 trainers
Vontaze Burfict(26), Jaquiski Tartt(23)

End of job

an approach:

Create "buckets" to represent the enrollment groupings. The "buckets" can be implemented by using additional parallel arrays (like the master list - one array for the trainer, another for their enrollment).

After examining each item in the master list of trainers, they can be placed in one of the subset "buckets" (both the the trainer's name and the number of people they have enrolled). After walking through the master list, the trainers and their enrolled will be distributed among the "buckets".

The output is formed by simply extracting the information from the appropriated "bucket".

Solutions

Expert Solution

import java.util.*;

public class example {
public static void main(String[] args) {
   String[] trainer = {"Jake Butt", "Ziggy Hood", "Hroniss Grasu", "Vontaze Burfict", "Jaquiski Tartt",
           "Ndamukong Suh", "Thurston Armbrister", "Captain Munnerlyn", "Barkevious Mingo", "Ha Ha Clinton-Dix",
           "Mister Alexander", "BenJarvus Green-Ellis", "Richie Incognito", "Champ Bailey", "Captain Munnerlyn",
           "Mike Kafka", "Ras-I Dowling", "Bryan Anger", "D'Brickashaw Ferguson", "Rex Hadnot",
           "Sage Rosenfels", "Robert Griffin III", "Sav Rocca", "Chad Ochocinco", "Brett Rypien"};
   int[]enrollment = {3, 9, 13, 26, 23,
           19, 15, 13, 17, 8,
           2, 3, 5, 7, 11,
           18, 12, 14, 20, 16,
           4, 6, 10, 1, 0};
  
   ArrayList<bucket> zeroTo5 = new ArrayList<>();
   ArrayList<bucket> sixTo12 = new ArrayList<>();
   ArrayList<bucket> thirteenTo20 = new ArrayList<>();
   ArrayList<bucket> moreThan20 = new ArrayList<>();
   for(int i=0;i<enrollment.length;i++) {
       bucket tmp = new bucket(trainer[i],enrollment[i]);
       if(enrollment[i]<=5) {
           zeroTo5.add(tmp);
       }
       else if(enrollment[i]<=12) {
           sixTo12.add(tmp);
       }
       else if(enrollment[i]<=20) {
           thirteenTo20.add(tmp);
       }
       else {
           moreThan20.add(tmp);
       }
   }
   //0 to 5 trainers
   System.out.println("0 to 5 - "+zeroTo5.size()+" trainers");
   for(int i=0;i<zeroTo5.size();i++) {
       if(i == zeroTo5.size()-1) {
           System.out.print(zeroTo5.get(i).name +"("+zeroTo5.get(i).enrollment+")");
           break;
       }
       System.out.print(zeroTo5.get(i).name +"("+zeroTo5.get(i).enrollment+"), ");
   }
   System.out.println();
  
   //6 to 12 trainers
   System.out.println("6 to 12 - "+sixTo12.size()+" trainers");
   for(int i=0;i<sixTo12.size();i++) {
       if(i == sixTo12.size()-1) {
           System.out.print(sixTo12.get(i).name +"("+sixTo12.get(i).enrollment+")");
           break;
       }
       System.out.print(sixTo12.get(i).name +"("+sixTo12.get(i).enrollment+"), ");
   }
   System.out.println();
  
   //13 to 20 trainers
   System.out.println("13 to 20 - "+thirteenTo20.size()+" trainers");
   for(int i=0;i<thirteenTo20.size();i++) {
       if(i == thirteenTo20.size()-1) {
           System.out.print(thirteenTo20.get(i).name +"("+thirteenTo20.get(i).enrollment+")");
           break;
       }
       System.out.print(thirteenTo20.get(i).name +"("+thirteenTo20.get(i).enrollment+"), ");
   }
   System.out.println();
  
   //over 20 trainers
   System.out.println("over 20 - "+moreThan20.size()+" trainers");
   for(int i=0;i<moreThan20.size();i++) {
       if(i == moreThan20.size()-1) {
           System.out.print(moreThan20.get(i).name +"("+moreThan20.get(i).enrollment+")");
           break;
       }
       System.out.print(moreThan20.get(i).name +"("+moreThan20.get(i).enrollment+"), ");
   }
   System.out.println();
}
}
class bucket{
   String name;
   int enrollment;
   public bucket(String name, int enrollment) {
       this.name = name;
       this.enrollment = enrollment;
   }
}


Related Solutions

Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
Create a java program that allows people to buy tickets to a concert. Using java create...
Create a java program that allows people to buy tickets to a concert. Using java create a program that asks for the users name, and if they want an adult or teen ticket. As long as the user wants to purchase a ticket the program with "yes" the program will continue. When the user inputs "no" the program will output the customer name, total amount of tickets, and the total price. The adult ticket is $60 and the child ticket...
Write a java program using the following instructions: Write a program that determines election results. Create...
Write a java program using the following instructions: Write a program that determines election results. Create two parallel arrays to store the last names of five candidates in a local election and the votes received by each candidate. Prompt the user to input these values. The program should output each candidates name, the votes received by that candidate, the percentage of the total votes received by the candidate, and the total votes cast. Your program should also output the winner...
how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable radius = -999 declare character choice create do while loop inside of do loop write: System.out.println(); System.out.println("*** CIRCLE CALCULATIONS ***"); System.out.println(); System.out.println("1. Enter the radius of the circle"); System.out.println("2. Display the area of the circle"); System.out.println("3. Display the circumference of the circle"); System.out.println("4. Quit"); System.out.println(); System.out.println("Enter a number from 1 - 4"); System.out.println(); Declare choice character and relate to scanner declare switch (choice) case...
Create a program in Java for storing the personal information of students and teachers of a...
Create a program in Java for storing the personal information of students and teachers of a school in a .csv (comma-separated values) file. The program gets the personal information of individuals from the console and must store it in different rows of the output .csv file. Input Format User enters personal information of n students and teachers using the console in the following format: n Position1 Name1 StudentID1 TeacherID1 Phone1 Position2 Name2 StudentID2 TeacherID2 Phone2 Position3 Name3 StudentID3 TeacherID3 Phone3...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods....
5.9 Online shopping cart (Java) Create a program using classes that does the following in the...
5.9 Online shopping cart (Java) Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need. (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT