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

ACME Manufacturing Company randomly selects one of its four factories to inspect

ID: 3558510 • Letter: A

Question

ACME 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 confident that the factory selection is random.

Save the file as Inspections.java.

Write it with two classes. One for the user interface, one that produces the Inspection Schedule and the percentages that each factory will be inspected for the year.

      2. User interface class is written as a JApplet

Explanation / Answer

import java.applet.Applet;

import java.awt.Graphics;

public class AcmeManufacturing extends Applet{

FactoryPercentage factoryPercentage=new FactoryPercentage();

int factory;

public static final int noOfWeeks=10;

public void paint(Graphics g) {

int factory1=0;

int factory2=0;

int factory3=0;

int factory4=0;

int j=20;

for(int i=0;i<noOfWeeks;i++,j+=15)

{

factory = 1 + (int) (Math.random() * 4);

if(factory==1)

{

factory1++;

}

else if(factory==2)

{

factory2++;

}

else if(factory==3)

{

factory3++;

}

else if(factory==4)

{

factory4++;

}

g.drawString("Inspecting Factory : Week "+(i+1)+": Factory "+factory,50,j);

}

j=j+15;

g.drawString("---------------------",50,j+15);

g.drawString("Average",50,j+30);

g.drawString("---------------------",50,j+45);

g.drawString("Factory 1:"+factoryPercentage.findAverage(factory1),50,j+60);

g.drawString("Factory 2:"+factoryPercentage.findAverage(factory2),50,j+75);

g.drawString("Factory 3:"+factoryPercentage.findAverage(factory3),50,j+90);

g.drawString("Factory 4:"+factoryPercentage.findAverage(factory4),50,j+105);

}

}

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