Site icon Tutor Bin

SMC Java Software Engineer Project

SMC Java Software Engineer Project

Description

Problem 1:

( 10 points ) Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic in 2020, the federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis.

You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working on a software solution to check that given a set of resources, whether they can be proportioned and distributed equally to k medical facilities. Resources are represented as an array of positive integers. You want to see if these resources can be sub-divided into k facilities, each having the same total sum (of resources) as the other facilities. For example with resources = {1,2,3,4,5,6} we can sub-divide them into k = 3 medical facilities, each having the same total sum of 7: {1,6}, {2,5}, and {3,4}.

EXAMPLES

input: {3,4,5,6}, 2

output: true

Explanation: {3,6}, {4,5}

input: {1}, 1

output: true

Explanation: {1}

input: {1 , 3 , 2 , 3 , 4 , 1 , 3 , 5 , 2 , 1}, 5

output: true

input: {1}, 4

output: false

Explanation: cannot split further with a value of 1 in resource.

HINTS

  • Note: you may choose to solve this problem in your own way or use the following pseudo code.
  • Check for all boundary conditions to return result immediately if known, e.g., resources.length() = 1 and k = 1, return true, resources.length() = 1 and k = 4, return false, etc.
  • Find the purported allocation for each group, i.e., allocation = SUM(resources)/k.
  • Sort the resources in either ascending or descending order.
  • Create another solution method of your choice to enable recursion.
  • Remaining Pseudo Code:
    1. Create an empty array of integers with k elements. This is your “memory buffer”. At the end of your recursion, you want this memory buffer be filled with equally allocated values, allocation.
    2. Pick the highest resource (one with the highest integral value) in your resources.
    3. Check if the selected resource is <= allocation:
      • If yes, add that value to the first available element in your memory buffer of k elements. Go to #4.
      • If not, move on to other elements in your memory buffer to see if there’s available space to accommodate it.
      • If there’s no available space to accommodate the selected resource, it is impossible for resources to be allocated equally.
    4. Advance to the next highest resource. Repeat Step #3. If all resources have been considered and there is no more next highest, go to Step #5.
    5. Check if every element in your memory buffer has the same value. If so you have an evenly allocated distribution – return true. False otherwise.

SUBMISSION

  • Submit your solution in HW4_1.java.
  • There are two classes in this Java code. One of them is your HW4_1 class, and the other is the same top-level class (the one without the public access modifier) named Solution.

STARTER CODE

Write a solution method, canDistribute, that returns whether it is possible (true or false) that a given set of resources divides into k equal-sum facilities. You will solve this problem using a recursion:

public class HW4_1 {    
   public static void main(String[] args) {
      // your solution will be tested as such, sequentially with random input
      Solution sol = new Solution();
      sol.canDistribute(new int[]{1}, 2);
      sol.canDistribute(new int[]{1,2,2,3,3,5,5}, 12);
      // etc.
   }
}

/**
 * PURPOSE:
 * PARAMETERS:
 * RETURN VALUES:
*/
class Solution {
   public boolean canDistribute(int[] resources, int groups) { 
      // YOUR CODE HERE 
   } 

}

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version