This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

Please help me (Data mining Program)

Anthony_Reaper
Anthony_Reaper Member Posts: 17
edited May 27, 2015 5:11PM in New To Java

Hey guys I am needing to create a data mining program in Java code. I am using NetBeans and created a JavaFX application. I need this program to read a file, analyze the data (calculate percentages based on total sales of each group to overall sales of company, and add an organizational value code to each group), then write this information to a new file. So far I have been able to code to find the file and open it but I cannot figure out how to do the analysis portion. Could you please help me figure this out. I have attached the code I have come up with so far.

 

package businesssalesdataanalysis;

 

 

import javafx.application.Application;

 

import javafx.event.ActionEvent;

 

import javafx.event.EventHandler;

 

import javafx.geometry.Insets;

 

import javafx.scene.Scene;

 

import javafx.scene.control.Button;

 

import javafx.scene.layout.Pane;

 

import javafx.scene.layout.GridPane;

 

import javafx.scene.layout.VBox;

 

import javafx.stage.Stage;

 

import javafx.stage.FileChooser;

 

import java.awt.Desktop;

 

import java.io.File;

 

import java.io.IOException;

 

import java.util.logging.Level;

 

import java.util.logging.Logger;

 

 

 

/**

 

*

 

* @author Anthony

 

*/

 

public final class BusinessSalesDataAnalysis extends Application {

 

      

 

    private final Desktop desktop = Desktop.getDesktop();

 

   

 

    @Override

 

    public void start(final Stage primaryStage) {

 

        primaryStage.setTitle("Business Sales Data Analysis");

 

       

 

        final FileChooser fileChooser = new FileChooser();

 

       

 

        final Button uploadButton = new Button("Upload a file");

 

       

 

        uploadButton.setOnAction(

 

                new EventHandler<ActionEvent>(){

 

                    @Override

 

                    public void handle(final ActionEvent e){

 

                        configureFileChooser(fileChooser);

 

                        File file = fileChooser.showOpenDialog(primaryStage);

 

                        if (file != null){

 

                            openFile(file);

 

                        }

 

                    }

 

                });

 

 

        final GridPane inputGridPane = new GridPane();

 

       

 

        GridPane.setConstraints(uploadButton, 100, 50);

 

        inputGridPane.setHgap(6);

 

        inputGridPane.setVgap(6);

 

        inputGridPane.getChildren().addAll(uploadButton);

 

       

 

        final Pane rootGroup = new VBox(12);

 

        rootGroup.getChildren().addAll(inputGridPane);

 

        rootGroup.setPadding(new Insets(12, 12, 12, 12));

 

       

 

        primaryStage.setScene(new Scene(rootGroup));

 

        primaryStage.show();

 

       

 

    }

 

 

    /**

 

     * @param args the command line arguments

 

     */

 

   

 

    public static void main(String[] args) {

 

        Application.launch(args);

 

    }

 

   

 

    private static void configureFileChooser(final FileChooser fileChooser){

 

        fileChooser.setTitle("Choose a File");

 

        fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));

 

       

 

        fileChooser.getExtensionFilters().addAll(

 

            new FileChooser.ExtensionFilter("All Files", "*.*"),

 

            new FileChooser.ExtensionFilter("DOC", ".doc"),

 

            new FileChooser.ExtensionFilter("DOCX", ".docx")

 

        );                      

 

    }

 

   

 

    private void openFile(File file){

 

        try{

 

            desktop.open(file);

 

        }

 

        catch (IOException ex){

 

            Logger.getLogger(BusinessSalesDataAnalysis.class.getName()).log(Level.SEVERE, null, ex);

 

        }

 

    }

 

   

 

}

 

Anthony_ReaperaJohny
«13

