a collector wanted to create a wishlist items he wants to buy, but when he was s
ID: 3794475 • Letter: A
Question
a collector wanted to create a wishlist items he wants to buy, but when he was shopping at the online store can only be wishlist each application that he wants is to be noted for all online and offline stores. you are asked to make a program to combine the wishlist with the following conditions: 1. the user is asked to input how many kinds of items to be purchased 2. The user is prompted to input the name of the goods, the store name, price and date of purchase (repeated as many types of goods previously inputted) 3. The program will calculate the total price of goods bought 4. after all items terinput program will display all the names of goods and pricing, name store and date of purchase plus the total value of expenditure a collector wanted to create a wishlist items he wants to buy, but when he was shopping at the online store can only be wishlist each application that he wants is to be noted for all online and offline stores. you are asked to make a program to combine the wishlist with the following conditions: 1. the user is asked to input how many kinds of items to be purchased 2. The user is prompted to input the name of the goods, the store name, price and date of purchase (repeated as many types of goods previously inputted) 3. The program will calculate the total price of goods bought 4. after all items terinput program will display all the names of goods and pricing, name store and date of purchase plus the total value of expenditure 1. the user is asked to input how many kinds of items to be purchased 2. The user is prompted to input the name of the goods, the store name, price and date of purchase (repeated as many types of goods previously inputted) 3. The program will calculate the total price of goods bought 4. after all items terinput program will display all the names of goods and pricing, name store and date of purchase plus the total value of expenditureExplanation / Answer
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 price store date");
for(Goods x: al)
{
System.out.println(x.getNameOfGoods()+" "+x.getPrice()+" "+x.getStoreName()+" "+x.getDate());
}
System.out.println("Total: "+total(al));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.