Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Resource Allocation The representative of Health Department of Texas wants to in

ID: 3920278 • Letter: R

Question

Resource Allocation The representative of Health Department of Texas wants to investigate the optimal allocation of orgarn procurement organizations (OPOs) for organ transplant. Location data Demand x int # 0 ???? 10.5 11 4 9 2.5 24 28.5 3 25 26 25.5 4 8 15 OPO2 13 -6 OPO14 32.5 5 OPO1 30.5 5.5 OPO2 20.5 -5.5 OP03 | 25.5 | 3.5 Q1 (40 points). Write a program that can assign all demand points to the nearest or the farthest OPO given the location information above Program requirements 1. The distance must be calculated as follows Distance between A and B(x of A -x of B)A2 (y of A y of B)A2 We assume the unit of distance is mile 2. The program asks the user to choose one of the allocation rules specified below: (1) Rule 1: All demand points are assigned to the nearest OPO (2) Rule 2: All demand points are assigned to the farthest OPO 3. After the user chooses the rule, the program allocates the demand points following the rule the user chooses and prints out the allocation results. 4. The program must check to be sure that the user input is valid. The program keeps displayinga warning message until the user puts a valid input. If the user repeatedly enters an invalid input more than 3 time, the program displays an error message and terminates. 5. Use selection(s), loop(s), and array(s). Sample Inputs/Outputs Chose an allocation rule: 1-nearest rule, or 2-farthest rule:3 Invalid input! try again! Chose an allocation rule: 1-nearest rule, or 2 - farthest rule: 1 Allocation Results: [1, 2, 3, 3, 2, 1, 1, 2, .] Q2 (20 points). Suppose OPO 1 can cover demand points only within 50 miles. Explain in 10 sentences (or less) how to modify your program code Q3 (20 points). Suppose OPO 2 can only cover points on the north of OPO 2. Explain in 10 sentences (or less) how to modify your program code

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

  

double demandX[] = {0, 9, 10, 10.5, 11, 18, 18, 21, 24, 28.5, 25, 26, 25.5, 30, 32.5};

double demandY[] = {0, 1, 8, 11, -5, 2.5, -7, -4, -15, 3, -9, -3, 4, -6, -5};

double OPOX[] = {30.5, 20.5, 25.5};

double OPOY[] ={-5.5, -5.5, 3.5};

  

Scanner sc = new Scanner(System.in);

int count = 0, choice = 0;

while(count<3&&(choice!=1&&choice!=2))

{

System.out.print("Chose an allocation rule: 1 - nearest rule, or 2 - farthest rule: ");

choice = sc.nextInt();

count++;

if(count<3&&choice!=1&&choice!=2)

System.out.println("Invalid input! try again!");

}

if(count>3||(count==3&&choice!=1&&choice!=2))

System.out.println("You have exceeded max selections. Good Bye!!");

else if(choice==1)

{

int[] allocation = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

double near;

  

for(int i=0; i<demandX.length; i++)

{

allocation[i] = 1;

near = (demandX[i]-OPOX[0])*(demandX[i]-OPOX[0]) + (demandY[i]-OPOY[0])*(demandY[i]-OPOY[0]);

if(near>(demandX[i]-OPOX[1])*(demandX[i]-OPOX[1]) + (demandY[i]-OPOY[1])*(demandY[i]-OPOY[1]))

{

allocation[i] = 2;

near = (demandX[i]-OPOX[1])*(demandX[i]-OPOX[1]) + (demandY[i]-OPOY[1])*(demandY[i]-OPOY[1]);

}

if(near>(demandX[i]-OPOX[2])*(demandX[i]-OPOX[2]) + (demandY[i]-OPOY[2])*(demandY[i]-OPOY[2]))

{

allocation[i] = 3;

near = (demandX[i]-OPOX[2])*(demandX[i]-OPOX[2]) + (demandY[i]-OPOY[2])*(demandY[i]-OPOY[2]);

}

}

  

System.out.print("Allocation Results: [ " + allocation[0]);

for(int i=1; i<allocation.length; i++)

System.out.print(", " + allocation[i]);

System.out.println(" ]");

}

else if(choice==2)

{

int[] allocation = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

double far;

for(int i=0; i<demandX.length; i++)

{

allocation[i] = 1;

far = (demandX[i]-OPOX[0])*(demandX[i]-OPOX[0]) + (demandY[i]-OPOY[0])*(demandY[i]-OPOY[0]);

if(far<(demandX[i]-OPOX[1])*(demandX[i]-OPOX[1]) + (demandY[i]-OPOY[1])*(demandY[i]-OPOY[1]))

{

allocation[i] = 2;

far = (demandX[i]-OPOX[1])*(demandX[i]-OPOX[1]) + (demandY[i]-OPOY[1])*(demandY[i]-OPOY[1]);

}

if(far<(demandX[i]-OPOX[2])*(demandX[i]-OPOX[2]) + (demandY[i]-OPOY[2])*(demandY[i]-OPOY[2]))

{

allocation[i] = 3;

far = (demandX[i]-OPOX[2])*(demandX[i]-OPOX[2]) + (demandY[i]-OPOY[2])*(demandY[i]-OPOY[2]);

}

}

System.out.print("Allocation Results: [ " + allocation[0]);

for(int i=1; i<allocation.length; i++)

System.out.print(", " + allocation[i]);

System.out.println(" ]");

}

sc.close();

}

}

The modification will be as follows:

2Q.

for (int i = 0; i<15; i++)

{

                double min = 1000;

                int mini = 0;

                for (int j = 0; j<3; j++)

{

                    double d = Math.sqrt((x[i] - opox[j]) * (x[i] - opox[j]) + (y[i] - opoy[j]) * (y[i] - opoy[j]));

                    if ( j == 0 && d > 50)

{

                        continue;

                    }

                    if (d < min)

{

                       min = d;

                       mini = j;

                    }

                }

                assign[i] = mini + 1;

          if (i < 14)

                   System.out.print(assign[i] + ",");

                else

                   System.out.print(assign[i] );

           }

3Q.

   for (int i = 0; i<15; i++)

{
                double min = 1000;
                int mini = 0;
                for (int j = 0; j<3; j++)

{
                    if ( j == 1 && y[i] <= opoy[j])

{
                        continue;
                    }
                    double d = Math.sqrt((x[i] - opox[j]) * (x[i] - opox[j]) + (y[i] - opoy[j]) * (y[i] - opoy[j]));
                    if (d < min)

{
                       min = d;
                       mini = j;
                    }
                }
                assign[i] = mini + 1;
           
                if (i < 14)

System.out.print(assign[i] + ",");

else
                  System.out.print(assign[i] );
         

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote