This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

David McWilliams

Ranch Hand
+ Follow
since Mar 14, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David McWilliams

If I have the SCJP 5 exam already passed, do I still have to start with the OCA before going to OCP?
Thanks for your reply.

No, I have no experience of Java 7 either.

Can you tell me the difference between the OCA and OCP exam? Am I foolish taking on the OCP exam without having written an LOC in Java 8?
Many moons ago I passed the SCJP 1.5 exam. I'm told I can skip the full OCP Java 8 exam and just to the Java 8 Upgrade exam 1Z0-813.

The aim of me doing this exam is to teach me Java 8. I have no personal or commercial experience in it. Is the Upgrade exam a good way of teaching me Java 8?

If so, is there a book I can buy? I see that the OCP 8 book is not out until January 2016.

Junilu Lacar wrote:

David McWilliams wrote:Am I correct in saying I should have a separate strategy for each year?


That's probably too fine-grained for what you described. I would go for a strategy for each type of customer. That is, however many different interest tables you have, that would be how many strategies you'd have to implement and choose from.

Edit: Sorry, I thought you meant something else when I read "separate strategy for each year".

Another way might be to base it on the different sets of "bands" you have, then just parameterize the interest rates. In the examples you gave, you'd have two strategies, with the strategy with three bands being parameterized for it's interest rates. That might be over-complicating things though. I usually experiment with different approaches before I decide which one to go with. Seeing the code gives you a better feel for how maintainable and understandable it is vs. just thinking about it.



Would that be 7 strategies for my example then? Sorry about the questions. I'm new to this game and am not sure how to implement this strategy approach.
6 years ago
I've been reading up on the Strategy pattern. A different strategy is chosen based on the specific data inputted. Am I correct in saying I should have a separate strategy for each year?
6 years ago

Campbell Ritchie wrote:Also do not use -1. How do you know you will get -1 back from the compareTo() method? If you look at its documentation, it says nothing about returning 1 or -1. It says negative positive or 0. It says signum returns -1 0 1, but you are not using signum.



Thanks. I have changed that.
6 years ago

Junilu Lacar wrote:Also, you have declared some pseudo constants--I say "pseudo" because they follow the naming convention but they're not declared as final--but you fail to use them in your calculations, preferring to use hard-coded values instead.



Thanks - I'll fix that.

I'll have a read on Strategy pattern. Do you think implementing a strategy is over-complicating it? I'm not saying it is, I'm just trying to be careful not to over complicate the solution.
6 years ago
I have written a program that, given an amount, returns the interest you would receive on that figure for a bank's customer. There are 3 interest rate bands as follows:

1% - £0 to £1000
2% - £1000 to £5000
3% - £5000+


I would like to amend the program to cater for different bands for different customers. If a customer is with the bank for a period of time, she gets a better rate. Here are the new rates:

After one year:

1% - £0 to £1000
2.5% - £1000 to £5000
4% - £5000+

After two years:

2% - £0 to £1000
3% - £1000 to £5000
4% - £5000 to £10000
5% - £10000+

My initial approach is below. Can anyone suggest how I'd go about implementing the additional part? I want the program to be as simple as possible with minimal complexity. I don't want an all-compassing solution, just something that works well and is extensible.

6 years ago
I was unable to figure out the answer so I've tried the following:



So 2013-03-17T09:00:00Z converts to 2013-03-17 09:00 +0000
6 years ago
I need to convert a date from one format to another, as follows:

2013-03-17T19:12:14Z -> 2013-03-17 19:12 +0100



Prints:
date 2013-01-17T09:00:00.000Z

Can anyone tell me how to get my desired format? I've tried everything.
6 years ago

H Paul wrote:Have you look into Jackson Json Annotation?



No but I will. Can you tell me what part of the problem it will solve? I'm already using Gson..
6 years ago

H Paul wrote:So mechanically:
1. Use JAXB to unmarshall xm string into a list of xml annotated Car class (ford)
2. Then use Jackson Json to jsonize the list of xml annotated Car class.



Thanks for your reply.

I have made progress on the application and here it is:

I have witten the following methods:

String getAllCars();
Calls Interface 1 above returning all cars as a sample XML file in a string format (I must adhere to this exact format).

List<Cars> parseCars()
Generates a list of Car objects based on the XML file. The Car object has other sub objects, e.g. owner.

List<Cars> searchCars(String make)
Loops through the list of cars from above and finds any cards specified by make.
Return a new list of those cars.

String convertToJSON()
Converts the list above into a JSON object.

This JSON object is then returned to the user.

The only issue I have is that the XML file and the JSON formats differ. E.g. instead of the Person object in the XML, the JSON just wants the person name, no other data. I must adhere to the JSON format given.

My question is, what is the best design for this? Would it be best to have to groups of Car objects (and sub objects), e.g. a group that are used to store the XML data, and a new group that are used to convert to JSON. I could write a convertor methods to do the conversion.

Would that be a good design or can you hink of a more effecient method? Is 2 groups of objects excessive?
6 years ago

H Paul wrote:Can you clarify? Is that soapful or restful web service?

Call external web service to get an XML file (as string)

of all Car information.



It's not either really. All I have is an interface with one method: getAllCars();

My program has 2 interfaces:
1. Gets all cars in XML string.
2. Call interface 1. method getAllCars() and parse the data.

I have to implement interface number 2. Interface number 1 is mocked.

So it's just a trivial little program. I suppose I could wrap the 2 Interfaces with a web service later.
6 years ago
Can any give their opinions on my design?

Write Java web service to:

Call external web service that returns an XML document as a String of 'Car' information.
Search this xml/string object for particular Car (bring me back all Fords).
Return all Fords as a JSON object.
Solution:

Call external web service to get an XML file (as string) of all Car information.
Using JAXB, parse this String object into multiple Car objects.
Loop through the car objects and when I find a Ford, add it to a Car list.
Loop through Ford list and convert the list into a JSON object.
Return JSON object from web service.

I need my solution to demonstrate good coding practices, not just get a working solution.

What do you think?
6 years ago