The license plate game and csv parsing

Assignment Help JAVA Programming
Reference no: EM13671766

Part One:

Your job in this is to write a method private int syllablesInWord (String word) that takes in a single word and returns the number of syllables in that word.

It is difficult to determine the exact number of syllables in a word just from its spelling. For example, the word are has just one syllable, while the similarly-spelled area has three. Therefore, we aren't go- ing to ask you to count syllables exactly. Instead, you should approximate the number of syllables us- ing the following heuristic: count up the number of vowels in the word (including 'y'), except for

• Vowels that have vowels directly before them, and

• The letter e, if it appears by itself at the end of a word.

Notice that under this definition, the word me would have zero syllables in it, since the 'e' at the end of the word doesn't contribute to the total. To address this, your method should always report that there is at least one syllable in any input word, even if the heuristic would otherwise report zero. This resulting method will correctly estimate that there are two syllables in quokka and two syllables in springbok, though it does get the number of syllables in syllable wrong (guessing two instead of three). With the zero-syllable correction in place, the heuristic correctly counts syllables in the words the, be, and she.

Think about how the heuristic works and choose test words that ensure your code correctly implements the heuristic.

Part Two: Algorism Algorithms

The Art and Science of Java, Java's primitive data types (int,   double, etc.) have ranges on what values they can store. int,  for example, can't hold values greater than

2,147,483,647. Since we may want the computer to work with values larger than this (say, for example, the US national debt or the number of atoms in one gram of carbon), programmers sometimes use other types (such as String) for large integers. For example:

String  worldPopulationin2010              = "6993309969";

String  possibleRubiksCubeStates = "43252003274489856000";

In order to make use of numbers encoded this way, we have to have some way to add them. In grade school, you probably learned how to add two large numbers one digit at a time. You write the two num- bers out, one on top of the other, then work from the right to the left adding the individual digits of the numbers. When the digits sum up to a value greater than ten, you would write out just the ones digit of their sum, then carry a 1 into the next column. For example, here's 137 + 864:

1

1

1

 

 

1

3

7

+

8

6

4

1

0

0

1

In this part of the assignment, we'd like you to write a method private String  addNumericStrings(String n1,   String  n2)

This method will accept as input two numbers represented as Strings. It should then return a String representing the sum of the two input numbers. To compute this sum, you'll program the computer to do arithmetic the same way that you learned in grade school: work from right to left, summing the dig- its of each string, and keeping track of the carry across columns.

