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

Write a function plotCDPrices(cds) that plots for you the prices of all your cds

ID: 656489 • Letter: W

Question

Write a function plotCDPrices(cds) that plots for you the prices of all your cds in ascending order (smallest to largest). Add a title to this plot. This function again takes an array of CD structures like the one you create in your test function.

Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );
Write a function plotCDPrices(cds) that plots for you the prices of all your cds in ascending order (smallest to largest). Add a title to this plot. This function again takes an array of CD structures like the one you create in your test function.

Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );
Write a function plotCDPrices(cds) that plots for you the prices of all your cds in ascending order (smallest to largest). Add a title to this plot. This function again takes an array of CD structures like the one you create in your test function.

Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );

Explanation / Answer

import java.util.*;

public class Plot {
static HashMap h[]=new HashMap[10];
public static void main(String args[]){
try{
   for(int i=0;i<=9;i++)
       h[i] = new HashMap();

   h[0].put("name","Blues");
   h[0].put("price","18.95");

   h[1].put("name","Classical");
   h[1].put("price","14.49");

   h[2].put("name","Country");
   h[2].put("price","13.49");
  
   h[3].put("name","Latin");
   h[3].put("price","12.15");
  
   h[4].put("name","Rock/Pop");
   h[4].put("price","13.49");
  
   h[5].put("name","R & B");
   h[5].put("price","13.49");
  
   h[6].put("name","Rap");
   h[6].put("price","15.75");
  
   h[7].put("name","Jazz");
   h[7].put("price","12.48");
  
   h[8].put("name","Dance");
   h[8].put("price","14.56");
  
   h[9].put("name","Rock");
   h[9].put("price","11.31");

   plotCDPrices(h);
  

}
catch(Exception e){
System.out.println(e);
}
}
public static void plotCDPrices(HashMap h[]){
   HashMap temp = new HashMap();

   for(int i=0;i<=9;i++)
   for(int j=0;j<i;j++)
   {
   double a1 = Double.parseDouble((String)h[i].get("price"));

   double a2 = Double.parseDouble((String)h[j].get("price"));  
       if( a1 < a2 )
       {
       temp = h[i];
       h[i] = h[j];
       h[j] = temp;  
  
       }
  
   }

   for(int i=0;i<=9;i++)
       System.out.print(h[i].get("price")+"("+h[i].get("name")+") ");

}


}

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