CSCI 1302 Homework #6 Due 11:30pm, April 25, Saturday, 2020 (50pts) Problem 1: In the attached text file US_Canada.txt, each line contains a state or province name together with the corresponding...

1 answer below »
assignment files


CSCI 1302 Homework #6 Due 11:30pm, April 25, Saturday, 2020 (50pts) Problem 1: In the attached text file US_Canada.txt, each line contains a state or province name together with the corresponding country name (USA or Canada). The tab `\t` character is used to separate the two names on each line. Write a Java program to read the text file and build a map object to map each country name to a set of state or province names. After the map is built, print to stdout in alphabetical order the state or province names associated with each country. It does not matter whether US state names or Canadian province names are printed first. Partial output of a program run can look like the following: C:\> java TestMapSet1 USA, Alabama USA, Alaska … Canada, Alberta Canada, British Columbia … Program Implementation Requirements & Hints: · You are recommended to use the File, Scanner, some variants of the Map and Set classes to achieve the goals. Make sure that for each country, the state or province names are printed in alphabetical order. Put all your classes in the same file. (50pts) Problem 2: For each string s, define its repetition_ratio R(s) as the ratio between the number of characters in s and the number of distinct characters in s. For example, the state name GEORGIA has repetition_ratio R=7/6. (Note: if a state name consists of more than one word, do not take the space between the words into account when calculating its repetition_ratio. Also, case insensitive names should be used in the calculation.) Write a Java program to store the 50 US state names together with their repetition_ratios into a priority queue of objects of some appropriate class of your design. The priority should be the repetition_ratio of the state names. In case there is a tie between the priorities of two states, alphabetical order should be used as the priority order. For example, both Florida and Idaho have the same repetition_ratio 1/1 and Florida takes priority over Idaho since Florida is smaller than Idaho in alphabetical order. After the priority queue is built, print to stdout the state names with their repetition_ratios by visiting and removing all 50 objects in the priority queue according to the ordering criterion of this priority queue, one state per line. Your program may still read US_Canada.txt for problem 1 to retrieve the 50 state names. Note: you must achieve the desired printing results through a priority queue object. Partial output of a program run can look like the following: C:\> java TestPQ1 Florida repetition_ratio:7/7 Idaho repetition_ratio:5/5 … Tennessee repetition_ratio:9/4 Mississippi repetition_ratio:11/4 Program Implementation Requirements & Hints: · You are recommended to use the File, Scanner and PriorityQueue classes (together with additional classes of your design) to achieve the goals. DO NOT use the Rational class in Folio. Your own class to encapsulate each state name and its repetition_ratio should be designed appropriately and a comparator class can be designed for it so that the priority queue can be ordered correctly according to the specified criteria. Put all your classes in the same file. You may check out GeometricObjectComparator.java, TestComparator.java and PriorityQueueDemo.java to find out about how to design a custom comparator to order your priority queue. Submit your program (two .java source files) to the dropbox a6 folder by deadline. Do not send any screen shot. Do not send any .pdf file, or MS Word file, or any similar Word-Processing file, or .class file. New JerseyUSA Rhode IslandUSA MarylandUSA ColoradoUSA WyomingUSA ArizonaUSA South CarolinaUSA MassachusettsUSA QuebecCanada IdahoUSA ArkansasUSA NevadaUSA NebraskaUSA CaliforniaUSA South DakotaUSA LouisianaUSA MississippiUSA IllinoisUSA ManitobaCanada KentuckyUSA New BrunswickCanada PennsylvaniaUSA Nova ScotiaCanada IndianaUSA MaineUSA DelawareUSA New YorkUSA New HampshireUSA North CarolinaUSA Northwest TerritoriesCanada North DakotaUSA Newfoundland and LabradorCanada SaskatchewanCanada TennesseeUSA West VirginiaUSA MontanaUSA AlaskaUSA AlbertaCanada ConnecticutUSA WashingtonUSA WisconsinUSA UtahUSA VermontUSA TexasUSA Prince Edward IslandCanada HawaiiUSA KansasUSA MissouriUSA GeorgiaUSA MinnesotaUSA YukonCanada OhioUSA OklahomaUSA MichiganUSA OregonUSA AlabamaUSA FloridaUSA IowaUSA NunavutCanada British ColumbiaCanada VirginiaUSA New MexicoUSA OntarioCanada
Answered Same DayApr 25, 2021

Answer To: CSCI 1302 Homework #6 Due 11:30pm, April 25, Saturday, 2020 (50pts) Problem 1: In the attached text...

Aditya answered on Apr 26 2021
149 Votes
package question1;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Ha
shMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Question1 {

public static void main(String[] args) throws FileNotFoundException{
String filename = "uscanada.txt";
File f = new File(filename);// File object to store file Name
Scanner sc = new Scanner(f); //scanner object for file reading
int lineNumber = 0;
Map unsortMap = new HashMap();
while(sc.hasNextLine()){
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here