Question: Write a Java program that analyzes a JSON file containing sales data. Each sale has an item ID , quantity sold, and total price. The

Write a Java program that analyzes a JSON file containing sales data. Each sale has an item ID,quantity sold, and total price. The program should:
Calculate and display the total sales amount. Determine the item that sold the most units. Write a summary report to a new text file (sales_report.txt).
The summary report should include:
The sum of the total prices for all sales.
The total quantity of all items sold.
The item that has the highest quantity sold, along with its ID and quantity.
A breakdown of sales for each item (item ID,quantity sold, total price).
The date when the report is generated.
Json file: [
{
"sale": {
"itemId": 1,
"itemName": "Laptop",
"quantitySold": 3,
"totalPrice": 2999.97
}
},
{
"sale": {
"itemId": 2,
"itemName": "Smartphone",
"quantitySold": 5,
"totalPrice": 2499.95
}
},
{
"sale": {
"itemId": 3,
"itemName": "Headphones",
"quantitySold": 2,
"totalPrice": 179.98
}
},
{
"sale": {
"itemId": 4,
"itemName": "Smartwatch",
"quantitySold": 4,
"totalPrice": 799.96
}
},
{
"sale": {
"itemId": 5,
"itemName": "Tablet",
"quantitySold": 1,
"totalPrice": 299.99
}
},
{
"sale": {
"itemId": 6,
"itemName": "Camera",
"quantitySold": 6,
"totalPrice": 4199.94
}
},
{
"sale": {
"itemId": 7,
"itemName": "Printer",
"quantitySold": 2,
"totalPrice": 259.98
}
},
{
"sale": {
"itemId": 8,
"itemName": "Monitor",
"quantitySold": 3,
"totalPrice": 749.97
}
},
{
"sale": {
"itemId": 9,
"itemName": "Bluetooth Speaker",
"quantitySold": 10,
"totalPrice": 799.90
}
},
{
"sale": {
"itemId": 10,
"itemName": "Gaming Mouse",
"quantitySold": 5,
"totalPrice": 249.95
}
}
]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!