Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the main Download the main method file here: Midterm.java Open the file and add your code for method1 - method3 (Q1-Q3 below) When

image text in transcribed
This is the main
image text in transcribed
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:00 Q2: [key1, key3] Q3: Correct Q1. Write a method called method1 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, value 3), key2=[value4, value5, value, value 7), key3= [value8, value9, value 10] 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. /* Please complete the programming questions here and submit the file on Canvas */ /* WRITE YOUR NAME HERE */ import java.util.; public class Midterm { /* 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(4); list.add(s); methodi(3, list); // list = [3, 4, 5] System.out.print ("Q1: [3, 4, 5] " + list); methodi(6, list); // list = [] System.out.println (", Q1: [] + list); Map map = new HashMap (); string Ol values = { "value1", "value2", "value3"); map.put ("keyi", values); String [] values1 = {"value4", "values", "value6", "value7"); map.put ("key2", valuesi); String [] values2 = ("value", "value9", "value10"); map.put ("key3", values2); System.out.println("02: " + method2(map)); if (method3(123456) == 11223456 && method3(21) == 2211) System.out.print in ("Q3: Correct"); else System.out.println ("Q3 test failed"); System.out.println("method3(123456): " + method3 (123456)); System.out.println ("methods(21): + method3(21)); 3 / add your code for methodi / 7 add your code for method2 */ / add your code for methods */

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_2

Step: 3

blur-text-image_3

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

1. Discuss the main incentives for individual employees.pg 87

Answered: 1 week ago

Question

What is the environment we are trying to create?

Answered: 1 week ago