Hey guys i hope someone can point me in the right direction

The problem
I have just started my first year in computer science and have just recieved my first java assignment. I know its really simple but i just cant get my head round it, the worse thing is, although it was simple stuff, i actually did some java last year so this SHOULD be a doddle. I have been looking for help online but because my lecturer thought it would be a good idea to start with applets i am finding that all the examples and tutorials are way above my head. there are whole chunks of jargon and code that i just dont understand (last year i did VERY SIMPLE applications)

the assignment
i have to create a simplified game of hangman or a program that will convert time from a 12 hour format to 24 hr format. I decided to do the clock thing because it sounds easier (i know i'm stupid lol).

when i'm in lectures i understand what is going on, and line by line i understand most of the example codes we have been given, but when i have to implement it i just dont know where to start

i was given this assignment a week ago. So far I have asked a mate to help, he's in his first year at a different uni, so he really couldnt offer much. i have also spent about 16hrs in total over the past week searching for online material that might help. I have spent all evening trying to find something that might help.

i'm not expecting anyone to write the code for me because i really do want to learn. Last year we worked from psuedo (sp?) code. if someone was to write that for me, would that be too much help?

i have made several rubbish attempts at writing the code but beyond declaring int variables for hrs mins and secs i am at a loss. i dont even know what methods i should use

p.s.... thanks for taking the time to read, if you got this far lol, i will check back as soon as i can as i have decided that 6 hours of total unproductivity (if thats even a word lol) is quite enough for one day and you guys really are my last hope at the moment

Member Avatar for Mouche

I don't know java, but I would think this would be how you do it. I'm guessing java has a module or something for time.


Get time
Determine whether time is AM or PM
If PM:
time = time + 12
Remove AM/PM label

not really very helpful but i do really appreciate it... my problem is a little more complex than i have made it sound i guess lol... i have been trying to write this program from start to finish and i think that mite be my problem... after a brain explosion last nite i decided to do all the bits i think i know about (even tho it wont work) and then maybe ask for help for the missing parts

thanks again, i do appreciate people trying to help

writing pseudocode and problem solving is all part of programming & software development (And if you haven't tried to write pseudocode for this problem yet, then I suggest you give it a go, and see if that helps!), so I'm not going to write a complete comprehensive solution, although, its equally true that the best way to get your head around a problem you've been sweating over is to find a fresh brain to skim over it.

Here's how I would approach the problem:

What does the input look like? You should make sure you have this well-defined. the first hurdle might be string manipulation, eg, if you've got to extract several elements from a string such as "09:45am", then you probably want to search for the delimiter : which seperates the numbers, and extract the two numerical parts as ints, then extract the am/pm suffix to a String

Alternatively, you could leave that bit til last, and just have each part input seperately by the user - in which case, the problem should be more trivial. If your suffix is "am", then the hours remain the same. if your suffix is "pm", then you need to add 12 to your hours. minutes remain the same regardless, and the suffix isn't used in 24hr time.

Finally, what does the output look like? you could simply concatenate hours & minutes for 'military' time format, eg "2315", or perhaps add a seperator in the middle - "23:14".

if string manipulation is proving tricky (String manipulation in java is a bit awkward IMHO), try creating that seperately in another program while you work out how to break up your input to seperate components. good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.