Professional Documents
Culture Documents
Sample Input/Output How Many Names: 4 Give Name 1:elvis Give Name 2:priscilla Give Name 3:vernon Give Name 4:lisamarie Lisamarie Vernon Priscilla
Sample Input/Output How Many Names: 4 Give Name 1:elvis Give Name 2:priscilla Give Name 3:vernon Give Name 4:lisamarie Lisamarie Vernon Priscilla
Write a program that asks how many names the user wants to input, asks for
those names, and shows the names afterwards. But it should only show names
that are longer than 5 characters (Array List/LinkedList)
Sample Input/Output
How many names: 4
Give name 1:Elvis
Give name 2:Priscilla
Give name 3:Vernon
Give name 4:LisaMarie
LisaMarie
Vernon
Priscilla
2. Suppose you have a set s containing some strings. Write a code fragment that
uses an iterator to print out each element in s.
3. Write Java code to define yet another Set S. Insert 3 floating point numbers in S
and find the sum of the numbers in S using Stream API.
4. Write a Java code and demonstrate the following:
a. Create a new HashMap and populate with below elements
i. Orange 50
ii. Apple 100
iii. Grapes 70
iv. Strawberry 150
b. Iterate over the HashMap and print key and value
c. Retrieve a value associated with a given key from the HashMap (key your
choice)
d. Check whether a particular Apple exist in a HashMap. If so print the<key,
Value> pair, if not print not exists
5. Julie has created a TreeMap containing name and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the
following operations:
a. Push the keys (name of the student) of the hash map into a stack,
where the corresponding value(marks) is greater than 75.
b. Pop and display the content of the stack.
Sample Input /Output:
Om:76
Jai:45
Bob:89
Ali:65
Anu:90
Tom:82
Output:
Tom,Anu,Bob,Om
7. Implement a superclass Appointment and subclasses Onetime, Daily, and
Monthly. An appointment has a description (for example, “see the dentist”) and a
date.
Implement methods occursOn(int year, int month, int day) for each of the
subclasses that checks whether the appointment occurs on that date or not and
return true or false respectively. For example, for a monthly appointment, you
must check whether the day of the month matches.
Create a tester class that creates various objects from all the implemented
classes and call their occursOn method to see if you have implemented the
classes to do the right calculations.
Give the user the option to add new appointments. The user must specify the type
of the appointment, the description, and the date. You do NOT need to save these
in a file, once the program terminates all appointments are lost. Add another
method dayOfTheWeek in class Appointment which returns a string
corresponding to the day of the week that the appointment occurs, e.g if the
appointment occurs on 17 October 2015, the method returns “Sunday”. (Hint: use
the GregorianCalendar library class).
Implement a method displayAll() which displays all the appointments sorted by
date in ascending order, i.e. appointments occurring at an earlier date should be
displayed first.
8. In this, you will find a CatalogItem class which represents an item from a
product catalog. These catalog items are provided in form of a CSV file and are to
be loaded into a list, but it's ordering is randomized (Collections .shuffle()).