Question: JAVA Midterm.java /* Please complete the programming questions here and submit the file on Canvas */ /* WRITE YOUR NAME HERE */ import java.util.*; public

JAVA

JAVA Midterm.java /* Please complete the programming questions here and submit the

Midterm.java

/* Please complete the programming questions here and submit the file on Canvas */ /* WRITE YOUR NAME HERE */

import java.util.*;

public class Midterm1 { /* The main is to test your implementations. Examples in the questions are implemented in main. * Do not change anything in main */ public static void main (String [] args) { ArrayList list = new ArrayList (); list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); method1(3, list); // list = [3, 4, 5] System.out.print ("Q1: [3, 4, 5] " + list); method1(6, list); // list = [] System.out.println (", Q1: [] " + list);

Map map = new HashMap (); String [] values = { "value1", "value2", "value3"}; map.put ("key1", values); String [] values1 = {"value4", "value5", "value6", "value7"}; map.put ("key2", values1); String [] values2 = {"value8", "value9", "value10"}; map.put ("key3", values2); System.out.println ("Q2: " + method2(map)); if (method3(123456) == 11223456 && method3(21) == 2211) System.out.println ("Q3: Correct"); else { System.out.println ("Q3 test failed"); System.out.println ("method3(123456): " + method3(123456)); System.out.println ("method3(21): " + method3(21)); } } /* add your code for method1 */ /* add your code for method2 */ /* add your code for method3 */ }

this is for practice

Download the main method file here: Midterm.java Open the file and add your code for method1 - method3 (Q1-Q3 below) When you are done, upload the file. The file name should NOT be changed : Midterm.java Here is the expected output when the completed program is executed: Q1: [3, 4, 5] [3, 4, 5), Q1: [] [] Q2: [key1, key3] Q3: Correct Q1. Write a method called method 1 that takes an integer n and an ArrayList of integers as parameters and deletes all elements less than n in the ArrayList. For example, if a variable called list stores the vaules (1,2,3,4,5), method1 (3, list) should delete all values less than 3, changing the list to store (3, 4, 5). If a call method1 ( 6, list ) is made again on the list = [3,4,5), the list will be [] after the call since all values less than 6 will be removed from the list. Q2. Write a method called method2 that accepts a map as a parameter. The keys are strings and values are string arrays. method2 will return the set containing keys with 3 values from the map. The returned set should be sorted in an ascending order. For example, the map {key1=[value1, value2, value3), key2=[value4, value5, value6, value7], key3=[value8, value9, value10] will return [key1, key3]. Q3: Write a recursive method called method3 that accepts an integer parameter and returns the integer reformed by repeating digits 1 and 2. For example, method3 (123456) will return 11223456 repeating only 1 and 2 and method3 (21) will return 2211. If the number is 0, return 0. You may assume that n is not negative. Loop structures should not be used. Download the main method file here: Midterm.java Open the file and add your code for method1 - method3 (Q1-Q3 below) When you are done, upload the file. The file name should NOT be changed : Midterm.java Here is the expected output when the completed program is executed: Q1: [3, 4, 5] [3, 4, 5), Q1: [] [] Q2: [key1, key3] Q3: Correct Q1. Write a method called method 1 that takes an integer n and an ArrayList of integers as parameters and deletes all elements less than n in the ArrayList. For example, if a variable called list stores the vaules (1,2,3,4,5), method1 (3, list) should delete all values less than 3, changing the list to store (3, 4, 5). If a call method1 ( 6, list ) is made again on the list = [3,4,5), the list will be [] after the call since all values less than 6 will be removed from the list. Q2. Write a method called method2 that accepts a map as a parameter. The keys are strings and values are string arrays. method2 will return the set containing keys with 3 values from the map. The returned set should be sorted in an ascending order. For example, the map {key1=[value1, value2, value3), key2=[value4, value5, value6, value7], key3=[value8, value9, value10] will return [key1, key3]. Q3: Write a recursive method called method3 that accepts an integer parameter and returns the integer reformed by repeating digits 1 and 2. For example, method3 (123456) will return 11223456 repeating only 1 and 2 and method3 (21) will return 2211. If the number is 0, return 0. You may assume that n is not negative. Loop structures should not be used

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!