Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Bank Transactions:

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>.

For example, a file with transactions might look like:


CREATE,John Doe,100.00
CREATE,Jane Doe,130.50
DEPOSIT,John Doe,50.00
WITHDRAW,Jane Doe,200.00
TRANSFER,John Doe,100,Jane Doe

The resulting output should be


John Doe,50.00
Jane Doe,230.50
Laser Tracer
Your task is to simulate a laser beam. The beam will be fired on a grid that contains
mirrors. Create a class LaserTracer. It need to have 2 methods: load() and
getCollision(). Load is a static method that returns a new LaserTracer. It will the read
the grid from a java.io.Reader that is an argument to the function. An example grid is at
the bottom. The grid contains a border of asci characters and slashes that represent
mirrors. getCollision takes a java.awt.Point, which is the position of the laser in the grid,
and an int for the direction of the beam, 0=up, 1=right, 2= down, 3= left. It then will
return the position of where the beam hits the wall as an java.awt.Point. Mirrors on the
grid will bounce the beam at a 90 degree angle.

+--------+
| \ |
| / |
+--------+

A beam at (1,1) heading right will collide at (0,2)

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

and the result of toString(): {“google.com”: ["youtube@google.com",


"google@google.com", "gmail@google.com"], "yahoo.com": ["foobar@yahoo.com",
"baar@yahoo.com"], “msn.com”: ["microsoft@msn.com"]}
ArrayCounts

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.

Create a class ArrayCounter. You need to provide 2 methods: getTotal() and


load().The method load() is static and take in a Reader as an argument that contains
the list of employees, and returns a new ArrayCounter object. It take in input in the
following form: <from>,<to>,<amount>. The from and to are positive integers that tell
you the range of cells and amount is an integer that tells you how much to add to
each cell. getTotal() takes in two integers and returns the total of all integers in the
range. The first int tells you the start of the range and the second the end of the
range. Note the may include cells that are beyond the range you have incremented
so far.

Example input:
1,10, 1
5,6, -2

Calling getTotal(6,100) should return 3.


String Replacer

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"

You might also like