Java: Update your word occurrences application. Put a GUI on top of the word occurrences class. Try
Question:
Java:
Update your "word occurrences" application. Put a GUI on top of the word occurrences class. Try to follow the GUI guidelines and practices that you learned about, so that the GUI is clean and usable. Use this
Learning Outcomes
Student will create software to solve basic business problems.
Student will document software solutions.
Assignment Instructions
- Submit your .java files for the application, and a couple of screen shots of your program in action.
- Submit a screen shot of the top 20 words in the following file (a poem): https://www.gutenberg.org/files/1065/1065-h/1065-h.htm(Links to an external site.)
- Submit to your GIT hub repository and provide the link.
***** So far, this is what I have but I can't figure out how to make it print to the GUI*******
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Set; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.stage.Stage;
public class Steffan_module7_word_occurrence extends Application {
@Override public void start(Stage stage) { Scene scene = new Scene(new Group());TextField tb = new TextField(); Label lbl = new Label(); lbl.setLayoutX(300); lbl.setLayoutY(100); lbl.setFont(Font.font("Times New Roman", FontWeight.NORMAL, FontPosture.ITALIC, 24)); Button btnStart = new Button("Start"); btnStart.setLayoutX(120); btnStart.setOnAction((ActionEvent e) -> { try { Steffan_text_analyzer(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } }); VBox RBpane = new VBox(); RBpane.setPadding(new Insets(10,10,10,10)); RBpane.setSpacing(5); RBpane.getChildren().addAll(btnStart); //*********************************************************** // Prepare the Vertical Box // //*********************************************************** VBox vbox = new VBox(); vbox.setMaxWidth(700); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 10,10, 10)); vbox.getChildren().addAll(lbl, RBpane); ((Group) scene.getRoot()).getChildren().addAll(vbox);
//*********************************************************** // Prepare the Stage //*********************************************************** stage.setScene(scene); stage.setTitle("Word Occurrences"); stage.setWidth(700); stage.setHeight(550); stage.show(); } private void Steffan_text_analyzer() throws FileNotFoundException { /** Reading file line by line */ File file = new File("macbeth-1.txt"); Scanner scan = new Scanner(file); Map map = new HashMap(); while (scan.hasNext()) { String lowerCaseWord = scan.next().toLowerCase(); if(map.containsKey(lowerCaseWord) == false) map.put(lowerCaseWord,1); else { int count = (int)(map.get(lowerCaseWord)); map.remove(lowerCaseWord); map.put(lowerCaseWord,count+1); } } Set> set = map.entrySet(); List> sortedList = new ArrayList>(set); Collections.sort( sortedList, new Comparator>() { public int compare( Map.Entry a, Map.Entry b ) { return (b.getValue()).compareTo( a.getValue() );
} } ); List> sortedList2 = sortedList.subList(0, 20); for(Map.Entry i:sortedList2){ System.out.println((i.getKey()+" -> "+i.getValue())); } }
public static void main(String[] args) throws FileNotFoundException { launch(args); } }
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood