Data Collections Lab

Note: This should be done in pairs.

Requirements

Write 5 functions that accept parameters that use combinations of control flow and multiple conditionals. Some of these functions will also require you to iterate over data collections (Arrays, ArrayLists,Hash Maps). When a function is created, please call it and test all the cases including edge ones (e.g. empty strings, null values, big and small values). It is of high importance to practice and master Java fundamentals, which are the core of Android development.

Getting Started
  • Each student should create a new Git repository and publish it called collections-lab
  • Work together to solve these problems
  • Both students should write final code themselves
  • Bothn students should sync/publish their changes when done

Functions

  1. Write a function that accepts no parameters and creates a list of any characters and returns a string, which contains every other element in the list. Thus, if the list has 'a', 'b', 'c', 'd', the output should be "bd".

  2. Write a function that takes in an array of integers and returns the max value in that array. Please do not sort the array.

  3. Write a function that takes in a month of the year and returns the number of days in this month. If the input is not a valid month, return 0.

  4. Write a function that takes in an array of integers, sums the integers that are greater than 1, and subtracts 3 if the number is greater than 20. The function returns the result of the operations on the array.

  5. Write a function that creates the right data structure to keep the names of your family members and their age. The function asks the user to type in a family member's name and returns his/her age if the name exists or the string "Such family member does not exist!" if such a member does not exit.

Bonus!

  1. Write a function that takes in a list of names, filters the list removing all duplicate names and returns a list with unique names.

Deliverable

You are expected to create a Java file with 6 functions and run them testing all cases.

Resources

results matching ""

    No results matching ""