Question: Using Java in netbeans The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is
Using Java in netbeans
The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is when the insert method returns an object from the last element of the AssemblyLine's encapsulated array, what about those ManufacturedProduct objects that are "left hanging" in the array because they never got to the last element position? How do we get them out?
Lab B is to modify your project so you can deal with the above problem and return those objects.
Code:
Manufactured Product Class:
import java.util.Random;
public class ManufacturedProduct
private int productId;
private boolean passedInspection;
Constructor
public ManufacturedProductint productId
this.productId productId;
Set a default value for inspection true or false
this.passedInspection inspectProduct;
Getter for productId
public int getProductId
return productId;
Inspection method
public void inspection
this.passedInspection inspectProduct;
toString method
@Override
public String toString
return "ManufacturedProduct
"productId productId
passedInspection passedInspection
;
Private method to simulate inspection
private boolean inspectProduct
Random random new Random;
int randomNumber random.nextInt;
return randomNumber ;
AssemblyLine Class:
public class AssemblyLine
private ManufacturedProduct assemblyLineArray;
Constructor
public AssemblyLine
this.assemblyLineArray new ManufacturedProduct;
Insert method
public ManufacturedProduct insertManufacturedProduct newProduct
Shift elements up
for int i assemblyLineArray.length ; i ; i
assemblyLineArrayi assemblyLineArrayi ;
Add the new product to the first position
assemblyLineArray newProduct;
Return the last element of the array element
return assemblyLineArrayassemblyLineArraylength ;
AssemblyLineTest Class:
public class AssemblyLineTest
public static void mainString args
AssemblyLine assemblyLine new AssemblyLine;
Insert ManufacturedProduct objects into the AssemblyLine
for int i ; i ; i
ManufacturedProduct product new ManufacturedProducti;
assemblyLine.insertproduct;
Display a report on each object
System.out.printlnReport for ManufacturedProduct # i :;
System.out.printlnproduct;
System.out.println;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
