Question: To do: We will now write a driver using ArrayLists for our Drink class from #14 above. Make a copy of the DrinkDriverArray and name

To do: We will now write a driver using ArrayLists for our Drink class from #14 above. Make a copy of theDrinkDriverArray and name it DrinkDriverArrayList. Convert this program from an array collection to an ArrayList. You do not need to make any changes in the Drink program (that one blueprint will work for both drivers or any type of collection). We want it to use an ArrayList instead of an array.

To do: We will now write a driver using ArrayLists for our

public class DrinkDriverArray{

public static void main(String[] args){

Drink[] DrinkDriverArray = new Drink[20];

Scanner sc = new Scanner(System.in);

int count = 0;

for (int i = 0; i

DrinkDriverArray[i] = new Drink();

System.out.println("Enter the type of drink");

DrinkDriverArray[i].setType(sc.nextLine());

System.out.println("What size?(S,M or L)");

DrinkDriverArray[i].setSize(sc.nextLine().charAt(0));

System.out.println("Enter the cost of each drink");

DrinkDriverArray[i].setCost(Double.parseDouble(sc.nextLine()));

System.out.println("Enter number of these drinks purchased");

DrinkDriverArray[i].setNumOrdered(Integer.parseInt(sc.nextLine()));

System.out.println("Enter another drink order? (yes or no)");

String ch = sc.nextLine();

count++;

if (ch.equals("no"))

break;

}

System.out.println("The orders are:");

double totalCostPurchased = 0;

for (int i = 0; i

String type = DrinkDriverArray[i].getType();

int n = DrinkDriverArray[i].getNumOrdered();

String size = "";

if (DrinkDriverArray[i].getSize() == 'L')

size = "Large";

if (DrinkDriverArray[i].getSize() == 'M')

size = "Medium";

if (DrinkDriverArray[i].getSize() == 'S')

size = "Small";

double cost = DrinkDriverArray[i].getCost();

double totalCost = DrinkDriverArray[i].getCost() * DrinkDriverArray[i].getNumOrdered();

totalCostPurchased = totalCostPurchased + totalCost;

System.out.printf("You ordered %d %s %s at $%.2f for each drink. The total cost was %.2f ",n,size,type,cost,totalCost);

}

System.out.printf("The cost of total order purchased for all orders is $%.2f ",totalCostPurchased);

}

}

Java Class GDrinkDriverArrayList itp 120mod5ANSWERS17_18 DrinkDriverArrayList0 Omain(Stringl)void printOrders(ArrayList sDrinkshvoid totalNum(ArrayListDrinks>)int

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!