Computer Science, asked by rbrohan8510, 6 hours ago

Alex has a list of items to purchase at a market. Theowner offers to discount each item after the firstone by the lowest marked price among the prioritems. No item's price can be discounted below o,and the list of items may not be reorderedCalculate the payable amountExampleAlex pays 2 for the first item since there are noprevious items to compare toThe second item costs 5.23The third item is free, marri min(25) 0) = max 1The fourth item costs 13The total cost to purchase all items is 2+ 3+0+38The first item is never discounted and theminimum cost of any item is aFunction DescriptionComplete the function calculateAmount in theeditor below. The function must return Alex's total cost to purchase all the items.​

Answers

Answered by joymerlin2531
4

Answer:

Alex has a list of items to purchase at a market. Theowner offers to discount each item after the firstone by the lowest marked price among the prioritems. No item's price can be discounted below o,and the list of items may not be reorderedCalculate the payable amountExampleAlex pays 2 for the first item since there are noprevious items to compare toThe second item costs 5.23The third item is free, marri min(25) 0) = max 1The fourth item costs 13The total cost to purchase all items is 2+ 3+0+38The first item is never discounted and theminimum cost of any item is aFunction DescriptionComplete the function calculateAmount in theeditor below. The function must return Alex's total cost to purchase all the items.

Answered by shilpa85475
3

The owner offers to discount each item after the first one by the lowest marked price among the prior items.

No item's price can be discounted below o,and the list of items may not be reordered

Explanation:

import java.util.*;

public class abc

{

   public static void main (String[] args) {

       

       Scanner sc =new Scanner(System.in);

       

       int no_input=sc.nextInt();

       sc.nextLine();

       String input[]=new String[no_input];

       String input1[][]=new String[no_input][3];

       

       for(int i=0;i<no_input;i++)

       {

           input[i]=sc.nextLine();

           input1[i]=input[i].split(",");

       }

       

       int discount[]=new int[no_input];

       

       for(int i=0;i<no_input;i++)

       {

           discount[i]=(Integer.parseInt(input1[i][2])*Integer.parseInt(input1[i][1]))/100;

       }

       

       int min_dis=32767;//highest value that can be stored in Integer

       String output=new String();

       

       for(int i=0;i<input.length;i++)

       {

           if(min_dis>discount[i])

           {

               min_dis=discount[i];

           }

       }

       

       for(int i=0;i<input.length;i++)

       {

           if(discount[i]==min_dis)

           {

               output=output+input1[i][0]+" ";

           }

       }

       

       System.out.println(output);

   }

}

Similar questions