
write a program to store information of 50 products(code, quantity and price). Calculate the total cost (quantity*price) of each product and print the information.

import java.util.*;
class ShowData{
String code;
int quantity;
double price;
ShowData(String code,int quantity,double price){
this.code=code;
this.quantity=quantity;
this.price=price;
}
public void setCode(String code){
this.code = code;
}
public String getCode() {
return code;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getQuantity(){
return quantity;
}
public void setPrice(double price) {
this.price = price;
}
public double getPrice(){
return price;
}
}
public class ArrayListEx{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
ArrayList<ShowData> list=new ArrayList<ShowData>();
for(int i=0;i<50;i++){
System.out.print("Enter code: ");
String code=input.next();
System.out.print("Enter Quantity: ");
int quantity=input.nextInt();
System.out.print("Enter Price: ");
double price=input.nextDouble();
list.add(new ShowData(code,quantity,price));
}
for(ShowData data: list){
double cost=(data.getQuantity())*(data.getPrice());
System.out.println(data.getCode()+"\t "+data.getQuantity()+"\t "+data.getPrice()+"\t "+cost);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.