a collector wanted to create a wishlist items he wants to bu
Solution
The above problem I have solved using java
Created one java class which contains all given attribute
Created main class which takes input from user and set the value for GOODS class attribute
Created one object of ArrayList of type Goods class
Everytime user make entries for particular goods it is stored in ArrayList object
Then in last we retrieve values from ArrayList object and print in billing format and also prints total of all goods
/* program starts */
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Goods {
String NameOfGoods;
String StoreName;
double Price;
String date;
public String getNameOfGoods() {
return NameOfGoods;
}
public void setNameOfGoods(String nameOfGoods) {
NameOfGoods = nameOfGoods;
}
public String getStoreName() {
return StoreName;
}
public void setStoreName(String storeName) {
StoreName = storeName;
}
public double getPrice() {
return Price;
}
public void setPrice(double price) {
Price = price;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
class Main
{
public static double total(ArrayList<Goods> al )
{
double sum = 0;
for(Goods x:al)
{
sum+=x.getPrice();
}
return sum;
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.print(\"enter number of items: \");
int N = Integer.parseInt(br.readLine());
//sc.next();
ArrayList<Goods> al = new ArrayList();
while(N-->0)
{
System.out.println(\"enter the name of goods:\");
String nameOfGoods = br.readLine().toString();
System.out.println(\"enter the name of store:\");
String storeName = br.readLine().toString();
System.out.println(\"enter price for goods:\");
double price = Double.parseDouble(br.readLine().toString());
System.out.println(\"enter the date of purchase: \");
String date = br.readLine().toString();
Goods goods = new Goods();
goods.setNameOfGoods(nameOfGoods);
goods.setStoreName(storeName);
goods.setPrice(price);
goods.setDate(date);
al.add(goods);
}
System.out.println(\"Name\\t\\tprice\\t\\tstore\\t\\tdate\");
for(Goods x: al)
{
System.out.println(x.getNameOfGoods()+\"\\t\\t\"+x.getPrice()+\"\\t\\t\"+x.getStoreName()+\"\\t\\t\"+x.getDate());
}
System.out.println(\"Total:\\t\\t\\t\"+total(al));
}
}


