-3

I have this code that I'm producing...

I want to show the results as follows:

1) output to a .PDF & .TXT file. 2) Create a Bar Chart (in color) of the results.

Is this possible?

 import javax.swing.JOptionPane;

    public class TEXTTEXT_BarChart {
        public static void main(String[] args) {

            int numberOfStores = 5;
            String userStringInput;
            double storeSales;
            int numberofHundredDollarDivisions;
            String outputString = "SALES BAR CHART\n";

            for (int store = 1; store <= numberOfStores; store++) {
                userStringInput = JOptionPane.showInputDialog("Enter today's sales for store " + store);
                storeSales = Double.parseDouble(userStringInput);
                numberofHundredDollarDivisions = (int) (storeSales / 100);
                outputString += "Store" + store + ": ";
                for (int printAsterisk = 1; printAsterisk <= numberofHundredDollarDivisions; printAsterisk++) {
                    outputString += "*";
                }
                outputString += "\n";
            }
            JOptionPane.showMessageDialog(null, outputString);
            System.exit(0);
        }
    }
dhoctran
  • 3
  • 3

1 Answers1

-1

To answer you first question, you can use itext dependencies for creating pdf documents

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.5.10</version>
</dependency>

Check this tutorial for creating a pdf file programmatically.
And to write the txt file you can directly use the FileOutputStream . Again you can refer this tutorial

For 2nd question you can use JFreeChart

Lokesh Pandey
  • 1,739
  • 23
  • 50