Our system detected that your browser is blocking advertisements on our site. Please help support FoxesTalk by disabling any kind of ad blocker while browsing this site. Thank you.
Jump to content
General Smuts

Anyone any good at programming java?

Recommended Posts

Posted
ah right sod it then! you need this. if it's in a class I think like

class setTime {

int hr, min;

private void setHour (int hr) {

this.hour = ( hr >= 0 && hr <= 23 ) ? hr : 0;

}

private void setMin (int min) {

this.min = ( min >= 0 && min <= 59 ) ? hr : 0;

}

public void setTime( int hr, int min ) {

setHour( hr );

setMin( min );

}

}

who knows the mind of java, not the best language to be honest, probably as complex as C++ in some ways and way less powerful

Yeah its in a class and thats almost spot on to what i have.

Cheers again.

Posted
don't thank me, it probably won't work or do what it's meant to! haha

lol it seems to be working and that is more than good enough for me (as it were better than what i had already written).

:worship:

Posted

Another quick question, how do you provide a second constructor for the same class, without it already being defined in the previous constructor.

EG.

public Time()

{

hour = 0;

minute = 0;

}

Is the first constructor.

public Time ()

{

hour = hr;

minute = min;

}

Would be the 2nd constructor i want to write to account for the parameters ive now set. At least i think it is.

Posted
Another quick question, how do you provide a second constructor for the same class, without it already being defined in the previous constructor.

EG.

public Time()

{

hour = 0;

minute = 0;

}

Is the first constructor.

public Time ()

{

hour = hr;

minute = min;

}

Would be the 2nd constructor i want to write to account for the parameters ive now set. At least i think it is.

The second constructor would take in values (eg 23, 17) so that you can set the time, the first using predertermined values (eg 00, 00)

public Time ()

{

hour = "00";

minute = "00";

}

public Time (hr, min)

{

hour = hr;

minute = min;

}

Posted
The second constructor would take in values (eg 23, 17) so that you can set the time, the first using predertermined values (eg 00, 00)

public Time ()

{

hour = "00";

minute = "00";

}

public Time (hr, min)

{

hour = hr;

minute = min;

}

:worship:

I cannot use that smilie enough for the pair of you.

:wub:

Posted
To be honest, the code is not the problem.

Think about how you would construct this, assembling the time using pieces of paper. The logical approach with which you assemble it all together is the same logical format that the code will be assembled - and the code you are currently using is incredibly basic but all the brackets and if-else statements make it look more confusing than it really is.

Seriously, draft out or flow map your ideas first and the coding will be much quicker.

I know I'm a bit late but I'd say that's very good advice.

I haven't done programming in Java but I ecently just did a huge load of coding in VBA in Excel and I'm pretty sure half the course just seemed to be ways of planning the fecker.

In fact, the first bit of work was a group assignment worth 25% which was planning our models and the second bit worth 75% was actually doing them.

A bit useless now if we're honest, given that it has to be in today.

Erm, geekpower?

Posted
For some reason I just read all that and all that I can say is wtf?

When you meet me on saturday, you'll see why im struggling with this. Im of a similar mould that when given said coursework wtf was my reaction.

Posted

Another quick question. Sorry again im just reet shite at this Java lark.

'The submission time should be represented by two formal parameters of type int which are then passed on as actual parameters to a Time constructor.'

The bit above is what im stuck on. It should be a constructor of type Time but it needs 2 int's (hour and min?) written into the code.

So far ive written;

public Job(int refno, String depnom, int pgs, int cops, Boolean dubs, int hr, int min)

{

ref = refno;

dep = depnom;

pages = pgs;

copies = cops;

dble = dubs;

time = Time(hr + min);

date = 0;

}

But the bits in bold are obviously wrong. I can't think how i would word it. Any clues?

Cheers in advance again for any help. I love you all.

Posted

2 things

don't you need 'new'

also its not hr + min, that just suppies one argument, the sum of those, u need ot supply 2

so it's

time = new Time( hr, min );

Posted
2 things

don't you need 'new'

also its not hr + min, that just suppies one argument, the sum of those, u need ot supply 2

so it's

time = new Time( hr, min );

Love you!!!!

Its the little things like this that i keep missing. Bloody Java is so particular!

Cheers again!

Posted

Sorry again, im not very familiar with the boolean function.

I was wondering how in this constructor, i would incorporate it.

public Job(int refno, String depnom, int pgs, int cops, boolean dubs, int hr, int min)

{

ref = refno;

dep = depnom;

pages = pgs;

copies = cops;

dble = dubs;

time = new Time( hr, min );

date = null;

}

I've stated that 'dubs' will be boolean but given it no options so when testing/running the program it doesn't recognise any options. Would i write a new method or a mutator?

Thanks again for any help, you've been brilliant.

Posted

a boolean is just a data type like a string or a int etc. it can either be true or false, nothing else. It is a good idea to name booleans starting with is_ as its reads better, i.e. is_this_a_double, then you get nicer to read code that makes more sense like

is_this_a_double = false;

so when you call the function Job you would need to put true or false as the 5th argument.

I'm not sure what you are asking about giving it options? what are you trying to do?

Posted
a boolean is just a data type like a string or a int etc. it can either be true or false, nothing else. It is a good idea to name booleans starting with is_ as its reads better, i.e. is_this_a_double, then you get nicer to read code that makes more sense like

is_this_a_double = false;

so when you call the function Job you would need to put true or false as the 5th argument.

I'm not sure what you are asking about giving it options? what are you trying to do?

Yeah i sorted it. I were just being stupid. I was typing yes as a boolean option instead of true. The fancy name stumped me.

Sorry.

Posted

I'm thinking that next time you should start the entire thing earlier than two minutes to deadline.

Why not simply post all of your coursework specs here and then we can all work through it giving you plenty of time to get pissed and feel girls tits.

Hang on - bollocks to that - I want in on the drink and tit lark.

No one tell the Mrs (or Mrs Raj or Phube's Mrs) or or I'm dead.

Posted
I'm thinking that next time you should start the entire thing earlier than two minutes to deadline.

Why not simply post all of your coursework specs here and then we can all work through it giving you plenty of time to get pissed and feel girls tits.

Hang on - bollocks to that - I want in on the drink and tit lark.

No one tell the Mrs (or Mrs Raj or Phube's Mrs) or or I'm dead.

In my defence i was only set this a week ago without being told, it was just silently posted on my coursework site, and my friend told me at half time of my 5-a-side game yesterday.

In hindsight i should have checked the net more often but a week is a bit steep.

Posted
...it was just silently posted on my coursework site

Damn them silent internets.

It was far better when the air was thick with the sounds of cow horns and quaking ducks. :D

Posted

One more question again and im sorry. Im nearing completion now i promise.

Im trying to create a method which is a String representation of all the info that ive input, such as date etc.

This shockingly is wrong,

public String getAsString (String ref, String dep, String pages, String copies, String dble, String time, String date, String getCost)

{

return (ref), (dep), (pages), (copies), (dble), (time), (date), (getCost );

}

as is

public String getAsString (String ref, String dep, String pages, String copies, String dble, String time, String date, String getCost)

{

return ref;

return dep;

return pages;

return copies;

return dble;

return time;

return date;

return getCost;

}

Ive tried a few other things but im having no luck. Can anyone point me in the right direction please?

Thanks and man loves in advance.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...