Working With Abstraction - Exercise
Working With Abstraction - Exercise
This document defines the exercises for the "Java Advanced" course @ SoftUni.
Please submit your solutions (source code) to all below-described problems in Judge.
Examples
Input Output
Card Suits Card Suits:
Ordinal value: 0; Name value: CLUBS
Ordinal value: 1; Name value: DIAMONDS
Ordinal value: 2; Name value: HEARTS
Ordinal value: 3; Name value: SPADES
Examples
Input Output
Card Ranks Card Ranks:
Ordinal value: 0; Name value: ACE
Ordinal value: 1; Name value: TWO
Ordinal value: 2; Name value: THREE
Ordinal value: 3; Name value: FOUR
Ordinal value: 4; Name value: FIVE
Ordinal value: 5; Name value: SIX
Ordinal value: 6; Name value: SEVEN
Ordinal value: 7; Name value: EIGHT
Ordinal value: 8; Name value: NINE
Ordinal value: 9; Name value: TEN
Ordinal value: 10; Name value: JACK
Ordinal value: 11; Name value: QUEEN
Ordinal value: 12; Name value: KING
© SoftUni – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Note
Try using the enumeration types you have created in the previous problems but extending them with constructors
and methods. Try using the Enum.valueOf().
Examples
Input Output
TWO Card name: TWO of CLUBS; Card power: 2
CLUBS
ACE Card name: ACE of SPADES; Card power: 53
SPADES
Examples
Input Output
GREEN RED YELLOW YELLOW GREEN RED
4 RED YELLOW GREEN
GREEN RED YELLOW
YELLOW GREEN RED
RED RED RED GREEN GREEN GREEN GREEN YELLOW YELLOW YELLOW
GREEN GREEN YELLOW YELLOW YELLOW RED RED RED
6 RED RED RED GREEN GREEN GREEN
GREEN GREEN GREEN YELLOW YELLOW YELLOW
YELLOW YELLOW YELLOW RED RED RED
RED RED RED GREEN GREEN GREEN
© SoftUni – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
The input ends when you receive the command "Let the Force be with you". When that happens, you must
print the value of all-stars that Peter has collected successfully.
Input
On the first line, you will receive the number N, M -> the dimensions of the matrix. You must then fill the
matrix according to these dimensions.
On the next several lines you will begin receiving 2 integers separated by a single space, which represent
Peter’s row and col. On the next line, you will receive the Evil Power’s coordinates.
There will always be at least 2 lines of input to represent at least 1 path of Peter and the Evil force.
When you receive the command, "Let the Force be with you" the input ends.
Output
• The output is simple. Print the sum of the values from all-stars that Peter has collected.
Constraints
The dimensions of the matrix will be integers in the range [5, 2000].
The given rows will be valid integers in the range [0, 2000].
The given columns will be valid integers in the range [-231 + 1, 231 - 1].
© SoftUni – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
If you read an item that breaks one of these rules you should not put it in the bag. You should always be careful
not to exceed the overall bag’s capacity because it will tear down and you will lose everything! You will receive the
content of the safe on a single line in the format "{item} {quantity}" pairs, separated by whitespace. You
need to gather only three types of items:
Cash - All three letter items
Gem - All items which end on "Gem" (at least 4 symbols)
Gold - this type has only one item with the name - "Gold"
Each item that does not fall in one of the above categories is useless and you should skip it. Reading item’s
names should be CASE-INSENSITIVE, except when the item is Cash. You should aggregate items’ quantities that
have the same name.
If you’ve kept the rules you should escape successfully with a bag full of wealth. Now it’s time to review what
you have managed to get out of the safe. Print all the types ordered by the total amount in descending order.
Inside a type, order the items first alphabetically in descending order and then by their amount in ascending order.
Use the format described below for each type.
Input
On the first line, you will receive a number that represents the capacity of the bag.
On the second line, you will receive a sequence of item and quantity pairs.
Output
Print only the types from which you have items in the bag ordered by Total Amount descending. Inside a type
order, the items are first alphabetically in descending order and then by an amount in ascending order. Use the
following format for each type:
"<{type}> ${total amount}"
"##{item} - {amount}" - each item on new line
© SoftUni – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
150 <Gold> $28
Gold 28 Rubygem 16 USD 9 GBP 8 ##Gold - 28
<Gem> $16
##Rubygem - 16
<Cash> $9
##USD - 9
24000010 <Gold> $10300000
USD 1030 Gold 300000 EmeraldGem 900000 Topazgem 290000 ##Gold - 10300000
CHF 280000 Gold 10000000 JPN 10000 Rubygem 10000000 <Gem> $10290000
KLM 3120010 ##Topazgem - 290000
##Rubygem - 10000000
<Cash> $3410010
##KLM - 3120010
##JPN - 10000
##CHF - 280000
80345 <Gold> $80000
RubyGem 70000 JAV 10960 Bau 60000 Gold 80000 ##Gold - 80000
© SoftUni – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.