Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Enter the file name oftoday\'s sales for store 1: Store1.txt Enter the file name

ID: 3609490 • Letter: E

Question

Enter the file name oftoday's sales for store 1: Store1.txt
Enter the file name of today's sales for store 2: Store2.txt
Enter the file name of today's sales for store 3: Store3.txt
Enter the file name of today's sales for store 4: Store4.txt
Enter the name of the output file: Summary.txt


Note: A file named Summary.txt is created by the program asfollows.
[Begin of SalesSummary.txt]
PART I
BAR CHART
---------
Store 1: ***************
Store 2: ************
Store 3: ********************
Store 4: *****************

PART II
TODAY'S TOP STORE
-----------------
Store Name: Store 3
Number of Transactions: 25
Total Sales: $2,028

PART III(optional, 10bonus points)
SALES REPORT (sorted in descending order of total sales)
------------
Rank#1 Store:   Store 3
Rank#2 Store:   Store 4
Rank#3 Store:   Store 1
Rank#4 Store:   Store 2
[End of SalesSummary.txt]

Explanation / Answer

import java.util.*;
import java.io.*;
public class BarChart
{public static void main(String[] args)throwsFileNotFoundException

{int i;
String filename;
int stores=4;
String storename[]=new String[stores];
double total[]=new double[stores];
int trans[]=new int[stores];

Scanner key=newScanner(System.in); //BarChart.txt
System.out.println("Enter file name for store sales: ");
filename=key.next();
Scanner input=new Scanner(new File(filename)); //SalesReport.txt

System.out.println("Enterfile name for store sales report: ");
filename=key.next();
PrintStream output=new PrintStream(new File(filename));

graph(total,stores,output);
sort(storename,total,trans,stores);

output.println(" TodaysSales Summary: ");
for(i=0;i<stores;i++)
   output.println(storename[i]+" "+trans[i]+"   "+total[i]);

output.println(" Todays Top Store: ");
output.println("Name:                  "+storename[0]);
output.println("Number of Transactions: "+trans[0]);
output.println("Sales                  "+total[0]);


}
public static void sort(String storename[],double total[],inttrans[],int stores)
   {int i,j,t;
double t1;
String t2;
for(i=0;i<stores-1;i++)
     for(j=i;j<stores;j++)
       if(total[i]>total[j])
        {t=trans[i];
      trans[i]=trans[j];
      trans[j]=t;
      t1=total[i];
      total[i]=total[j];
      total[j]=t1;
      t2=storename[i];
      storename[i]=storename[j];
      storename[j]=t2;
     }
  return;
  }
  
public static void graph(double total[],int stores,PrintStreamoutput)
{int i,j,tot;
for(i=1;i<4;i++)
   {output.printf("%3d|",i);
tot=(int)(total[i]+.5);
    for(j=0;j<tot;j++)
        output.printf("*");
    output.printf("    | ");
    }    
return;
}


}