ExtraCredit Homework.docx ITEC 3150 – Extra Credit Homework – Worth 1 homework grade DUE DATE: Sunday, November 8, 2020 by 11:30 PM- NO LATE SUBMISSIONS FOR ANY REASON SINCE THIS IS EXTRA CREDIT....

Files have been attached


ExtraCredit Homework.docx ITEC 3150 – Extra Credit Homework – Worth 1 homework grade DUE DATE: Sunday, November 8, 2020 by 11:30 PM- NO LATE SUBMISSIONS FOR ANY REASON SINCE THIS IS EXTRA CREDIT. Coding standards note: The coding standards are in a document in a D2L module titled Coding Standards. See Grading Criteria for points lost if not followed. Competencies being graded: 1. Ability to implement a HashMap 2. Ability to populate and print from a HashMap 3. Ability to write items from a HashMap 4. Read and write a binary file using ObjectInputStream and ObjectOutputStream 5. Ability to read an English language problem description and design a multi class solution in Java 6. Ability to follow given coding standards- in D2L content under Coding Standards. Problem Statement: Create a program that reads in the file people.dat from Homework 2. (Yes, you can use the code from Homework 1). Please make sure to include Person.java in your submission. Implement your own HashMap implementation. You may use the HashMap example provided in the notes, but you MUST modify it to handle Person objects only and bring it completely up to coding standards to receive all points. You MAY NOT use java.util.HashMap or java.util.TreeMap in this problem. After reading in the Person objects, store the Personobjects into your HashMap implementation using the unique ID as the key to the map rather than the ArrayList used in Homework 2. Then print the Person objects from the HashMap in a user friendly fashion. You may use iterator or for-each loop-> DO NOT JUST System.out.println THE HASHMAP- ITERATE THROUGH IT. Hint: Modify your toString in Person to get a nice looking output. Grading Criteria Reads a file 15 Correctly creates an appropriate HashMap 20 Correctly adds Person objects to the HashMap with ID as key 15 Correctly prints the HashMap 25 Correctly reads the people.dat file 10 Meets coding standards 15 people.dat peopleFile.txt Nana Agyeman Buford 1 Joseph Anderson Duluth 2 Kyle Brooks Lawrenceville 3 Joshua Broughton Dacula 4 Demetri Clark Lilburn 5 David Edwards Snellville 6 Joni Elshani Atlanta 7 Jacob Fagan Decatur 8 Person.java Person.java import java.io.Serializable; /**  * ITEC 3150 - Text File I/O Example Person Class - This is the object we will  * read and write to file  *   * @author cjohns25  *   */ public class Person implements Serializable {     public String firstName;     public String lastName;     public int idNum;     public String city;     /**      * Default constructor used to create empty attributes      */     public Person()     {         firstName = "";         lastName = "";         idNum = 0;         city = "";     }     /**      * @param firstName      * @param lastName      * @param idNum      * @param city      */     public Person(String firstName, String lastName, int idNum, String city)     {         this.firstName = firstName;         this.lastName = lastName;         this.idNum = idNum;         this.city = city;     }     /*      * (non-Javadoc)      *       * @see java.lang.Object#toString()      */     @Override     public String toString()     {         return firstName + " " + lastName ;     }     /**      * @return the firstName      */     public String getFirstName()     {         return firstName;     }     /**      * @param firstName the firstName to set      */     public void setFirstName(String firstName)     {         this.firstName = firstName;     }     /**      * @return the lastName      */     public String getLastName()     {         return lastName;     }     /**      * @param lastName the lastName to set      */     public void setLastName(String lastName)     {         this.lastName = lastName;     }     /**      * @return the idNum      */     public int getIdNum()     {         return idNum;     }     /**      * @param idNum the idNum to set      */     public void setIdNum(int idNum)     {         this.idNum = idNum;     }     /**      * @return the city      */     public String getCity()     {         return city;     }     /**      * @param city the city to set      */     public void setCity(String city)     {         this.city = city;     } } GeneratePeopleFile.java GeneratePeopleFile.java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Scanner; public class GeneratePeopleFile {     public static void main(String[] args)     {         // Starting point of program         // open a file of Person class and read them into an ArrayList of Persons         ArrayList people = new ArrayList();         File peopleFile = new File("peopleFile.txt");         // open a Scanner to read data from File         Scanner peopleReader = null;         try         {             peopleReader = new Scanner(peopleFile);         } catch (FileNotFoundException e)         {             // TODO Auto-generated catch block             System.out.println("File not found - terminating program");             System.exit(0);             e.printStackTrace();         }         // read one person at a time         while (peopleReader.hasNext())         {             // read first name             String firstName = peopleReader.next();             String lastName = peopleReader.next();             String city = peopleReader.next();             int id = peopleReader.nextInt();             // create new Person instance and add to ArrayList             Person temp = new Person(firstName, lastName, id, city);             people.add(temp);         }         // print info to user         System.out.println("The people from the file are:");         System.out.println(people);         // write people to another file         File secondPeopleFile = new File("people.dat");         ObjectOutputStream peopleWrite = null;         try         {             peopleWrite = new ObjectOutputStream(new FileOutputStream(secondPeopleFile));             for (Person temp : people)             {                 peopleWrite.writeObject(temp);             }             peopleWrite.close();         } catch (IOException e)         {             System.out.println("Problems writing to file");             // TODO Auto-generated catch block             e.printStackTrace();         }     } } GeneratePeopleFile.java GeneratePeopleFile.java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Scanner; public class GeneratePeopleFile {     public static void main(String[] args)     {         // Starting point of program         // open a file of Person class and read them into an ArrayList of Persons         ArrayList people = new ArrayList();         File peopleFile = new File("peopleFile.txt");         // open a Scanner to read data from File         Scanner peopleReader = null;         try         {             peopleReader = new Scanner(peopleFile);         } catch (FileNotFoundException e)         {             // TODO Auto-generated catch block             System.out.println("File not found - terminating program");             System.exit(0);             e.printStackTrace();         }         // read one person at a time         while (peopleReader.hasNext())         {             // read first name             String firstName = peopleReader.next();             String lastName = peopleReader.next();             String city = peopleReader.next();             int id = peopleReader.nextInt();             // create new Person instance and add to ArrayList             Person temp = new Person(firstName, lastName, id, city);             people.add(temp);         }         // print info to user         System.out.println("The people from the file are:");         System.out.println(people);         // write people to another file         File secondPeopleFile = new File("people.dat");         ObjectOutputStream peopleWrite = null;         try         {             peopleWrite = new ObjectOutputStream(new FileOutputStream(secondPeopleFile));             for (Person temp : people)             {                 peopleWrite.writeObject(temp);             }             peopleWrite.close();         } catch (IOException e)         {             System.out.println("Problems writing to file");             // TODO Auto-generated catch block             e.printStackTrace();         }     } } __MACOSX/._GeneratePeopleFile.java Main.java Main.java import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Scanner; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.scene.layout.StackPane; public class Main extends Application {     Button addButton, submitButton;     TextField firstTextField, lastTextField, cityTextField, idTextField;     Person personAdd;     Stage stage1;     ArrayList people;     ObservableList list;     ListView listView;     public static void main(String[] args) {         Application.launch(args);     }     @Override     public void start(Stage stage) {         people = new ArrayList();         File peopleFile = new File("peopleFile.txt");         Scanner peopleReader = null;         try {             peopleReader = new Scanner(peopleFile);         } catch (FileNotFoundException e) {             System.out.println("File not found - terminating program");             System.exit(0);             e.printStackTrace();         }         while (peopleReader.hasNext()) {             String firstName = peopleReader.next();             String lastName = peopleReader.next();             String city = peopleReader.next();             int id = peopleReader.nextInt();             Person temp = new Person(firstName, lastName, id, city);             people.add(temp);         }         Label addressBook = new Label("Address Book: ");         list = FXCollections.observableArrayList(people);         listView = new ListView<>(list);         listView.setOrientation(Orientation.VERTICAL);         listView.setPrefSize(120, 200);         listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {             public void changed(ObservableValue ov, final Person oldvalue, final Person newvalue) {                 handleChanged(ov, oldvalue, newvalue, stage);             }         });         EventHandler submitEvent = new EventHandler() {             public void handle(ActionEvent e) {                 personAdd = new Person(firstTextField.getText().trim(), lastTextField.getText().trim(),                         Integer.parseInt(idTextField.getText().trim()), cityTextField.getText().trim());                 people.add(personAdd);                 stage1.close();                 listView.getItems().clear();                 listView.getItems().addAll(people);             }         };         EventHandler event = new EventHandler() {             public void handle(ActionEvent e) {                 Label first = new Label("First Name: ");                 firstTextField = new TextField();                 HBox h1 = new HBox();                 h1.setSpacing(15);                 h1.getChildren().addAll(first, firstTextField);                 Label last = new Label("Last Name: ");                 lastTextField = new TextField();                 HBox h2 = new HBox();                 h2.setSpacing(15);                 h2.getChildren().addAll(last, lastTextField);                 Label city = new Label("City: ");                 cityTextField = new TextField();                 HBox h3 = new HBox();                 h3.setSpacing(60);                 h3.getChildren().addAll(city, cityTextField);                 Label id = new Label("ID Number: ");                 idTextField = new TextField();                 HBox h4 = new HBox();                 h4.setSpacing(15);                 h4.getChildren().addAll(id, idTextField);                 submitButton = new Button("Submit");                 submitButton.setOnAction(submitEvent);                 VBox vBox = new VBox();                 vBox.setSpacing(10);                 vBox.setPadding(new Insets(10));                 vBox.getChildren().addAll(h1, h2, h3, h4, submitButton);                 StackPane secondaryLayout = new StackPane();                 secondaryLayout.getChildren().add(vBox);                 Scene detailed = new Scene(secondaryLayout, 480, 300);                 stage1 = new Stage();                 stage1.setTitle("Add Person");                 stage1.setScene(detailed);                 stage1.setX(stage.getX() - 50);                 stage1.setY(stage.getY() + 100);                 stage1.show();             }         };         addButton = new Button("Add Person");         addButton.setOnAction(event);         VBox vBox = new VBox();         vBox.setSpacing(10);         vBox.getChildren().addAll(addressBook, listView, addButton);         stage.setOnCloseRequest(e -> {             saveDataToFile();             System.exit(0);         });         Scene scene = new Scene(vBox, 400, 500);         stage.setScene(scene);         stage.setTitle("Person Library");         stage.show();     }     public void handleChanged(ObservableValue observable, Person oldValue, Person newValue,             Stage primaryStage) {         Label first = new Label("First Name: " + newValue.getFirstName());         Label last = new Label("Last Name: " + newValue.getLastName());         Label city = new Label("City: " + newValue.getCity());         Label id = new Label("ID: " + newValue.getIdNum());         VBox vBox = new VBox();         vBox.setSpacing(10);         vBox.setPadding(new Insets(10));         vBox.getChildren().addAll(first, last, city, id);         StackPane secondaryLayout = new StackPane();         secondaryLayout.getChildren().add(vBox);         Scene detailed = new Scene(secondaryLayout, 280, 150);         Stage stage = new Stage();         stage.setTitle("Person");         stage.setScene(detailed);         stage.setX(primaryStage.getX() + 100);         stage.setY(primaryStage.getY() + 100);         stage.show();     }     public void saveDataToFile() {         try {             BufferedWriter bw = new BufferedWriter(new FileWriter(new File("peoplefile.txt")));             File secondPeopleFile = new File("people.dat");             ObjectOutputStream peopleWrite = null;             peopleWrite = new ObjectOutputStream(new FileOutputStream(secondPeopleFile));             for (Person per : people) {                 bw.write(per.getFirstName());                 bw.newLine();                 bw.write(per.getLastName());                 bw.newLine();                 bw.write(per.getCity());                 bw.newLine();                 bw.write(per.getIdNum()+"");                 bw.newLine();                 peopleWrite.writeObject(per);             }             bw.flush();             bw.close();             peopleWrite.close();         } catch (Exception ex) {         }     } } __MACOSX/._Main.java Person.java Person.java import java.io.Serializable; /**  * ITEC 3150 - Text File I/O Example Person Class - This is the object we will  * read and write to file  *   * @author cjohns25  *   */ public class Person implements Serializable {     public String firstName;     public String lastName;     public int idNum;     public String city;     /**      * Default constructor used to create empty attributes      */     public Person()     {         firstName = "";         lastName = "";         idNum = 0;         city = "";     }     /**      * @param firstName      * @param lastName      * @param idNum      * @param city      */     public Person(String firstName, String lastName, int idNum, String city)     {         this.firstName = firstName;         this.lastName = lastName;         this.idNum = idNum;         this.city = city;     }     /*      * (non-Javadoc)      *       * @see java.lang.Object#toString()      */     @Override     public String toString()     {         return firstName + " " + lastName ;     }     /**      * @return the firstName      */     public String getFirstName()     {         return firstName;     }     /**      * @param firstName the firstName to set      */     public void setFirstName(String firstName)     {         this.firstName = firstName;     }     /**      * @return the lastName      */     public String getLastName()     {         return lastName;     }     /**      * @param lastName the lastName to set      */     public void setLastName(String lastName)     {         this.lastName = lastName;     }     /**      * @return the idNum      */     public int getIdNum()     {         return idNum;     }     /**      * @param idNum the idNum to set      */     public void setIdNum(int idNum)     {         this.idNum = idNum;     }     /**      * @return the city      */     public String getCity()     {         return city;     }     /**      * @param city the city to set      */     public void setCity(String city)     {         this.city = city;     } } __MACOSX/._Person.java
Nov 08, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here