| View previous topic :: View next topic |
| Author |
Message |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Sep 23, 2010 9:59 pm Post subject: |
|
|
| Your main problem was having 3 constructors. Whilst overloading is fun, in this case there was no reason for it. Also unless your spec specifically states it I would have a getter for the discount and savings in which they are calculated and returned. This way you decouple them from initial price and current price. Notice your reduceprice function if coded properly should've updated those 2. This becomes a problem in larger code. You will end up creating a lot of dependencies. In this case it is a tradeoff between efficiency and good code design. Since the generation you will be doing within the getters is very simple code it could be argued this way is even more efficient making it a win-win solution. Let's say someone called reduceprice twice without fetching either discount or savings. Then you would have done 2 unnecessary calculations.
|
|
| Back to top |
|
 |
Oblivious Grandmaster Cheater Supreme
Reputation: 45
Joined: 12 Mar 2008 Posts: 1729
|
Posted: Thu Sep 23, 2010 10:02 pm Post subject: |
|
|
| tl;dr slugsnake sucks at coding
|
|
| Back to top |
|
 |
elpacco Grandmaster Cheater Supreme
Reputation: 30
Joined: 16 Oct 2007 Posts: 1258
|
Posted: Thu Sep 23, 2010 11:22 pm Post subject: |
|
|
| Slugsnack wrote: | | Your main problem was having 3 constructors. Whilst overloading is fun, in this case there was no reason for it. Also unless your spec specifically states it I would have a getter for the discount and savings in which they are calculated and returned. This way you decouple them from initial price and current price. Notice your reduceprice function if coded properly should've updated those 2. This becomes a problem in larger code. You will end up creating a lot of dependencies. In this case it is a tradeoff between efficiency and good code design. Since the generation you will be doing within the getters is very simple code it could be argued this way is even more efficient making it a win-win solution. Let's say someone called reduceprice twice without fetching either discount or savings. Then you would have done 2 unnecessary calculations. | Yeah the third constructor was pointless and that's just what I started with and didn't get rid of. As it actually turns out, I was doing a whole fucking lot more than I needed to do in the first place. I just had to slap some stuff with JOptionPane on it, make a toString and turn it in.
_________________
| [AM]Misery wrote: |
| FangBanger wrote: | | What is the best way for a lv19 Soldier to solo Sledge on Borderlands? | Shoot him. |
|
|
| Back to top |
|
 |
Thanh =) Newbie cheater
Reputation: 3
Joined: 20 Mar 2010 Posts: 19
|
Posted: Thu Sep 23, 2010 11:27 pm Post subject: |
|
|
| Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks.
_________________
Where will you be for the REVOLUTION? |
|
| Back to top |
|
 |
