Question

In: Computer Science

PLATFORM INDEPENDENCE Please see Syllabus for more information. Your solution has to be platform-independent; it must...

PLATFORM INDEPENDENCE

  • Please see Syllabus for more information.
  • Your solution has to be platform-independent; it must run on any platforms including any online IDEs:
    • You solution should be free of any use of packages. Example, absolutely no
    • /* Java Program Example - Java Import Packages *
      package YOUR_CUSTOM_PACKAGE HERE;
    • Your solution, regardless of how many classes it has, should be in one .java file.
    • Your solution has to run on any online IDEs.
    • If your solution fails the platform-independence criteria, you will have to resubmit work subject to the late penalty.
    • The Late Work policy applies for all late submissions.

(10 points) Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our 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}.

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 HomeworkAssignment5_2 {    
   public static void main(String[] args) {
      // just like any problems, whatever you need here, etc.
   }
}
class Solution {
   // YOUR STYLING DOCUMENTATION GOES HERE
   public boolean canDistribute(int[] resources, int groups) { 
      // YOUR CODE HERE 
   }
}

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

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

input: {1}, 4

output: false

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

CONSTRAINTS / ASSUMPTIONS

  • 0 < resources.length() < 1000.
  • 0 < medical facilities < 1000.
  • A sub-divided facility is never empty.
  • The solution method returns false if resources cannot be evenly distributed, true otherwise.
  • There may be more than one ways to sub-divide a given set of resources into k facilities. Doesn't matter. Your solution should return true in that case.
  • You will use a Recursion for this. Failure to do so received -4 points.

HINT

  • 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.

Solutions

Expert Solution


Related Solutions

Your company has developed a new videoconference gaming platform that allows players to see and hear...
Your company has developed a new videoconference gaming platform that allows players to see and hear their friends while they play together remotely. The sales can be modeled by q(p)= 350000-2430p^2 where p is the price of the app in dollars and q is the number of user accounts sold, and the cost of production is C(q)= 3q+4500 Do all your work neatly labeled on your own paper.   a. Write the revenue function R(p) b. Write the cost function C(p)...
An researcher wishes to see if the primary way people obtain information is independent of their...
An researcher wishes to see if the primary way people obtain information is independent of their highest level of education. A survey of 400 high school and college graduates yielded the following information. At the  = 0.05 significance level, test the claim that the way people obtained information is independent of their education level. - A clear statement of hypotheses    - An indication of the test being used    - Statement of the test statistic and either p-value (or appropriate...
An instructor wishes to see if the way people obtain information is independent of their educational...
An instructor wishes to see if the way people obtain information is independent of their educational background. A survey of 400 high school and college graduates yielded this information. At a=5%, test the claim that the way people obtain information is independent of their educational background. Table: Television newspaper other sources high school 159 90 51 college 27 42 31 College 27 42 31
#1)  An researcher  wishes to see if the primary way people obtain information is independent of their highest...
#1)  An researcher  wishes to see if the primary way people obtain information is independent of their highest level of education. A survey of 400 high school and college graduates yielded the following information. At the a = 0.05 significance level, test the claim that the way people obtained information is independent of their education level.                          TV        Newspaper      Other sources      High school                        163            30                  52             College                        37             65                  53    - A clear statement of hypotheses    - An indication of the test being used    - Statement of the test statistic and...
For each of the studies, please indicate the following: a) Independent variable(s) b) Is there more...
For each of the studies, please indicate the following: a) Independent variable(s) b) Is there more than one independent variable? c) Levels of the independent variable d) Dependent variable                      e) Level of measurement of the DV Will students to do better in school if you “pay for grades”? To test this question, an instructor gives students a math test. Before taking the test, half the students were told that they would receive $0.25 for every correct answer. The other half...
Your solution must include all supporting calculations and these supporting calculations must be performed with appropriate...
Your solution must include all supporting calculations and these supporting calculations must be performed with appropriate Excel formulas. Failure to do so will result in a reduction in points. For each case, you must submit one printed copy of the Excel spreadsheet which contains your case solution and a second printed copy displaying the formulas contained in each cell of the spreadsheet. Be sure to format your spreadsheet so that your work is clearly presented and easy to review. Wright...
PLEASE NO PLAGIARISM AND MUST BE IN YOUR OWN WORDS You must write a minimum of...
PLEASE NO PLAGIARISM AND MUST BE IN YOUR OWN WORDS You must write a minimum of two paragraphs and every paragraph should have at least four complete sentences. What is risk management? What is Vulnerability assessment? Thanks!!
PLEASE NO PLAGIARISM AND MUST BE IN YOUR OWN WORDS You must write a minimum of...
PLEASE NO PLAGIARISM AND MUST BE IN YOUR OWN WORDS You must write a minimum of two paragraphs and every paragraph should have at least four complete sentences. What is the difference between security and safety? What is the relationship between risk management and vulnerability assessment? Thank!!
Renewable Energy question: (PLEASE provide me with TYPED solution) ********* PLEASE TYPE YOUR SOLUTION ************ I...
Renewable Energy question: (PLEASE provide me with TYPED solution) ********* PLEASE TYPE YOUR SOLUTION ************ I lost one question because I could not read the hand writing of the solution that somone provided, so please type yours. Thank you. #. Solar heat harvesting makes use of what three modes of heat distribution? How does each work?
RENEWABLE ENERGY QUESTION : *************(PLEASE provide me with typed solution)*************** PLEASE TYPE YOUR SOLUTION. Do Not...
RENEWABLE ENERGY QUESTION : *************(PLEASE provide me with typed solution)*************** PLEASE TYPE YOUR SOLUTION. Do Not Provide Hand-Written solution Please. Q) Which state in the United States would be the best one to harvest wind power? Why? (Don’t forget to include the state’s shoreline in this decision).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT