Lab11-Assign7

pdf

School

Temple University *

*We aren’t endorsed by this school

Course

2168

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

5

Uploaded by MateMusic12373

Report
CIS2168 Assignment 7 Usage of Map, HashMap, TreeMap 1. Learning Objectives After the successful completion of this assignment, you will be able To explain what is a Map, a HashMap, and a TreeMap To explain the usage of Map data structure To read and write Java code using Map, TreeMap, HashMap in Java API 2. Task & Coding Requirements & Coding Hints You will complete the application that reads online purchase data from a .CSV file, generates a summary of purchases made by customers from different countries, and prints the data summary in a simple and nice format. You are given one data file named purchases.csv. and two classes SummaryGenerator and SummaryGeneratorTest. Data file: purchases.csv o It contains the purchase data. o Each line represents a purchase of a single item in an invoice. An invoice may include multiple products. In this case, there are multiple lines for this invoice, one product per line. o The file format is CSV (Comma Separated Value), which is a text file. All values are separated by comma. o The first line in the file shows the structure of each line (i.e a record): InvoiceNo,StockCode,Description,Quantity,InvoiceDate,UnitPrice,CustomerID,Country o The lines after the first line are the real purchase data. One example is: 536365,85123A,WHITE HANGING HEART T-LIGHT HOLDER,6,12/1/2010 8:26,2.55,17850,United Kingdom o To read from this data file without having to specify the directory path, please make sure that you place this file in the same folder as the folder named src in your project folder. SummaryGenerator class o It includes the methods that generate the data summary based on the data in the file purchases.csv and show such summaries. Currently it only counts how many times each country appears. o The data summary: countsByCountry is stored in a Map data structure. o Data field countsByCountry the data summary stored in a Map data structure. You complete this definition. o Constant COMMA_DELIMITER: the delimiter comma in the data file: purchases.csv o Methods SummaryGenerator() constructor to create the objects for the empty data summary map: a HashMap or TreeMap You complete this method. You must add the code for creating each type of Map. Then you comment the code for one type, use the other type at a time. createCountsByCountry(BufferedReader br)
It takes in a BufferedReader object that is already associated with the file purchases.csv, read the data line by line, create the country summary and save the summary entries in the summary map countsByCountry . showCountsByCountry() You complete this method. print the content of the data summary map in the format given in the sample output. o A tabular format that uses * to show the counts. 5 stars means count of 5. printNChars(char ch, int count) You complete this method. print the character ch count number of times in one line SummaryGeneratorTest class o This class tests the implementation of SummaryGenerator class. o It creates a BufferedReader to read from the data file purchases.csv, creates an object of SummaryGenerator, uses this object to call createCountsByCountry and pass the BufferedReader object br to this method, uses this object to call showCountsByCountry, which displays the summary. o You complete the last 3 tasks: creates an object of SummaryGenerator, uses this object to call createCountsByCountry and pass the BufferedReader object br to this method, uses this object to call showCountsByCountry. Coding Requirements The data summary counts by country must use a Map data structure o Declare it as a Map in Java API o First use an object of HashMap class in Java API o Then use an object of a TreeMap class in Java API. createCountsByCountry(BufferedReader br) o You must use the BufferedReader br to read from the given data file, and populate the data summary Map. showCountsByCountry() o The information must be printed in a tabular format like the sample output where data is aligned. printChars(char ch, int count) o All characters must be printed in one line 3. Sample Output Output from main() in SummaryGeneratorTest class for the HashMap data summary Country Count ------------------------------------------------------------ Canada ******* United States ******* United Kingdom ************ France ************ Germany ********
Output from main() in SummaryGeneratorTest class for the TreeMap data summary Country Count ------------------------------------------------------------ Canada ******* France ************ Germany ******** United Kingdom ************ United States ******* 4. Coding Hints Assign7 Template o Assign7_template.zip includes all files necessary for you to complete this assignment. Data field: data summary map o Map & HashMap It’s very similar to frequencies in the class CharacterCount in the package hashmap_use posted for Lec#21. o TreeMap Similar to the code in the class SimpleMapTest in the package set_map_use or set_map_use_demo posted for Lec#19 in Week 10 Module . createCountsByCountry() o It’s very similar to buildCharacterCount() in the class CharacterCount in the package hashmap_use posted for Lec#21. o The difference is in handling the map entry type (stored format). showCountsByCountry() o Display data summary entry information in the format similar to the sample output o You can use System.out.printf (…) method. o See the class CharacterCountTest in the package hashmap_use posted for Lec#21. Code in SummaryGeneratorTest class o Similar to the code in main() method in class IndexGenerator in the package set_map_use posted for Lec#19. 5. Recommended Steps Understand the classes in assign7_template. Understand the class SimpleMapTest in the package set_map_use posted for for Lec#19 in Week 10 Module . Understand the class IndexGenerator in the package set_map_use posted for Lec#19 in Week 10. Understand the class CharacterCountTest, CharacterCount in the package hashmap_use posted for Lec#21 in Week 11. Revise the SummaryGenerator class in the following order and add the code to test it in SummaryGeneratorTest class i. Declare the data field countsByCountry ii. The constructor SummaryGenerator() iii. createCountsByCountry() iv. printChars(char ch, int count) v. showCountsByCountry()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
6. Submission Requirements WHEN: Code Submission Due: Please see the assignment Canvas page for details. Code Demo Due: Please see the assignment Canvas Page for details. o NOTE: This assignment has a different Code Demo Due Date from previous assignments. WHAT: Either format below ALL your source code files (.java files). o if you upload the files one by one, then comments can be marked on your .java files via SpeedGrader A single zipped file that is named Assign7_YourFirstName_YourLastName.zip . So for example: Assign7_Taylor_Swift.zip o IT IS REQUIRED THAT YOU MARK WHICH IDE TOOL YOU USED TO CREATE THE PROJECT IN YOUR SUBMISSION. o Your .java files can NOT be marked with comments using SpeedGrader. Your submissions MUST include your SOURCE CODE and any other files your code may have used. A README file that contains the following: o If your code does not produce the perfect result, please explain which parts you accomplished, which parts you did not attempt, and which parts you attempted but failed. If you attempted but failed, please include the corresponding output. o Anything else that you want the TA and the Instructor to know. WHERE: Submit to Canvas via the link Lab11-Assign7 in Content Folder Assignments . Attach each of your source code files or a zipped file and submit. 7. Grading This assignment will be totally 100 points. Grading will be based on two things: Correctness (80%) Programming style (10%) Code Demo (10%) The detailed breakdown of Correctness and Programming Style Points among different classes will be posted later. 7.1 Correctness Your code does all the functionalities that are required. Your code compiles, runs, and produces the correct result. There is no compile error or runtime error. 7.2 Programming Style
Your code is organized into classes and methods within classes. Each class and each method except the getters and setters is documented and commented. Each file has a file header comment, including the following o CIS2168 003 Data Structures or CIS2168 005 Data Structures. Please mark your section. o Your full name and email address o Which Assignment: Assign 7 o Program name: your file name or class name o Program description: summarize the functionalities of the program in the file. Each class has a class header comment, stating what the class is about if you haven’t done so in the file header comment . o In another word, if a file contains only 1 class, just write a file header comment. You d on’t need to write a class header comment. Each method has a method header comment, stating the method functionalities, parameters, and return values. o You don’t have to comment on the getter and setter methods. Comment on important control structures (loops, branching like if-lese, etc ) inside the methods. The writing of classes and methods is consistent with the Google Java Coding Style Standard listed in the following link: http://google.github.io/styleguide/javaguide.html Please pay attention to these things in your programs: Naming of a class, method, variable, constant Indentation and spacing Use end of line { No more than one variable/constant declaration in one line 7.3 Code Demo As long as you demo and explain the code to the TA or me, you will get ALL the credit. You will get 10 points if you compile, run, and explain your code to the TA or Instructor Cindy. You don't have to explain each and every line. But you must explain the following important parts: * what each method does. * the control structures: branching, looping. * the overall flow when your code executes. The main goal for the demo is for the TA or Instructor Cindy to give you better feedback and facilitate your learning. In addition, you get some practice in explaining your work in preparation for your future job interviews.