Q1. You are given M number of coins and P number of notes.
Write a program to separate the two forms of money without creating two separate classes for notes and coins.
(The order of the output should be the same as that of the input).
Input format
First line : N
Next N lines : Space-separated string S and an integer val (where S is either a Coin or
a Note and val denotes the denomination of a coin or a note)
Output format
Print the string Coins: followed by M lines, each of which contains an integer denoting the denominations of the
coins.
Print the string Notes: followed by P lines, each of which contains an integer denoting the denominations of the
notes.
Constraints
1≤N≤102
1≤Val≤102
Description of Classes:
You need to design 3 classes:
Bag
Coin
Note
Note and Coin Class
Both the classes have common attributes as well as common methods.
Attributes:
Val: refers to the denomination of the coin or note
Methods:
setvalue(int val): Set the denomination of the coin to the value which is passed as a parameter.
Bag Class
This should be a generic class.
Methods
add(Type t): Add the coin or note to the bag.
Display(): Display the denomination of the coin or note.
Q2. When a subclass inherits from a superclass, it also inherits its methods; however, it can also override the
superclass methods (as well as declare and implement new ones). Consider the following Sports class:
class Sports{
String getName(){
return "Generic Sports";
}
void getNumberOfTeamMembers(){
[Link]( "Each team has n players in " + getName() );
}
}
Next, we create a Soccer class that inherits from the Sports class. We can override the getName method and return
a different, subclass-specific string:
class Soccer extends Sports{
@Override
String getName(){
return "Soccer Class";
}
}
Note: When overriding a method, you should precede it with the @Override annotation. The parameter(s) and
return type of an overridden method must be exactly the same as those of the method inherited from the
supertype.
Task
Complete the code in your editor by writing an overridden getNumberOfTeamMembers method that prints the
same statement as the superclass' getNumberOfTeamMembers method, except that it replaces with (the number
of players on a Soccer team).
Output Format
When executed, your completed code should print the following:
Generic Sports
Each team has n players in Generic Sports
Soccer Class
Each team has 11 players in Soccer Class
Q3. Write a Java program to convert a linked list to array list.
Q4. Write a Java program to append the specified element to the end of a hash set.
Q5. Write a program to print "Good morning" and "Welcome" continuously on the screen in Java using threads.
Add a step method in the welcome thread to delay its execution for 200ms.
Q6. Demonstrate gerPriority() and setPriority() methods in Java threads. How do you get the state of a given
thread in Java? How do you get the reference to the current thread in Java?