Computer Programming 2 — Java Classworks
CLASSWORK #1
01) For your first "official" Java classwork you are to write a program contained
in a single file (named "NameInfo.java") that reads a person's full name from
the keyboard in the format First Middle Last (all on one line). The program
should then (a) print each name on a separate line, (b) print the person's
initials on the fourth line, (c) print the first three letters of the person's
middle name on the fifth line, (d) print the fourth character in the person's
last name on the sixth line, (e) print the total number of characters in the
person's full name, excluding spaces, on the seventh line, and (f) display
the full name back to the user on the eighth line, but with the order of the
characters reversed and each letter capitalized. Assume that each name has
exactly three parts, with no spaces or punctuation within each part, that the
names are separated from each other by a single space, that there are no
leading or trailing spaces, that the last name has at least four characters,
and that each of the three names starts with a capital letter.
You must read the names into three separate string variables using the 'next()'
method of the 'Scanner' class. You must use the 'charAt()' method of the 'String'
class for (b), and you must use the 'substring()' method of the 'String' class for
(c) and (d). For (e), use the 'length()' method of the 'String' class, and use a
'for' loop and the 'toUpperCase()' String method for (f). After reading the three
names, you must create an additional string variable, set it equal to the person's
full name (with spaces), and then use that variable for (e) and (f).
You may not use any arrays or global variables for this assignment. For this
program you may, if you wish, put all of your code into the 'main' method. When
displaying the output, you should format it exactly as shown below.
Sample Output
Enter a three-part name (First Middle Last): James Tiberius Kirk
James
Tiberius
Kirk
JTK
Tib
k
17
KRIK SUIREBIT SEMAJ
This program should be contained in a single file named "NameInfo.java".
Point Value: 15
Due Date: Friday, 1-15-2021
EXTRA CREDIT OPTION FOR CLASSWORK #1
In addition to displaying the information described above, also have your
program display the number of occurrences (the frequency) of each non-space
letter in the name (ignoring case). If you wish, you may use arrays to
implement this extra credit option.
EC Due Date: Friday, 1-15-2021
CLASSWORK #2
02) For your second Java classwork you are to write a program contained in a single
file that displays a message telling the educational level of a student based on
his/her number of years of school. The user should be prompted to enter an integer
indicating the number of years of school, and the program should then print the
corresponding message given below.
If years of school is Then the message should be
less than 0 The years in school must be a non-negative integer.
0 Education level: No school
1 - 5 Education level: Elementary school
6 - 8 Education level: Middle school
9 - 12 Education level: High school
> 12 Education level: College
You may assume that the user will always enter an integer. Be sure to keep your
logical expressions as simple as possible. You will lose points if they are
unnecessarily complex (no compound 'if' statements should be used). Also, for
this program you must use named global constants for all numbers other than zero.
In other words, no number other than zero should appear in 'main' or in any of
the other methods in your program. Make sure your program contains no more than
four named constants, which should be named using all capital letters.
You may not use any global variables for this assignment. Your program should
contain exactly two methods (in addition to 'main'). One of the methods should
be named "getYears" and should get the number of school years from the user.
The other method should be named "showSchool" and should display the appropriate
school level to the user. Both of these methods must be called from 'main'.
Your program's output should be neat, organized, and grammatically correct,
similar to what is shown below.
Sample Output #1
Enter the number of years in school: 7
Education level: Middle school
Sample Output #2
Enter the number of years in school: 12
Education level: High school
Sample Output #3
Enter the number of years in school: -4
The years in school must be a non-negative integer.
This program should be contained in a single file named "SchoolYears.java".
Point Value: 15
Due Date: Friday, 1-22-2021
EXTRA CREDIT OPTION FOR CLASSWORK #2
Instead of asking for the number of years in school just one time, have
your program ask for a number of years, display the proper output, then
ask for another number of years, then display the correct output, then ask
for more years, and so on. Keep doing this until the user presses the
ENTER key without entering any data at all. In addition, after the user
presses the ENTER key by itself to quit the program, display a small table
showing the number of times that each level of education was displayed,
along with the percent value of the total number of entries. Make sure
the values are nicely aligned in neat columns and the percent values are
rounded to one decimal place.
EC Due Date: Friday, 1-22-2021
CLASSWORK #3
03) For this classwork (and the next few classworks) you will practice creating
simple standalone classes from which "objects" can be created. So, for this
assignment, create a non-static class named 'MarbleBank' in its own file.
The class should contain two constructors. The first takes no arguments and
sets the starting marble count to zero. The second constructor takes a single
positive integer as its argument, representing the initial number of marbles
in the bank, and sets the starting marble count to that number. For example,
a call such as
MarbleBank bank1 = new MarbleBank();
will create a new MarbleBank object named 'bank1' that will set up a bank
containing no marbles, while a call such as
MarbleBank bank2 = new MarbleBank(25);
will create a new MarbleBank object named 'bank2' that will set up a bank
containing 25 marbles. Note that the above calls to the 'MarbleBank' class
are merely examples. The identifiers 'bank1' and 'bank2', as well as the
number 25 (or any specific marble number, for that matter), should not appear
ANYWHERE in your "MarbleBank.java" file.
The method 'main' and the keyword 'static' must not appear anywhere in the
'MarbleBank' class. Make sure the internal variables in that class are
private. The class should contain the following public methods:
countMarbles
Arguments: None
Displays: Nothing
Returns: An integer equal to the current number of marbles in the
bank
-------------
addMarbles
Arguments: A positive integer representing the number of new marbles
to add to the bank
Actions: Adds the newly supplied number of marbles to the bank
Displays: Nothing
Returns: Nothing
-------------
emptyBank
Arguments: None
Actions: Sets the current number of marbles in the bank to zero
Displays: Nothing
Returns: Nothing
Point Value: 15
Due Date: Friday, 1-29-2021
EXTRA CREDIT OPTION FOR CLASSWORK #3
To the 'MarbleBank' class, add another public method named 'showHistory' that
displays the number of individual marbles added to the bank during each prior
call to the 'addMarbles' method since the creation of the 'MarbleBank' object
or since the last call to 'emptyBank'. The method should not return anything.
EC Due Date: Friday, 1-29-2021
CLASSWORK #4
04) Create a non-static class named 'WordThing' in its own file. The class should
contain a single constructor that takes a single string as its argument. The
constructor should store the value of the submitted string in an internal
class variable (which, along with any other internal variables in the class,
should be private). You may assume that the submitted string will contain
only uppercase and/or lowercase letters (no spaces, numbers, punctuation,
etc.). The method 'main' and the keyword 'static' must not appear anywhere in
the 'WordThing' class. The class should contain the following public methods:
displayWord
Arguments: None
Displays: The "active" word (by itself, on its own line)
Returns: Nothing
-------------
countLetters
Arguments: None
Displays: Nothing
Returns: An integer equal to the number of characters in the "active"
word
-------------
reverseWord
Arguments: None
Displays: Nothing
Returns: A string containing the characters in the "active" word in
reverse order (you must use a 'for' loop)
-------------
changeWord
Arguments: A single string
Actions: Changes the "active" word to the new input
Displays: Nothing
Returns: Nothing
Point Value: 15
Due Date: Friday, 2-5-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #4
To the 'WordThing' class, add another public method named 'alphabetize'
that returns a string containing the letters in the "active" word in
alphabetical order (ignoring case).
EC Due Date: Friday, 2-5-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #4
To the 'WordThing' class, add another public method named 'variations' that
returns an ArrayList of strings of all of the different permutations of the
letters in the "active" word. So, for example, if the word is "cat", then
your method should return an ArrayList consisting of these six strings:
"cat", "cta", "act", "atc", "tac", and "tca". If a word contains more than
one of the same letter (e.g., "animal", "cook", "situation"), make sure
your returned ArrayList does not contain any duplicate entries. So, for
example, for the word "too", your method should return an ArrayList that
has only three words in it: "too", "oot", and "oto".
EC Due Date: Friday, 2-5-2021
CLASSWORK #5
05) Create a non-static class named 'DiceRoll' in its own file. The class
should contain a single constructor that takes two positive integers as its
arguments, representing the number of sides of two separate fair dice.
For example, a call such as
DiceRoll dice = new DiceRoll(6, 10);
will create a new DiceRoll object called 'dice' that will set up a six-sided
die (numbered 1 through 6) and a ten-sided die (numbered 1 through 10).
Remember that the above call to 'DiceRoll' is an example. No specific dice
values should appear anywhere in the 'DiceRoll' class.
The method 'main' and the keyword 'static' must not appear anywhere in the
'DiceRoll' class. Make sure all of the internal variables in the 'DiceRoll'
class are private. The class should contain the following public methods:
newRoll
Arguments: None
Actions: "Rolls" both dice and stores the result of the rolls
Displays: Nothing
Returns: Nothing
-------------
lastRoll
Arguments: None
Displays: Nothing
Returns: A string containing BOTH of the die values from the last
(most recent) time that the dice were rolled; the string
should have the form "#, #" (e.g., "2, 9", but without the
quotes); if this method is called before the current dice
have been rolled for the first time (or right after the
'reset' method has been called), an empty string should be
returned
-------------
sum
Arguments: None
Displays: Nothing
Returns: An integer equal to the sum of the most recent roll of the
two CURRENT dice; if the dice have not yet been rolled (or
if the 'reset' method has just been called), a zero should
be returned
-------------
total
Arguments: None
Displays: Nothing
Returns: An integer equal to the sum of ALL of the rolls so far of
the two CURRENT dice; if the dice have not yet been rolled
(or if the 'reset' method has just been called), a zero
should be returned
-------------
reset
Arguments: None
Actions: Resets the internal "sum" and "total" dice values to zero,
and also clears the internal 'last roll' values of the dice
(as if the current dice have never been rolled)
Displays: Nothing
Returns: Nothing
-------------
changeDice
Arguments: Two positive integers representing the number of sides of
two separate fair dice
Actions: Changes the number of sides of the two dice to the newly
supplied values; also calls the 'reset' method to clear
all internal sum values and the roll history
Displays: Nothing
Returns: Nothing
Point Value: 20
Due Date: Friday, 2-12-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #5
To the 'DiceRoll' class, add another public method named 'cheatRoll' that
functions in the same manner as the 'newRoll' method, except that for each
die, regardless of the number of sides on the die, it should be twice as
likely that an even number (as opposed to an odd number) will be rolled.
EC Due Date: Friday, 2-12-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #5
To the 'DiceRoll' class, add another public method named 'showLastRoll' that
functions in the same manner as the 'lastRoll' method, except that it returns
nothing, but instead displays a JFrame containing the two values of the most
recent dice roll. It is up to you how you display the two values on the
JFrame (text in labels, graphically with images, large dots, etc.).
EC Due Date: Friday, 2-12-2021
CLASSWORK #6
06) Create a non-static class named 'SimpleCalculator' in its own file. The
class should contain a single constructor and should perform addition and
multiplication of sets of two and three numbers of type double. When the
following sample 'main' code is run, it should produce the exact output
shown below:
SAMPLE CALLING CODE:
public static void main(String[] args)
{
SimpleCalculator calc = new SimpleCalculator();
calc.add(3.5, 4.2);
calc.add(2.45, 7.1, 3.6);
System.out.println();
calc.multiply(1.9, 8.4);
calc.multiply(3.8, 2.57, 4.6);
}
EXACT OUTPUT FROM ABOVE CODE:
The sum of 3.5 and 4.2 is 7.70.
The sum of 2.45 and 7.1 and 3.6 is 13.15.
The product of 1.9 and 8.4 is 15.96.
The product of 3.8 and 2.57 and 4.6 is 44.92.
You must use the 'printf' method to display all answers (sums and products)
rounded to exactly two decimal places. (Do not change the manner in which
user-supplied numbers are displayed.)
The above sample calling code is merely an example. Your 'SimpleCalculator'
class should be able to add and multiply ANY two-number and three-number
combinations. Also, remember that the method 'main' and the keyword
'static' must not appear anywhere in the 'SimpleCalculator' class.
Point Value: 20
Due Date: Friday, 2-26-2020
EXTRA CREDIT OPTION #1 FOR CLASSWORK #6
To the 'SimpleCalculator' class, add two more public methods, named
'addUnlimited' and 'multiplyUnlimited', both of which allow an unlimited
number of arguments of type double. These two new methods do not need to
display the arguments back to the user. They do, of course, need to
display the calculated answers. Note that you may complete the other
extra credit options in addition to, or instead of, this option.
EC Due Date: Friday, 2-26-2020
EXTRA CREDIT OPTION #2 FOR CLASSWORK #6
To the 'SimpleCalculator' class, add two more public methods, named
'subtract' and 'divide'. The 'subtract' method should take two
arguments (doubles) and display the result when the second number is
subtracted from the first number. Display the result in the same
manner that the 'add' and 'multiply' methods display their results.
The 'divide' method should work in the same manner as the 'subtract'
method, except that the two numbers should be divided. However,
if the second number is zero, then display a statement indicating
that a number cannot be divided by zero. Note that you may complete
this extra credit option in addition to, or instead of, either of
the other options.
EC Due Date: Friday, 2-26-2020
EXTRA CREDIT OPTION #3 FOR CLASSWORK #6
To the 'SimpleCalculator' class, add additional methods of your
choosing. For example, you might add a 'power' method that takes
two integer arguments and then raises the first integer to the
power of the second (e.g., power(2, 5) displays 32). Or, you might
add a method named 'squareRoot' which displays the square root of a
number. These are just examples, and you should consider adding
other methods of your choosing. For each method that you add, also
add code to the constructor that displays a message (whenever a
'SimpleCalculator' object is created) that tells the user what
methods are available in your calculator. Be sure to include in
the message the required methods, as well as any additional methods
that you added for the above extra credit options. Note that you
may complete this extra credit option in addition to, or instead
of, any of the above options.
EC Due Date: Friday, 2-26-2020
CLASSWORK #7
07) The purpose of this assignment is to have you practice using a JFrame, JButton,
JLabel, and JTextField, as well as ActionListeners and KeyListeners. So, for
this classwork, you are to write a program that is contained in a single file
(named "ShowEntry.java") that contains one JFrame. You may choose the layout,
size, background color, and title of the JFrame, but make sure the JFrame
appears in the center of the user's screen, is not resizable, and will close
(and also end the application) when a user clicks on the "X" in the upper-right
corner of the JFrame.
On the JFrame you should place one JButton, one JLabel, and one JTextField.
When the program starts, only the JTextField should be visible (and it should
have the focus). The JButton should appear only when text has been typed into
the JTextField. If the user types text into the JTextField, and then erases
all of it, the JButton should become hidden again.
When the user clicks the JButton, three things should happen: 1) the JButton
should disappear, 2) the JLabel should appear, displaying in it whatever text
the user has typed into the JTextField (it is okay if not all of the characters
in the JTextField can fit into the JLabel), and 3) the text from the JTextField
should be cleared (but the empty JTextField should remain visible). If the
user again types text into the JTextField, if the JLabel is visible, it should
be made hidden until the JButton is clicked again.
You may choose the locations, sizes, and colors of the JButton, JLabel, and
JTextField, including their font sizes and colors. Make sure all components
on the JFrame are neat and organized.
When writing your code for this program, you should NOT extend the "JFrame"
class. In other words, you are not to use the "default" JFrame, but should
instead explicitly define and use your own JFrame within your program.
Point Value: 20
Due Date: Friday, 3-12-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #7
Limit the number of characters that a user can type into your JTextField to
the amount of characters that can fit into (and be visible in) your JLabel.
EC Due Date: Friday, 3-12-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #7
Add a menu bar to the JFrame of the 'ShowEntry' class. The menu bar should
contain two top-level items: "File" and "Edit". Under "File" should be an
option to close the JFrame and quit the program. Under "Edit" should be an
option to clear the text from the JLabel. You are welcome to put additional
items in the menu bar.
EC Due Date: Friday, 3-12-2021
CLASSWORK #8
08) Write a Java program contained in a single file (named "NoRepeats.java") that
uses a loop to have the user enter a list of up to ten words (or phrases), one
per line. The user should signal the end of the list by pressing the ENTER
key by itself on an empty line. Your program must require the user to enter
at least one word or phrase (by continuously querying the user until at least
one entry is made), and it should not allow the user to enter more than ten
words or phrases (after the tenth entry it should stop asking for new input).
Your program must eliminate leading and trailing spaces from all user input.
In addition to the above requirements, your program must use a loop to prevent
the user from entering duplicate words or phrases. If the user enters a word
or phrase that has already been entered, discard that entry, tell the user
that duplicate entries are not allowed, and then have the user enter a new
word or phrase. Your program should not modify the case of the words or
phrases, but it should ignore case when checking for duplicate entries.
Finally, after the user has entered up to ten unique words or phrases, your
program should use a loop to display the word/phrase list back to the user,
one entry per line. The words/phrases should be displayed back to the user in
the same order in which they were entered. When displaying the list, if it
contains fewer than ten words or phrases, make sure no blank (empty) lines or
'null' entries are displayed.
For this program you must use a built-in Java array of strings to store the
words and phrases. You are allowed to use only one array, and you may not use
any other type of List (such as an ArrayList) or Collection anywhere in your
program. Also, the maximum number of entries allowed (10) should be stored in
your program as a globally-defined integer constant (all capital letters), and
with the exception of the line where you define the constant, the number 10 (or
9 or 11) should not appear anywhere in your program.
Other than the global constant and array of strings, you may not use any
global variables for this assignment. In addition to 'main', you should have a
separate method that gets the entries from the user, another method that checks
for duplicate entries, and another method that displays the word/phrase list
back to the user.
Point Value: 20
Due Date: Wednesday, 3-24-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #8
When displaying the words back to the user, display the words arranged in
order by length (number of characters), with the shortest word shown first.
If the list contains multiple words with the same number of characters, then
that group of words should be displayed in ascending alphabetical order
(within the larger list of words, which should still be sorted by length).
This extra credit option can be completed along with, or instead of, either or
both of the other two extra credit options. You may use additional arrays
for this extra credit option.
EC Due Date: Wednesday, 3-24-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #8
This option can be completed before or after, or instead of, the other extra
credit options. When displaying the words back to the user, number each word
(starting with "1"). Then, after the list has been displayed, allow the user
to change the order of the words in the list by swapping the positions of any
two of the words. The user should be able to type the numbers of two words in
the list to indicate which words should be swapped, after which the list should
be re-displayed in its new order (with all of the words newly renumbered). The
user should be allowed to continue to change the order of words indefinitely by
swapping sets of two words, with the list being re-displayed after each swap.
There should also be a way for the user to quit the program at any time. You
may use additional arrays for this extra credit option.
EC Due Date: Wednesday, 3-24-2021
EXTRA CREDIT OPTION #3 FOR CLASSWORK #8
After the list of words is displayed to the user, give the user two choices of
actions. The first choice is to save the word list to a disk text file. The
user should be able to choose the name (but not necessarily the location) of
the file. The second choice is to load and display an existing saved word
list. Once again, the user should be able to specify the name of the file to
be loaded (and the location, if locations can be specified when saving files).
The user should be able to save an unlimited number of disk text files. When
specifying a file name, if a file with that name already exists, then the user
should be told to choose a different file name (or location, if applicable).
When choosing a file to load from disk, the user should always be shown the
current list of text files in the folder from which the file is to be loaded.
If the user-specified file name does not include a "dot" suffix (file type),
then your program should automatically add ".txt" to the end of the name. It
is not necessary to trap for any exceptions that may occur while writing or
reading files, and there should be no way for a user to overwrite or delete
any disk text files. This extra credit option can be completed along with, or
instead of, either or both of the above two extra credit options. You may
use additional arrays for this extra credit option.
EC Due Date: Wednesday, 3-24-2021
CLASSWORK #9
09) Write a Java program contained in a single file (named "MeanMedianRange.java")
that has the user enter an unlimited number of integers, one per line. After
the user presses the ENTER key on an empty line by itself, the program should
compute and display the mean, median, and range of the entered numbers (please
label the output). Since the mean and median of a set of integers can be a
double, use the 'printf' method to always display the mean and median (but not
the range) rounded to exactly two decimal places. Also, be sure to gracefully
handle the case where the user does not enter any numbers, as well as the case
where the user enters only one number.
For this program you should use the 'ArrayList' class to create an array of
integers (the list must contain integers, not strings). In addition to
'main', you should have a separate method that gets the integers from the
user, another method that computes and displays the mean, another method for
computing and displaying the median, and another method to compute and display
the range of the numbers. You may use additional methods if you wish.
In this program you are allowed to use only one ArrayList, and you may not use
any other type of List or Collection anywhere in your program (although you
may use the 'Collections' class to sort your ArrayList). Other than the
ArrayList of integers, you may not use any global variables for this
assignment. Also, you must use a 'try-catch' block to error trap for "bad"
user input. If the user enters a non-integer (a double or a string), discard
the entry, display an appropriate message, and then continue to collect data.
Point Value: 20
Due Date: Friday, 4-2-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #9
Create an additional method in your program that computes and displays the
mode(s) of the integers entered by the user. Remember that a set of numbers
can have multiple modes. If you wish, you may use an additional ArrayList
for this extra credit option.
EC Due Date: Friday, 4-2-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #9
After displaying the mean, median, and range (and mode, if you completed the
above extra credit option) of the user-entered numbers, display (in either a
JFrame or the console), the user-entered integers in a column (bar) graph. The
X-axis should represent the range of numbers, while the Y-axis should show the
frequencies of the numbers. The range and frequencies of the numbers should
be used to determine the scales of the axes. You may choose the overall size
of the graph, as well as its colors and other characteristics. If you wish,
you may use more than one ArrayList for this extra credit option.
EC Due Date: Friday, 4-2-2021
CLASSWORK #10
10) Write a Java program contained in a single file (named "DataStorage.java")
that reads a series of key-value pairs, one per line, from a disk text (data)
file. Each key-value pair represents a name (string), followed by an age
(integer). I have created a sample data file for you to use when writing and
testing your program (see my sample program output below). You may use the
provided file or a different file of your choosing, as long as it contains
data in the same format: each line contains a string, followed by a space,
followed by an integer. (When I test your submitted program, I will use a
different data file with different name/age key-value pairs.) You can
download my sample data file here.
Regardless of the data file that you use, when your program first starts it
must always ask the user to enter the exact name of the data file to be read
from disk. If the file is not found, then your program should report that
error to the user and then quit. Other than handling a missing file, your
program does not need to error trap for bad data within the file or for a
badly-formatted file. You may assume that the names will not contain any
spaces. Be sure to write your program to work with data files containing
any number of key-value pairs.
As you read each key-value pair from the disk file, you must add it to a
<String, Integer> HashMap. Your program must contain exactly one HashMap,
and you may not use any other type of HashMap or List or Collection. Also,
make sure your program reads the data from the given disk text file exactly
once. You may make your HashMap (and other variables) global.
After reading and storing the data in a HashMap, your program should display
all of the key-value pairs in the HashMap (in any order), one key-value pair
per line (see my sample program output below). Then your program should
ask the user to enter a key (name). If that name is in the HashMap (ignoring
case), then that name, along with the corresponding age, should be displayed.
Lastly, your program should ask the user to enter a value (age), after which
it should display all of the key-value pairs (if any exist) that contain the
given age. For each of the above two user entries, if no key-value pairs
are displayed, present the user with an appropriate message (see my program).
Your output does not have to look exactly like the output from my program,
but it should be presented neatly and formatted in a similar manner.
In addition to 'main', you should have a separate method (called from 'main')
that gets the name of the disk text file from the user, reads in the key-value
pairs from that file, and then puts them into a HashMap. Another method, also
called from 'main', should display all of the HashMap data. Still another
method, once again called from 'main', should handle checking the HashMap for
the user-supplied name, and yet another method, called from 'main', should
handle checking the HashMap for the user-supplied age. Other than handling a
user-supplied name or age that is not found, you do not need to error trap for
bad user input.
Sample Output #1
Please provide a name/age data file: mapdata.txt
Names and Ages:
Marie --> 12
Nicole --> 17
Ellen --> 17
Alexander --> 14
Susan --> 17
Michael --> 16
Charlie --> 18
Dave --> 16
Enter a name to find in the Hashmap: Dave
Dave --> 16
Enter an age to find in the Hashmap: 17
Nicole --> 17
Ellen --> 17
Susan --> 17
Sample Output #2
Please provide a name/age data file: mapdata.txt
Names and Ages:
Marie --> 12
Nicole --> 17
Ellen --> 17
Alexander --> 14
Susan --> 17
Michael --> 16
Charlie --> 18
Dave --> 16
Enter a name to find in the Hashmap: Alex
The name "Alex" was not found.
Enter an age to find in the Hashmap: 16
Michael --> 16
Dave --> 16
Sample Output #3
Please provide a name/age data file: mapdata.txt
Names and Ages:
Marie --> 12
Nicole --> 17
Ellen --> 17
Alexander --> 14
Susan --> 17
Michael --> 16
Charlie --> 18
Dave --> 16
Enter a name to find in the Hashmap: Susan
Susan --> 17
Enter an age to find in the Hashmap: 22
No one was found with an age of 22.
Sample Output #4
Please provide a name/age data file: mapdata
Error: mapdata (The system cannot find the file specified)
Point Value: 15
Due Date: Friday, 4-23-2021
EXTRA CREDIT OPTION #1 FOR CLASSWORK #10
After creating all of the above methods, create an extra method that
sorts the key-value pairs in ascending alphabetical order by name.
Then display all of the sorted data to the user. While you may not use
any other type of List or Collection, you may use a second HashMap (and
a different type of HashMap, if you like, for this extra credit method
only.
EC Due Date: Friday, 4-23-2021
EXTRA CREDIT OPTION #2 FOR CLASSWORK #10
After doing all of the above (including the first extra credit option),
create another extra method that writes the data from the modified (or
new) HashMap to a disk text file (different from the file from which
the data were read). The data in the new file should be in the same
format as the data in the original disk text file (so that the new file,
itself, can be read by your program).
EC Due Date: Friday, 4-23-2021