Professional Documents
Culture Documents
Problems PDF
Problems PDF
You are given a list of transactions that needs to be processed as part of your job at the
bank. Since the list can be very long, and you are somewhat error prone I you
arithmetic, you decide to create a java program that will do the work for you. Create a
class BankManager. You need to provide two methods readData() and toString(). Read
data take in an InputStream as an argument of that contains the various transactions. It
then clears any old data, executes the transactions and saves the results into some field
in the BankManager class. There are four transactions: CREATE, DEPOSIT,
WITHDRAW and TRANSFER. CREATE,<account name>,<initial amount> creates an
account and gives it an initial balance. WITHDRAW/DEPOSIT,<account
name>,<amount> withdraws/deposits money to an account. TRANSFER,<from
account>,<amount>,<to account> transfers money from one account to another. If a
transaction would result in an account having a negative balance, do not execute it. The
toString method then return a string representation of the accounts in the order they
were created in the following form: <account owner>,<balance to 2 decimal
places><new line>.
+--------+
| \ |
| / |
+--------+
0123456789
0+--------+
1|> \ |
2| / |
3+--------+
Supervisor
You are given a list of employees and their supervisor in csv format. Each employee
can either have only one supervisor, or no supervisor at all. Your job is for each
employee to be able to list who they supervise.
Create a class SupervisorFinder. It should have two methods: load() and toString(). The
method load() is static and take in a Reader as an argument that contains the list of
employees, and returns a new SupervisorFinder object. Each line will either be of the
form <employee>,<supervisor> or if there is no supervisor, <employee> by itself. The
toString method should return a String that represents the employees and everyone the
supervise in the following format (note neither order is important nor whitespace outside
of quoted strings):
{“<employee1>”:[“<supervisee1>”,“<supervisee2>”,…],“<employee2>”:[“<supervisee1>”,
”<supervisee2>”,…],…}
An example input is:
A. Person,A. Nother
Sum One
A. Nother, Some One
The result of toString() should be: {“A. Person”:[“”], “Sum One”:[“A. Nother”], “A.
Nother”: [“A. Person”]}
Email Lister
You are given a list of emails and need to group them base on their email. The
domain of the email is the part after the @. So for fobar@example.com, the domain
would be example.com.
Create a class EmailLister. It should have two methods: load() and toString().The
method load() is static and take in a Reader as an argument that contains the list of
employees, and returns a new EmailLister object. The file will simply be each email
on its own line. The toString method should return a String that represents the
domain and al emails in that domain in the following format (note neither order is
important nor whitespace outside of quoted strings): { “<domain1>”:[ “<email 1>”,
“<email 2>”….], “<domain2>”:[ “<email 1>”, “<email 2>”….] … }
An example input is:
google@google.com
foobar@yahoo.com
youtube@google.com
baar@yahoo.com
microsoft@msn.com
gmail@google.com
Your job is to keep track of counts in a list. You need to be able to answer 2 queries:
add a number to cell in a range and get the sum of all cells in a range. You do not
know the size of the list and all elements start out at 0.
Example input:
1,10, 1
5,6, -2
Your job is to take in a string and a list of rules that tell you how to replace
characters in the string. For example given a String “ABC” and rules “A” => “AA” and
“B”=>”C” would produce “AACC”.
Create a class String Replacer. It should have two methods addRule() and replace()
and a no arguments constructor. The method addRule() takes in a char that
represents the character to replace, and a String that represents the replacement
text. Note: if multiple rules exist for a given char, use the one that was added last.
The replace() method takes in a String and replaces the characters in the String
based on the rules given, and the return the resulting String. If there is no rule for a
given character, do not replace it.
For example after calling addRule(‘1’, “11”) and addRule(‘0’, “0[0]1”), calling
replace(“0”) should return "1[0]0", replace("1[0]0") "11[1[0]0]1[0]0", and
replace("11[1[0]0]1[0]0") "1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0"