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

Once items are loaded in a truck, if a stack is used, the last item will be unlo

ID: 3631984 • Letter: O

Question

Once items are loaded in a truck, if a stack is used, the last item will be unloaded first, and if a queue is used, the first item will be unloaded.
Hint: use class java.util.Stack and interface java.util.Queue<E>. Note that E denotes the type of elements held in the collection of Queue. The interface should be either implemented in your class creation or type-casted from class LinkedList. So, it will be in the following statement:

Queue<TruckItem> item = new LinkedList<TruckItem>();

So far, 1) load and 2) unload work well. However, “3) display current state” needs to be implemented more accurately. To do so, import java.util.Iterator and use the method hasNext().



import java.awt.*;
import java.util.ArrayList; // to enable ArrayList

public class TruckItem {
String name;
double price;
boolean delivered;
TruckItem truck;
int itemLeftForDelivery = 0;
private ArrayList<TruckItem> aTruck = new ArrayList<TruckItem>();

//Constructor
public TruckItem(String nm, double pc, int g){
name = nm;
price = pc;
delivered = false;
int given;
}
// Accessor Methods
public String getName(){return name;}
public double getPrice(){return price;}
public boolean setDelivery(){return true;}
}





import java.awt.*;
import java.util.Scanner; //Scanner for user input
import java.util.ArrayList; // to utilize and ArrayList
import java.io.*; // To catch IOExceptions

public class Delivery {
public static void main(String args[]) throws IOException{

Scanner s = new Scanner(System.in);
ArrayList<TruckItem> aTruck = new ArrayList<TruckItem>();
//TruckItem Array

int options;
int itemCount = 0;
int max_items = 5; //maximum items allowed on the truck
int unLoader;

System.out.println("Choose an Options (1) Load (2) Unload (3) Get Truck Status (4) Exit"); // Display options to user
options = s.nextInt();

switch(options){
/* Case 1(Load), if user selects option 1, the prompt will ask to enter item name and *price upon
* Receiving the information a TruckItem will be loaded into the array
* and the itemCount will be index++
*/
case 1:
if(options == 1 && aTruck.size() <= max_items){
String nm;
double pc;
System.out.println("Enter Item Name: ");
nm = s.next();
System.out.println("Enter Price: ");
pc = s.nextDouble();
itemCount++;
} else
{ if(aTruck.size() == max_items){
System.out.println("*** Truck is full 5 out of 5 Items Loaded ***");
}
}break;

/* Case 2(unload), if user selects option 2, the prompt will display items currently in the truck
*The display will show index + 1 and the item name and price
*the user will then be allowed to select the item they wish to remove from the truck */
case 2:
if(options == 2){
System.out.println("** Items On Truck **");
for(int index = 0; index < aTruck.size(); index++){
System.out.println("("+(index +1)+")" + "/t" + aTruck.get(index).name
+ aTruck.get(index).price );
}
System.out.println(" Choose and item to Unload ");
unLoader = s.nextInt();
aTruck.remove(unLoader);

}break;
/*
* Case 3 Get Truck Status, will display items on truck(name, price)
* then display how many items are left to be delivered
*/
case 3:
if(options == 3){
System.out.println("** Items to be Delivered **");
for(int index = 0; index < aTruck.size(); index++){
System.out.println("("+(index +1)+")" + "/t" + aTruck.get(index).name
+ aTruck.get(index).price );
System.out.println(aTruck.size() + " Items are left to be delivered ");
}
}break;

} while (options != 4); // The program will end when select exit.

}
}




Explanation / Answer

hey friend due to some upload problem , i'm not able to upload the solution . please rate me lifesaver and i'll make sure the solution is sent to ur email id. give me your email id too.

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