Practical 10

/*Create array of 5 items.Pass item name,qty,rate.Calculate and display net amount for each iteam.Also display iteam having highest net amount.*/

import java.io.*;
class net_amt
{
public static void main(String args[]) throws IOException
{
int qty[],rt[],amt[];
String inm[],mnm;
int maxq,maxr,maxa,i;
qty=new int[5];
rt=new int[5];
amt=new int[5];
inm=new String[5];
DataInputStream in=new DataInputStream(System.in);
for(i=0;i<5;i++)
{
System.out.print("Enter Iteam "+(i+1)+" Name ");
inm[i]=in.readLine();
System.out.print("Enter Iteam "+(i+1)+" Quantity ");
qty[i]=Integer.parseInt(in.readLine());
System.out.print("Enter Iteam "+(i+1)+" Rate ");
rt[i]=Integer.parseInt(in.readLine());
amt[i]+=(qty[i]*rt[i]);
}
System.out.println("Name \tQty \tRate \tNet Amount");
for(i=0;i<5;i++)
{
System.out.println(inm[i]+" \t"+qty[i]+" \t"+rt[i]+" \t"+amt[i]);
}
maxa=maxq=maxr=0;
maxa=amt[0];maxq=qty[0];maxr=rt[0];mnm=inm[0];
for(i=1;i<5;i++)
{
if(maxa<amt[i])
{
maxa=amt[i];maxq=qty[i];maxr=rt[i];mnm=inm[i];
}
}
System.out.println("Highest Net Amount Having Iteam is "+mnm+".");
}
}

Output:-

Comments

Popular Posts