i need help fix what the teacher want here the teacher feedback As you can see,
ID: 3912176 • Letter: I
Question
i need help fix what the teacher want here the teacher feedback
As you can see, since you're now shoving objects, instead of nulls, out of the AssemblyLine we're now getting reports on the objects in the AssemblyLine.
However, the big problem is that you didn't really implement the AssemblyLine class as a queue. Take a look at the Queue class -- and particularly it's insert method -- on page 138 of the book
This is the assignment question below.
Create an AssemblyLine class. An assembly line is, of course, a good real-world representation of a queue.
The AssemblyLine class has an encapsulated ManufacturedProduct array with five elements. Each element represents a position on an actual assembly line.
Give the AssemblyLine class a public insert method that adds a ManufacturedProduct object to element zero the ManufacturedProduct array. If any objects are already in the array, shift all of them one element 'up' the ManufacturedProduct array.
Example:
We are adding a ManufacturedProduct object to the array. However, we already have an object in the array. The new object occupies element zero in the array and the old object shifts up to element one.
Then we insert another object. The new object goes into element zero. The object we inserted previously shifts up to element one. And the first object now occupies element two.
etc.
The insert method should also return a ManufacturedProduct object. However, it will only return the ManufacturedProduct object that is currently the object in element four of the ManufacturedProduct array. Otherwise, it will return a null.
Example:
We have five objects in the five element ManufacturedProduct array. When a sixth object is added, it goes to element zero and all of the objects in the array shift up one in the element count -- except for the object in element number four, which is actually returned by the insert method.
The only way to add or return an element from the array should be via the insert method.
Remember that you should inspect each ManufacturedProduct object when they are finally returned by the insert method.
code:
public class AssemblyLine
{
ManufacturedProduct products[];
int n;
public AssemblyLine()
{
products= new ManufacturedProduct[5];
n=0;
}
public ManufacturedProduct insert(ManufacturedProduct p)
{
int x=n;
ManufacturedProduct t= products[4];
while(x>0)
{
products[x]=products[--x];
}
products[0]=p;
n++;
if(t!=null) t.inspection();
return t;
}
public ManufacturedProduct remove()
{ return products[--n];}
//--------------------------------------------------------------
}
public class AssemblyLineTest
{
public static void main(String a[])
{
KandelHeading.getHeader("Lab 4B"); //using my header
AssemblyLine l = new AssemblyLine();
System.out.println(l.insert(new ManufacturedProduct(1)));
System.out.println(l.insert(new ManufacturedProduct(2)));
System.out.println(l.insert(new ManufacturedProduct(3)));
System.out.println(l.insert(new ManufacturedProduct(4)));
}
}
// Insert only 5 elements and if u want more then increase array capacity
import java.util.*;
public class ManufacturedProduct
{
private int productId;
private boolean passedInspection;
public ManufacturedProduct(int id)
{
productId=id;
passedInspection= true;
}
int getProductId()
{
return productId;
}
public void inspection()
{
Random rand = new Random();
int n = rand.nextInt(19);
if(n==0) passedInspection=false;
}
public String toString()
{
return productId+" "+passedInspection;
}
}
here the page he talking about
prvate lonpll private int front ewate int rear rvate int nitens /I constructor oiblic Qeve int s) queArray - new longmaxsize]; frant rear1 nitens0 public void insert (long j) put item at rear of queue if rear-: maxSize-1) / deal with wraparound rear1; queArrayl++rear-j; nItems++ I increment rear and insert /I one more item public long renove() II take item from front of queue tenp=queArray[front++1; // get value and inc iffront maxSize) r front front I deal with wraparound return temp /I one less item uliconoExplanation / Answer
Please replace your insert method with the below method and it will work as suggested.
public ManufacturedProduct insert (ManufacturedProduct p)
{
ManufacturedProduct t = products[4];
int x;
// Putting a condition here because if the queue is full
// we will start with element at index 4 for swapping to avoid out of index error
if(n == 5)
{
x = n - 1;
}
else
{
x = n;
}
while (x > 0)
{
products[x] = products[--x];
}
products[0] = p;
// Once the queue is full, there is no need to increment the n value.
if(n < 5)
{
n++;
}
if (t != null)
t.inspection();
return t;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.