Answers

  • TPD-Opitz
    TPD-Opitz Dipl.-Ing, Dipl.-Inf GermanyMember Posts: 2,465 Silver Trophy
    edited May 25, 2015 12:25PM

    you should give your post a more specific name to make it more attractive to read for community members.

    Your business logic currently is desktop.open(file);

    l this causes the file to opem in the systems default application. Therefore its not quite helpfull.

    instead you need to transfer the the content of your data file into Java Objects.

    Unfortunately you did not tell what format your data files have. If you data file really is a MS office document (as the file extentions you coded indicate) then you should use the POI-Framefork. Of cause this will only hepl you to access the data. you still have to code the processing logic.

    please elaborate mor on the format of your data file.

    bye

    TPD

    Anthony_Reaper
  • Anthony_Reaper
    Anthony_Reaper Member Posts: 17
    edited May 25, 2015 12:30PM

    The data exists within a Microsoft Office text file.

    the data appears in the file as follows:

    Country name:      Total Sales:

    Germany               $562,000.00

    China                     $1,585,985.00

    America                 $5,285,025.00

    India                      $625,254.00

    Brazil                     $356,458.00

    Russia                   $212,845.00

    Canada                 $327,241.00

    Australia                $127,512.00

    France                  $562,251.00

    England                $954,265.00

    this is my test data file, I considered changing it to excel as it may be easier.

  • TPD-Opitz
    TPD-Opitz Dipl.-Ing, Dipl.-Inf GermanyMember Posts: 2,465 Silver Trophy
    edited May 25, 2015 12:35PM
    b22c36cf-64c5-485f-bc4f-820427531df0 wrote:
    
    The data exists within a Microsoft Office text file.
    
    this is my test data file, I considered changing it to excel as it may be easier.
    

    You should consider to change it to a plain text format like CSV or XML or JSON since it is both even easier and less platform dependend.

    bye

    TPD

    Anthony_Reaper
  • Anthony_Reaper
    Anthony_Reaper Member Posts: 17
    edited May 25, 2015 12:38PM

    I think I will try a CSV file format, it does seems as though it would make things a little easier.

  • TPD-Opitz
    TPD-Opitz Dipl.-Ing, Dipl.-Inf GermanyMember Posts: 2,465 Silver Trophy
    edited May 25, 2015 12:48PM
    b22c36cf-64c5-485f-bc4f-820427531df0 wrote:
    
    I think I will try a CSV file format, it does seems as though it would make things a little easier.
    

    OK, that's a point where we can start.

    first thing you have to do is to read the file.

    This is best done line by line using a BuffrerdReader.

    You should go through this totorial before you continue:

    b22c36cf-64c5-485f-bc4f-820427531df0 wrote:
    
    I think I will try a CSV file format, it does seems as though it would make things a little easier.
    

    OK, that's a point where we can start.

    first thing you have to do is to read the file.

    This is best done line by line using a BuffrerdReader.

    You should go through this totorial before you continue:

    https://docs.oracle.com/javase/tutorial/essential/io/

    bye

    TPD

  • Anthony_Reaper
    Anthony_Reaper Member Posts: 17
    edited May 25, 2015 1:08PM

    so would this then be a more appropriate method of opening the file?

    private void openFile(File file){

            try(BufferedReader reader = Files.newBufferedReader(file, file){

                String line = null;

         while ((line = reader.readLine()) != null){

      System.out.println(line);

            }

            catch (IOException ex){

                Logger.getLogger(BusinessSalesDataAnalysis.class.getName()).log(Level.SEVERE, null, ex);

            }

        }

  • TPD-Opitz
    TPD-Opitz Dipl.-Ing, Dipl.-Inf GermanyMember Posts: 2,465 Silver Trophy
    edited May 25, 2015 1:18PM
    b22c36cf-64c5-485f-bc4f-820427531df0 wrote:
    
    so would this then be a more appropriate method of opening the file?
    
    private void openFile(File file){
    
            try(BufferedReader reader = Files.newBufferedReader(file, file){
                String line = null;
         while ((line = reader.readLine()) != null){
      System.out.println(line);
            }
            catch (IOException ex){
                Logger.getLogger(BusinessSalesDataAnalysis.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    

    Yes.

    next step is to split the line appart to get the information you need.

    I'd suggest to use Pattern and Matcher from Java API.

    bye

    TPD

  • Anthony_Reaper
    Anthony_Reaper Member Posts: 17
    edited May 25, 2015 1:30PM

    These seem a little confusing, where would this go in the code?

  • Anthony_Reaper
    Anthony_Reaper Member Posts: 17
    edited May 25, 2015 1:51PM

    Am I correct in assuming these are public classes that will exist outside of the main code? And would be invoked within:

    private void openFile(File file){

            try(BufferedReader reader = Files.newBufferedReader(file, file){

                String line = null;

         while ((line = reader.readLine()) != null){

      System.out.println(line);

            }

            catch (IOException ex){

                Logger.getLogger(BusinessSalesDataAnalysis.class.getName()).log(Level.SEVERE, null, ex);

            }

        }

  • TPD-Opitz
    TPD-Opitz Dipl.-Ing, Dipl.-Inf GermanyMember Posts: 2,465 Silver Trophy
    edited May 25, 2015 1:55PM
    b22c36cf-64c5-485f-bc4f-820427531df0 wrote:
    Am I correct in assuming these are public classes that will exist outside of the main code?

    Follow the links I provided for examples of usage.

     And would be invoked within:
    
    

    yes.

    bye

    TPD

This discussion has been closed.