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

Pickering Manufacturing Company randomly selects one of its four factories to in

ID: 3558452 • Letter: P

Question

Pickering Manufacturing Company randomly selects one of its four factories to inspect
each week. Write an application that determines which factory will be selected each
week for the next 52 weeks. Use the Math.random() function explained in Appendix D
to generate a factory number between 1 and 4; you use a statement similar to:
factory = 1 + (int) (Math.random() * 4);
After each selection, display the factory to inspect, and after the 52 selections are
complete, display the percentage of inspections at each factory for the year. Run the
application several times until you are

Explanation / Answer

public class Factory {
public static void main(String [] args) {
int [] count = new int[4];
   for (int i = 0; i < 52; i++) {
int factory = (int) (Math.random() * 4);
   count[factory]++;
   System.out.println("Week: " + (i + 1) + ", Factory " + (factory + 1) + " Selected.");
   }
   for (int i = 0; i < 4; i++) {
double p = 100.0 * count[i] / 52.0;
   System.out.println("Factory " + (i + 1) + " is selected in " + p + "% cases.");
   }
}
}