This question is a repeat from Lab Exercise 1. Here, along with the header and footer...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This question is a repeat from Lab Exercise 1. Here, along with the header and footer methods, you need to add a static method. The Question: Create a data structure that will keep a record of key and values. Here the key will be the year of studies of a group of university students, and the values will be their first names. These students are the leaders in the University Student Council. Your task would be to find out how many student leaders belong to a specific year and get a leader- representative from each year and print the names of those representatives. (a) Define a generic class called Pair <Y, N> with the following specifications (see the class diagram below): [Hint: this code is given in the class handout] Two private data fields: key Y and value N. Constructor with both Y and N parameters. ⚫ Getter and setter methods for both the data fields. Pair <Y, N> - key: Y - value: N + Pair(key: Y, value: N) + setKey (key: Y): void + setvalue (value: N): void +getKey():Y +getValue(): N (b) Create a public static void header method (with void parameter list) with the following information (see the sample output): Names: firstNamel and firstName2. (Hardcode it; meaning put the data manually) Student Numbers: studentNumber] and studentNumber2 (Hardcode it) Goal of this project: Brief description of the project. (Hardcode it) (c) Create a public static void footer method (with void parameter list) with the following Message (see the sample output): This is timeOfDay on theDate. Completion of Lab Assignment 1 is successful! Good bye! yourFullName. (d) Write a static method public static <Y, N> Pair[] getRep yourFirstName(Pair[] pa) that will return a pair containing student representative along with the corresponding year, from each year from the Pair list. Hint: You can create two ArrayList lists with appropriate tags and populate those arrayLists based on the ArrayList method called contains. (example: if the name of the arrayList is myArray, then if myArray.contains(get the year from Pair object reference variable) is false, populate myArray) (e) Define the driver method and do the following (Check the class handouts): i) ii) iii) iv) Call the header method. Declare an ArrayList type reference variable with Integer-tag and fill out the list with integer values 2, 3, 4, 3, 2, 2 with the aid of Array.asList(valuel, value2..) method as shown below. These numbers will represent the year of studies of the student leaders, Note that both ArrayList<E> and Arrays classes are available in java.util.* package. ArrayList<Integer> anyValidName = new ArrayList(Arrays.asList(2,3,....)); Declare a second ArrayList type reference variable with String-tag and fill out the list with String values Harry, Lavender, Ron, Hermione, Luna and Vincent with the aid of Array.asList(..) method. These string values represent the names of the student leaders. (FYI: Based on both the Lists, Harry is in 2nd year, Lavender is in 3rd year and so on). Create an array of size any ValidName.size() of Pair type reference variables. v) vi) vii) viii) ix) x) xi) Populate this Pair-array by the key and the corresponding value pairs using the two ArrayList<E> reference variables with the help of the getter methods (Slide 16, Unit 1- P2) from the ArrayList class. Now ask the user the following question: "From which academic year would you like to list the names of the leaders: " Validate that the user enters either 2 or 3 or 4 (see the sample output). Now based on the user's choice print the names of the leader(s) from that specific year. Keep asking the user till she/he does not want to continue. When the user press 'n', your program will call the getRep_yourFirstName() method from main, and then based on the returned values, print the list of the student's rep from each year (see the sample output). Call the footer method. Sample output: ***** Names: firstName1 and firstName2. Student Numbers: studentNumber1 and studentNumber2 Goal of this project: Brief description of the project. ***** From which year you are looking for the names of the student leaders: 1 Invalid entry! Enter a positive integer between 2 and 4: dsfsdfas Invalid entry! Enter a positive integer between 2 and 4:5 Invalid entry! Enter a positive integer between 2 and 4: f Invalid entry! Enter a positive integer between 2 and 4: 2 We found 3 students from year 2 and they are: Harry Luna Vincent Do you want to continue? [y or n]: y From which year you are looking for the names of the student leaders: 5 Invalid entry! Enter a positive integer between 2 and 4: r Invalid entry! Enter a positive integer between 2 and 4:3 We found 2 students from year 3 and they are: Lavender Hermione Do you want to continue? [y or n]: n Here is the list of the class-reps..... 2- Harry 3- Lavender 4- Ron ******* This is timeOfDay on theDate. Completion of Lab Assignment 1 is successful! Good bye! yourFullName. ***** This question is a repeat from Lab Exercise 1. Here, along with the header and footer methods, you need to add a static method. The Question: Create a data structure that will keep a record of key and values. Here the key will be the year of studies of a group of university students, and the values will be their first names. These students are the leaders in the University Student Council. Your task would be to find out how many student leaders belong to a specific year and get a leader- representative from each year and print the names of those representatives. (a) Define a generic class called Pair <Y, N> with the following specifications (see the class diagram below): [Hint: this code is given in the class handout] Two private data fields: key Y and value N. Constructor with both Y and N parameters. ⚫ Getter and setter methods for both the data fields. Pair <Y, N> - key: Y - value: N + Pair(key: Y, value: N) + setKey (key: Y): void + setvalue (value: N): void +getKey():Y +getValue(): N (b) Create a public static void header method (with void parameter list) with the following information (see the sample output): Names: firstNamel and firstName2. (Hardcode it; meaning put the data manually) Student Numbers: studentNumber] and studentNumber2 (Hardcode it) Goal of this project: Brief description of the project. (Hardcode it) (c) Create a public static void footer method (with void parameter list) with the following Message (see the sample output): This is timeOfDay on theDate. Completion of Lab Assignment 1 is successful! Good bye! yourFullName. (d) Write a static method public static <Y, N> Pair[] getRep yourFirstName(Pair[] pa) that will return a pair containing student representative along with the corresponding year, from each year from the Pair list. Hint: You can create two ArrayList lists with appropriate tags and populate those arrayLists based on the ArrayList method called contains. (example: if the name of the arrayList is myArray, then if myArray.contains(get the year from Pair object reference variable) is false, populate myArray) (e) Define the driver method and do the following (Check the class handouts): i) ii) iii) iv) Call the header method. Declare an ArrayList type reference variable with Integer-tag and fill out the list with integer values 2, 3, 4, 3, 2, 2 with the aid of Array.asList(valuel, value2..) method as shown below. These numbers will represent the year of studies of the student leaders, Note that both ArrayList<E> and Arrays classes are available in java.util.* package. ArrayList<Integer> anyValidName = new ArrayList(Arrays.asList(2,3,....)); Declare a second ArrayList type reference variable with String-tag and fill out the list with String values Harry, Lavender, Ron, Hermione, Luna and Vincent with the aid of Array.asList(..) method. These string values represent the names of the student leaders. (FYI: Based on both the Lists, Harry is in 2nd year, Lavender is in 3rd year and so on). Create an array of size any ValidName.size() of Pair type reference variables. v) vi) vii) viii) ix) x) xi) Populate this Pair-array by the key and the corresponding value pairs using the two ArrayList<E> reference variables with the help of the getter methods (Slide 16, Unit 1- P2) from the ArrayList class. Now ask the user the following question: "From which academic year would you like to list the names of the leaders: " Validate that the user enters either 2 or 3 or 4 (see the sample output). Now based on the user's choice print the names of the leader(s) from that specific year. Keep asking the user till she/he does not want to continue. When the user press 'n', your program will call the getRep_yourFirstName() method from main, and then based on the returned values, print the list of the student's rep from each year (see the sample output). Call the footer method. Sample output: ***** Names: firstName1 and firstName2. Student Numbers: studentNumber1 and studentNumber2 Goal of this project: Brief description of the project. ***** From which year you are looking for the names of the student leaders: 1 Invalid entry! Enter a positive integer between 2 and 4: dsfsdfas Invalid entry! Enter a positive integer between 2 and 4:5 Invalid entry! Enter a positive integer between 2 and 4: f Invalid entry! Enter a positive integer between 2 and 4: 2 We found 3 students from year 2 and they are: Harry Luna Vincent Do you want to continue? [y or n]: y From which year you are looking for the names of the student leaders: 5 Invalid entry! Enter a positive integer between 2 and 4: r Invalid entry! Enter a positive integer between 2 and 4:3 We found 2 students from year 3 and they are: Lavender Hermione Do you want to continue? [y or n]: n Here is the list of the class-reps..... 2- Harry 3- Lavender 4- Ron ******* This is timeOfDay on theDate. Completion of Lab Assignment 1 is successful! Good bye! yourFullName. *****
Expert Answer:
Answer rating: 100% (QA)
Certainly Below is a Java code implementation that addresses the steps outlined in the question java import javautilArrayList import javautilArrays cl... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Are there dangers with incarcerating young people in detention facilities? What about the potential for negative long-term impact? Using three documented examples of misconduct/mistreatment of youth...
-
The owner of a bookstore has asked for your help designing a system that allows them to keep track of the store's inventory and members. The owner provides you with the following details about what...
-
Write a static method max3() that takes three int arguments and returns the value of the largest one. Add an overloaded function that does the same thing with three double values.
-
State the appropriate nonparametric test for each of the following examples. (a) A physiological psychologist compares differences in the amount of chemical activity in a certain brain region between...
-
Plot the curves of the given polar equations in polar coordinates. r = 2sin
-
Abbott Industries is a well-known supplier of pharmaceuticals worldwide. Founded by Dr. Wallace Abbott, the company was incorporated in 1900 after he had been developing and making pharmaceuticals...
-
ABC, process costing Parker Company produces mathematical and financial calculators and operas at capacity. Data related to the two products are presented here. Total manufacturing overhead costs...
-
Amazon, Inc. Presentation Your chief executive officer (CEO) has asked you to present the company's (Amazon, Inc.) process on making decisions under risks and uncertainty at the annual shareholders'...
-
ADG Ltd. is considering investing in a new start-up project. The company has a plan that after five years it will sell the project at a good profit to a big Industrialist. The project outlays are...
-
Company A buys bonds from Company B. The bonds carry with them contractual rights to annual interest and repayment of principal in 10 years. The price was quoted in an open market. What kind of...
-
The U.S. green energy industry is filled with failed firms. They became so dependent upon government subsidies and favors that they simply could not compete and produce a product or service that was...
-
4)The accounting records of rockiness company provided the data below?$ in 000s? Net income $25,200 Depreciation expense 3,300 Decrease in accounts receivable 2,000 Increase in inventory 4,500...
-
A taxpayer wishes to use costs from their home office as an expense on their Schedule C. They have an office that is two hundred (200) square feet and valid expenses (after using a Form 8829) of...
-
An industrial imaging system can be purchased for $95,000. At the end of five years, this unit will have a salvage value of $40,000. Alternative, you can lease the machine for five years, with annual...
-
opic: What are the major challenges in managing information systems? Explain the connection between the Firm, its IT Infrastructure and Business bilities. Discuss Cloud Computing in terms of fueling...
-
The following T-accounts show postings of selected transactions. Indicate the journal used in recording each of these postings a through e. Cash Accounts Receivable Inventory (d) 500 (e) 300 (b)...
-
Write a program that will read a line of text that ends with a period, which serves as a sentinel value. Display all the letters that occur in the text, one per line and in alphabetical order, along...
-
Repeat Exercise 13, but use a multibranch if-else statement instead of a switch statement. Exercise 13 Imagine a program that displays a menu of five possible choices, lettered a through e. Suppose...
-
Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in Section 5.2. The new version should include accessor and mutator methods. Also define...
-
In the past five years, there have been significant innovations in technology such as smartphones and tablets. Technology companies rely on intellectual property (IP) rights, such as patents,...
-
Respondents Varsity Brands, Inc., Varsity Spirit Corporation, and Varsity Spirit Fashions & Supplies, Inc., design, make, and sell cheerleading uniforms. Respondents have obtained or acquired more...
-
Mr. Tam is the front man for the Asian American dance-rock band The Slants. Mr. Tam named his band The Slants to reclaim and take ownership of Asian stereotypes. The band draws inspiration for its...
Study smarter with the SolutionInn App