:^( Grandmaster Cheater
Reputation: 109
Joined: 25 May 2007 Posts: 689
|
Posted: Thu Sep 23, 2010 11:36 pm Post subject: |
|
|
| Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you.
_________________
|
|
| Back to top |
|
 |
1929394839292057839194958 Grandmaster Cheater Supreme
Reputation: 130
Joined: 22 Dec 2006 Posts: 1509
|
Posted: Thu Sep 23, 2010 11:37 pm Post subject: |
|
|
| Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time.
|
|
| Back to top |
|
 |
:^( Grandmaster Cheater
Reputation: 109
Joined: 25 May 2007 Posts: 689
|
Posted: Thu Sep 23, 2010 11:38 pm Post subject: |
|
|
| konr wrote: | | Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time. |
Oh, the joy.
Also I chuckled
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 24, 2010 5:49 am Post subject: |
|
|
| Code: | public class Product {
private String name;
private double initPrice;
private double currentPrice;
public Product( String name, double initPrice ) {
this.name = name;
this.initPrice = initPrice;
currentPrice = initPrice;
}
// assuming reduction from initial not current price
public void reducePrice( double percent ) {
currentPrice = initPrice * percent / 100;
}
public String getSavings() {
return "$" + ( initPrice - currentPrice );
}
public String getDiscount() {
return ( currentPrice * 100 / initPrice ) + "%";
}
public String getName() {
return name;
}
public String getPrice() {
return "$" + currentPrice;
}
}
--------------------------TEST FILE--------------------------------
public class ProductTester {
public static void main( String[] args ) {
Product apple = new Product( "Apple", 400 );
System.out.println( apple.getPrice() );
apple.reducePrice( 50 );
System.out.println( apple.getPrice() );
System.out.println( apple.getDiscount() );
System.out.println( apple.getSavings() );
}
} |
Since I was on my phone last night and now on computer, this is something structurally close to what I meant. As you can see it preserves all the functionality you had before but I think you will agree is nicer code both to look at and potentially easier to maintain in the future.
| konr wrote: | | Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time. |
That makes no sense, worthless.
|
|
| Back to top |
|
 |
аhMunRa How do I cheat?
Reputation: 0
Joined: 13 Nov 2009 Posts: 0
|
Posted: Fri Sep 24, 2010 5:54 am Post subject: |
|
|
| Slugsnack wrote: | | konr wrote: | | Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time. |
That makes no sense, worthless. |
Actually it makes perfect sense, and from what I can deduce from your previous posts, you're also fairly mentally deficient.
Pissweak coder, too.
|
|
| Back to top |
|
 |
shitposter Newbie cheater
Reputation: 5
Joined: 12 Nov 2008 Posts: 15
|
Posted: Fri Sep 24, 2010 6:53 am Post subject: |
|
|
| Story wrote: | | Slugsnack wrote: | | konr wrote: | | Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time. |
That makes no sense, worthless. |
Actually it makes perfect sense, and from what I can deduce from your previous posts, you're also fairly mentally deficient.
Pissweak coder, too. |
I wouldn't say he's a terrible coder, he just thinks he's better than what he is.
|
|
| Back to top |
|
 |
1929394839292057839194958 Grandmaster Cheater Supreme
Reputation: 130
Joined: 22 Dec 2006 Posts: 1509
|
Posted: Fri Sep 24, 2010 7:41 am Post subject: |
|
|
| Slugsnack wrote: | | Code: | public class Product {
private String name;
private double initPrice;
private double currentPrice;
public Product( String name, double initPrice ) {
this.name = name;
this.initPrice = initPrice;
currentPrice = initPrice;
}
// assuming reduction from initial not current price
public void reducePrice( double percent ) {
currentPrice = initPrice * percent / 100;
}
public String getSavings() {
return "$" + ( initPrice - currentPrice );
}
public String getDiscount() {
return ( currentPrice * 100 / initPrice ) + "%";
}
public String getName() {
return name;
}
public String getPrice() {
return "$" + currentPrice;
}
}
--------------------------TEST FILE--------------------------------
public class ProductTester {
public static void main( String[] args ) {
Product apple = new Product( "Apple", 400 );
System.out.println( apple.getPrice() );
apple.reducePrice( 50 );
System.out.println( apple.getPrice() );
System.out.println( apple.getDiscount() );
System.out.println( apple.getSavings() );
}
} |
Since I was on my phone last night and now on computer, this is something structurally close to what I meant. As you can see it preserves all the functionality you had before but I think you will agree is nicer code both to look at and potentially easier to maintain in the future.
| konr wrote: | | Dalton. wrote: | | Thanh =) wrote: | | Slugsnack wrote: | | Who's cock you gonna hop on today, lil bunny ? |
Dalton can obviously take two dicks. |
You'd like that, wouldn't you. | Then you'd be able to take his dick around 4 times at the same time. |
That makes no sense, worthless. | Or maybe you're just an idiot.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 24, 2010 7:56 am Post subject: |
|
|
konr, remember that time where you tried to back someone up and ended shooting them in the back ? Then you got humiliated in IRC and you signed off all 'upset' boohoo ? Well yes, yes you did say Dalton has a loose pooper because Thanh's dick sure weren't small the other night when you were gagging on it like 3 year old on a black man. Like I said, you're worthless. It must hurt knowing that's my honest opinion of you. You hang off my every word and with your low confidence it must mean a lot to you that I say it from the bottom of my heart and you know I'm not shitting you and you know I'm right.
Oh and please don't try the 'idc about your opinion' rant, I know you do. 'Oh Slugsnack Slugsnack please don't humiliate me and patronise me You make me feel shit about myself BAWWW  '
And ladies, ladies I would never be so rude as to judge you at things you're good at when I know nothing about them. I never comment on your ability to give head or ride e-dick so why make judgement calls on things you know nothing of ( such as programming ) ?
Anyway. Global announcment:
Hey hey calling all cockriders. I just offended your demi-gods, quick come hop on !!! They're here till Wednesday !!!!someone bring the lube, some bitch is about to get really sore
|
|
| Back to top |
|
 |
|