Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Please help me (Data mining Program)

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();
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>(){
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);
}
}
}
Answers
-
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
-
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.
-
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
-
I think I will try a CSV file format, it does seems as though it would make things a little easier.
-
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
-
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);
}
}
-
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
-
These seem a little confusing, where would this go in the code?
-
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);
}
}
-
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