Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Required Skills Inventory Write a method that takes an argument and returns a value * Write a method that takes an ArrayList as an argument

image text in transcribed
Required Skills Inventory Write a method that takes an argument and returns a value * Write a method that takes an ArrayList as an argument 5 * Write a method that returns an ArrayList + Use a loop to iterate over the elements of an array Usean if statement to get the computer to make a decision Copy values from one ArrayListto another Declare and instantiate an ArrayList Problem Description and Given Info Write (define) a public static method named noDuplicates, that takes an ArrayList as an argument and returns a new ArrayList with all of the values in the argument ArrayList, but without any duplicates Copyright 2021 Arizona State University - THIS CONTENT IS PROTECTED AND MAY NOT BE SHARED, UPLOADED, SOLD, OR DISTRIBUTED. For Example: given an ArrayList named myList that contains this list of values: {5,3,1,2,1,3,3}, noDuplicates (myList) will return an ArrayList that contains this list of values: {5, 3, 1.2} given an ArrayList named myList that contains this list of values: {1,1,5,5,3,3}, noDuplicates (myList) will return an ArrayList that contains this list of values: {1, 5, 3} Vi s ssinh #a irita nama additinnal andn ta tact vmne mathad Required Skills Inventory + Write a method that takes no arguments and returns no value + Assign a value to an instance variable from within a constructor method + Implement a default constructor method in a Java class Copyright 2021 Arizona State University - THIS CONTENT IS PROTECTED AND MAY NOT BE SHARED, UPLOADED, SOLD, OR DISTRIBUTED. Problem Description and Given Info 'You must complete the Bunny class (in the bunny java file) you are given below. To complete this simple class, you must define a publ ic default constructor method that initializes the name and age fields. The name filed should be initialized to the String value "Mopsy", and the age field should be initialized to the int value 7. HINTS Remember that a constructor method has the same name as its class. Remember that a constructor method has no return type - not even void. Remember that a default constructor takes no arguments. NOTE In general, fields (instance variables) should be declared to be private. However, for this Challenge the fields are declared as public. Need Help? Additional help resources are available by clicking on the words "Need Help?" at the bottom of this page, and search for help or ask a question! Hitary Tt Ml'n.ilvll @ public class Main { public static void main(String(] args) | Bunny myBunny = new Bunny(); Bunny yourBunny = new Bunny(); yourBunny.name = "Flopsy"; yourBunny.age = 5; myBunny .print () yourBunny.print () ; i emuauswn e * Use a loop to get the computer to repeat instructions Use a loop to iterate over the elements of an ArrayList + Usean if statement to get the computer to make a decision + Usea variable to keep a count * Write a method that takes an ArrayList as an argument f Problem Description and Given Info Write (define) a public static method named countInList, that takes two arguments that are both an ArrayList of Integer. This method must retum a count (int) of the number of values in the first argument ArrayList that are also in the second argument ArrayList. For example: given an ArrayListnamed 1ist1 that contains this list of values: {1, 2, 1, 3, 2, 5, 6, 2, 4} and an ArrayListnamed 1ist2 that contains this list of values: {1, 2, 3} countInList(listl, list2) should return 6 (because there are six values in 1ist1 that are also in list2) given an ArrayListnamed listl that contains this list of valves: {1, 2, 1, 3, 2, 5, 6, 2, 4} and an ArrayListnamed list2 that contains this list of values: {2, 4} countInList(listl, list2) should return 4 (because there are 4 values in 1ist1 that are also in list2) given an ArrayList named list1 that contains this list of values: {1, 2, 1, 3, 2, 5, 6, 2, 4) and an ArrayListnamed 1ist2 that contains this list of values: {7, 8, 9} countInList(listl, list2) should return O (because there are 0 values in 1ist1 that are also in list2) You may wish to write some additional code to test your method, Copyright 2021 Arizona State University - THIS CONTENT IS PROTECTED AND MAY NOT BE SHARED, UPLOADED, SOLD, OR DISTRIBUTED. Helpful Hints: * Usealoop to iterate over the elements of the argument ArrayList + For each element in the array, you must decide to either count it or not For each value in the first argument ArrayList, you must search for that value in the second argument ArrayList o if the value is in both lists, then you must include it in the count * Return the count at the end * Write a method that takes arguments and returns no value * Use parameter variables in a method * Assign a value to an instance variable from within a constructor method Implement an overloaded parameterized constructor method in a Java class Problem Description and Given Info You must complete the Bunny class (in the bunny_java file) you are given below. To complete this simple class, you must define a public constructor method that takes two arguments. the first argument must be a string, and the second argument must be an int. The constructor must initializes the name and age fields with the argument values. HINTS Remember that a constructor method has the same name as its class. Remember that a constructor method has no return type - not even void. Remember that you can (and should) sue the this keyword to access an object's instance fields. Copyright 2021 Arizona State University - THIS CONTENT IS PROTECTED AND MAY NOT BE SHARED, UPLOADED, SOLD, OR DISTRIBUTED. NOTE In general, fields (instance variables) should be declared to be private. However, for this Challenge the fields are declared as public. Need Help? Additional help resources are available by clicking on the words "Need Help?\" at the bottom of this page, and search for help or ask a question! D O History Tutorial Main.java l & 1 public class Main { public static void main(Stringl) args) | Bunny myBunny = new Bunny("Flopsy\

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

Step: 3

blur-text-image

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions