Notes and coins <OOPS - Java, Java8>
Practice
2.6 (11 votes)
Basic programming
Basics of implementation
Easy
Grammar Verified
Implementation
Java
Oops
Oops
Python
Python
Problem
76% Success 2168 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \le N \le 10^2 \)
\( 1 \le Val \le 10^2 \)

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.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
20 votes
Tags:
ArraysBasic ProgrammingEasy
Points:20
11 votes
Tags:
Easy
Points:20
12 votes
Tags:
ApprovedBasic ProgrammingBrute-force searchEasyOpen