Dr Conlys beverage cellar needs to be organized He wants a p


Dr. Conly\'s beverage cellar needs to be organized. He wants a program that can sort his beverage in order of quantity from largest to smallest. Write a function order (string 1) data) the processes the list of beverage from main. Each string in data contains a beverage and a quantity in the following format: beverage_name: quantity The function should print the beverage in order of quantity from largest to smallest like this: Brasserie De Silly - Scotch Silly, Burgundy Bbl. Aged. 6 Boon Brewery - 2012 Geuze Mariage Parfait: 5 Brouwerij Van Steenberge - de Garre: 4 The Bruery - Smokey and the Bois: 3 Collective Brewing Project - American Sour Red: 2 Jolly Pumpkin Artisan Ales - Oro de Calabaza: 1

Solution

void order(String data[]){
       String[] quantity = new String[data.length];
       int index = 0;
       for(String val : data){
           quantity[index] = val.substring(val.lastIndexOf(\":\"),val.length());
       //   beverages[index] = val.substring(0,val.lastIndexOf(\":\"));
           index++;
       }
       for(int i : data.length-1){
           for(int j : data.length){
               if(quantity[i]>quantity[j]){
                   int t= quantity[i];
                   quantity[i]=quantity[j];
                   quantity[j]=t;
                   String x = data[i];
                   data[i] = data[j];
                   data[j]=x;
               }
           }
       }
   }

 Dr. Conly\'s beverage cellar needs to be organized. He wants a program that can sort his beverage in order of quantity from largest to smallest. Write a functi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site