When implementing this method, you can assume the following:

  • The two input strings will be nonnegative (that is, you'll never get an input like "-137").
  • The two input strings will consist purely of digits and will be valid representations of numbers. Therefore, you will never get inputs like "+3", "1,000,000,000", or "".
  • The two input strings will not necessarily be the same length as one another.

We recommend implementing this method in stages. First, write a method that adds two input numbers, assuming they're the same length and that no carrying will be needed involved. Then, implement carry - ing. Finally, generalize your method so that it works on numbers of differing lengths.

There is one important detail about the char  type that you're likely to run into when working on this part of the assignment. Internally, each char  is represented by a numeric value. For example, the char- acter 'A' has value 65, and the character '*' has value 42. Somewhat counterintuitively, the characters

'0', '1', '2', etc. have numeric values 48, 49, 50, etc. If you want to get the numeric value that's rep- resented by a particular character, you can do so by writing

int value = ch  - '0';

Similarly, if you have the numeric value of a digit, you can obtain its char  representation by writing

char  ch  = (char)(value  + '0');

The art of performing arithmetic with a place-value system is called algorism. Once you've finished part of the assignment, you'll have programmed the algorism algorithm and have taught the computer to do arithmetic the way that you did back in grade school.

Part Three: The License Plate Game

If you've ever driven on California streets, you've probably noticed that California license plates always consist of a number, three letters, then another three numbers. For example:

5NPT839 4KDD232 7FTW142

On a long highway drive in California, one fun way to pass the time is to play the license plate game, in which you look at the license plate of the nearest car, then try to find a word that uses the letters in that license plate in the order in which they appear. For example, for the license plate 5NPT839, you might use the word INPUT. For 4KDD232, you could use KIDDING. For 7FTW142, you could use AFTERGLOW.

For a word to match a license plate, it has to contain all the letters in the license plate in the order in which they occur. This means, for instance, that FTW doesn't match WATERFALL because the letters are in the wrong order. Similarly, NNN doesn't match ENTIRE, since only one of the N's was matched.

Certain letter combinations are a lot harder to find words for than others. The letter combination YRW only matches a handful of words (like EYEBROW). The combination XCX only matches two English words (EXECUTRIX, a woman who executes a will, and its plural EXECUTRIXES), and some com- binations don't match anything at all. There are no English words that match QQQ, for example.

Your job in this part of the assignment is to write a program that prompts the user for a three-letter string, then prints all English words that match that pattern. Your program should sit in a loop prompting the user to enter a three-letter string (which can be upper-case or lower-case), reprompting as necessary until the user enters a string consisting of three letters. Then, your program should list all English words that match that string. There's a screenshot of the program in ac- tion on the left.

Part Four: CSV Parsing

In class, we saw how to read a file one line at a time. This is a great way to read data if the file is struc- tured so that there is one piece of data per line. Most of the time, though, data isn't stored this way. This question explores a common data format called the comma-separated value format (or CSV).

The CSV format is a common data format for storing tables. Each row of the table is represented by one line in the CSV file, where the columns are delimited by commas (hence "comma-separated val- ues.") As an example, here is a sample table and what its CSV representation might look like:

Dish,Origin

Ful Medammas,Middle East Vindaloo,"India, Portugal" Maafe,West Africa Soondubu,Korea
Kuku,"Iran, Azerbaijan" Shakshuka,North Africa
Notice that each row is formed by writing out the contents of each of the cells separated by a comma. You'll also notice that the cell contents are glued together by a comma with no intervening spaces. For example, in the line for Soondubu, notice that there is no space between the comma and Korea. In some cases, the contents of a cell might contain a comma (for example, the origin entries for vindaloo and kuku). In that case, the contents of the cell will be surrounded by quotation marks to indicate that the comma is a part of the field and not a separator. Other cells may optionally be quoted, even if the cell doesn't contain an internal comma.

Part Five: Extensions!

Do you have any cool ideas for how to make these programs more interesting? If so, please feel free to submit your assignment with extensions! Here are a few suggestions of what you might work on, though this is by no means an exhaustive list:

• Improve the syllable-counting heuristic. Our heuristic gets the wrong answers in a few predica- ble places. Can you improve it to be more accurate?

• Count syllables in other languages. Do you have any ideas about how to implement a syllable counter for a different language like French, Chinese, or Arabic? If so, we'd love to see it!

• Implement subtraction, multiplication, or division. We asked you to implement addition in Part Two of this assignment, but there are lots of other operations you could support as well. Try teaching the computer how to subtract or multiply. For a real challenge, try teaching the com- puter long division. ?

• Find all losing license plates. We mentioned earlier that some three-letter combinations, such as QQQ, can't be expanded into an English word. What other letter combinations have this prop - erty? Can you find all of them?

• Summarize license plate answers succinctly. Once you start playing around with your solution to the license plate game, you'll probably find that there are a lot of matches for many common letter combinations. See if you can find a way to intelligently summarize those matches.

• Explore an interesting data set. Now that you have the ability to parse CSV files, you can im- port data from a bunch of different sources. Find an interesting CSV file (the World Bank and the US Government's www.data.gov are good sources) and write a program that uses that infor- mation to tell us something interesting.

• Build a complete table representation. Rather than just extracting one column from a CSV file, see if you can instead store the entire table in memory.

Reference no: EM13671766

Questions Cloud

Two masses are on frictionless horizontal surface moving : Two masses are on a frictionless horizontal surface moving with two perpendicular directions (m1=m and m2=3m). After the collision the m1 mass stops. What is the velocity of mass m2 after the collision, if before the collision of the masses v1=5m/s a..
What is the highest order visible maximum that is formed : White light strikes a diffraction grating ( 890 lines/mm) at normal incidence.  What is the highest order visible maximum that is formed?
Speed and direction of each ball after the collision : A ball of mass 0.640 kg moving east (+x direction) with a speed of 3.20 m/s collides head-on with a 0.480 kg ball at rest. If the collision is completely elastic, what will be the speed and direction of each ball after the collision?
Magnetic target is suspended on a string : A 0.73-kg magnetic target is suspended on a string. A 0.025-kg magnetic dart shot horizontally, strikes the target head-on. The dart and the target together acting like a pendulum, swing 12.0 cm above the initial level before instantaneously coming t..
The license plate game and csv parsing : Resulting method will correctly estimate that there are two syllables in quokka and two syllables in springbok, though it does get the number of syllables
Radius of the path of the ion in the field : A singly charged positive ion has a mass of 3.20x10^-26 kg. After being accelerated from rest during a potential difference of 843 V, the ion enters a magnetic field of 0.920 T along a direction perpendicular to the direction of the field.
Current should exist in the conductor in order for tension : A conductor suspended by two flexible wires as in the figure below has a mass per unit length of 0.0500 kg/m. What current should exist in the conductor in order for the tension in the supporting wires to be zero when the magnetic field is 3.50 T int..
A small rock is found orbiting an asteroid : A small rock is found orbiting an asteroid at a distance of 150,000 meters and with an orbital period of 12,000 seconds. Compute the mass of the asteroid. The constant is 6.67 x10-11m  3/kgs2.
How far has the car gone : A car starts from rest and travels for 7.0 s with a uniform acceleration of +2.7 m/s2.The driver then applies the brakes, causing a uniform acceleration of -3.0m/s2. If the brakes are applied for 1.0 s, How fast is the car going at the end of the bra..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Tracer for java

Implementation of a tracer of Java objects and the tracer can be invoked from any point of a Java program, accepting an object as argument.

  The array at the index method

have an array, how do i remove an entry from the array at the index method?

  Program that computes and prints the value of 6!/5! using

Write a Java program that computes and prints the  value of 6!/5! using Scanner.

  Inheritance involves the concept of super class

Inheritance involves the concept of super class (parent class) and sub class (derived class). What is a super class in Java? What is a sub or derived class in Java?

  Quadratic that solves quadratic equations

Write a method called quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form ax2 + bx + c = 0. The formula for solving a quadratic equation is ?..

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Develop a program that will handle a golfer and his scores

develop a program that will handle a Golfer and his scores. The program will be comprised of two classes: a Golfer class that will manage all the golfer's scores and a Score class.This is a class designed to represent a golfer including his name, hom..

  What position along the chord does minimum pressure occur

At what position along the chord does the minimum pressure occur? What is special about the point where C p is a maximum?

  Design a class named large integers

Design a class named largeIntegers such that an object of this class can store an integer of any number of digits.

  Develop view for order number and order total in file

Develop a view named OrdTot. It comprises of order number and order total for each order currently on file. Order total is the sum of number ordered.

  Write function in javascript to compute person-s gross pay

Write the function using JavaScript syntax to compute a person's gross pay for a week. The function should receive the number of hours worked and the rate of pay per hour.

  Bullpart 1 several types of point of interests poi such as

bullpart 1 several types of point of interests poi such as - 1 petrol station 2 taxi stand 3 atm 4 hospital and 5

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd