These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

Out of Pod Experience

 
  • Topic is locked indefinitely.
 

Little question bout a PHP class

First post
Author
Umad Bro Questionmark
Deep Core Mining Inc.
Caldari State
#1 - 2011-09-22 02:27:56 UTC
Hey there. Posting from mobile and I got my post eaten due to timeout 3 times no so I'm reaching the end of my patience. Also I can't access out of pod so I'm sorry in advance for posting this here. I got a quick question and I'm grateful for any help anyone might offer regarding my issue:

I need to create a class that takes the parameters length and width and after doing so it finds out whether it's a square or not.

If it is, it then calculates its area/surface (length * width). And there seems to be a trick regarding the parameters but I can't seem to figure it out.

Any help would be greatly appreciated. Thank you for the help and/or good troll attempts.


STUPID FORUM TIMEOUT. FIX THE POST EATING ISSUE PLEASE!!!

[b] (\ /)  (º .º)   ♥    ن٥ﻻ ﻉ√٥ﺎ ٱ[/b] c(”)(”) **_Crack bunny - will **Like for drugs ([u]because its e-peen is already big enough[/u]). _

The Apostle
Doomheim
#2 - 2011-09-22 02:32:34 UTC
This any help

http://pastebin.com/KEZVUXU0

[i]Take an aspirin. If pain persists consult your local priest. WTB: An Austrian kangaroo![/i]

Umad Bro Questionmark
Deep Core Mining Inc.
Caldari State
#3 - 2011-09-22 02:57:14 UTC
I love you. Ty!

[b] (\ /)  (º .º)   ♥    ن٥ﻻ ﻉ√٥ﺎ ٱ[/b] c(”)(”) **_Crack bunny - will **Like for drugs ([u]because its e-peen is already big enough[/u]). _

Umad Bro Questionmark
Deep Core Mining Inc.
Caldari State
#4 - 2011-09-22 03:13:11 UTC
Ok I get the part where it grabs the sides and calculates the area but 2 questions:

1. what's the deal with that 15 there. Did you mean 25 which would be the result of 5 *5?

2. Is there any piece of code there that actually checks if the sides are equal (aka being a square?) or any other way of determining the shape of the object?

[b] (\ /)  (º .º)   ♥    ن٥ﻻ ﻉ√٥ﺎ ٱ[/b] c(”)(”) **_Crack bunny - will **Like for drugs ([u]because its e-peen is already big enough[/u]). _

The Apostle
Doomheim
#5 - 2011-09-22 03:36:04 UTC  |  Edited by: The Apostle
I suspect the numbers used are hard-coded for readability. (Any programmer will tell you) NEVER to hard-code numeric values. Always pass or declare predefined vars. (EDIT unless they are constants like Pi/SoL etc.)

I can't answer Q2 without knowing what vars are available. If I can assume W and L, then it's a simple if {} construct to determine if it's a square.

I'm rusty on PHP so any other assist from other forum members would be good.

[i]Take an aspirin. If pain persists consult your local priest. WTB: An Austrian kangaroo![/i]

Mr M
Sebiestor Tribe
#6 - 2011-09-22 05:41:57 UTC
Someone should've done their homework in time Smile

Share your experience

Write for the EVE Tribune

www.eve-tribune.com

The Apostle
Doomheim
#7 - 2011-09-22 05:46:43 UTC
Quote:
Someone should've done their homework in time

It reminds me of when I use to lecture in programming. I always gave my phone number to students to contact me if they got stuck on assignments.

Had a call at 3.00am from a student saying he was stuck on Question x.

I was pretty nasty reminding him what time it was.

His reply. "You set the deadline!".

I failed him.

[i]Take an aspirin. If pain persists consult your local priest. WTB: An Austrian kangaroo![/i]

Tippia
Sunshine and Lollipops
#8 - 2011-09-22 06:16:32 UTC
class rect {
private $w;
private $l;
function __construct($length, $width) { $this->l = (int) $length; $this->w = (int) $width; }
function isSquare() { $this->w === $this->l ? return $this->w*$this->l : return FALSE; }
}

…or some such. I just realised I haven't touched PHP in years, so I'm sure it'll break something. Oops
DeBingJos
Sebiestor Tribe
Minmatar Republic
#9 - 2011-09-22 08:18:14 UTC  |  Edited by: DeBingJos

  class SquareThingy{
    private $length;
    private $width;
   
    function __construct($length, $width){
      $this->length = $length;
      $this->width = $width;
    }
   
    // Call this to check if the object is a square
    function IsSquare(){
      if ($this->length == $this->width) return true;
      else return false;
    }
   
    // Call this to get the area
    function GetArea(){
      return $this->length * $this->square;
    }
  }


How to use this?

Construct the object
$object = new SquareThingy(4, 8); // 4 is length, 8 is the width

$object->IsSquare() // Gives true or false

$object->GetArea() // Gives the area

Ungi maðurinn þekkir reglurnar, en gamli maðurinn þekkir undantekningarnar. The young man knows the rules, but the old man knows the exceptions.

Abdiel Kavash
Deep Core Mining Inc.
Caldari State
#10 - 2011-09-22 12:13:11 UTC
The Apostle wrote:
Quote:
Someone should've done their homework in time

It reminds me of when I use to lecture in programming. I always gave my phone number to students to contact me if they got stuck on assignments.

Had a call at 3.00am from a student saying he was stuck on Question x.

I was pretty nasty reminding him what time it was.

His reply. "You set the deadline!".

I failed him.


You're not alone. I am usually pretty specific with deadlines, saying "Jan 15th 23:59", so there's no confusion. Every single time I get three submissions between 23:00 and midnight, often at least one after 23:55.
Messoroz
AQUILA INC
#11 - 2011-09-22 12:26:13 UTC
What all you failed at is providing proper set methods for the arguments in the constructor.
Efraya
V0LTA
OnlyFleets.
#12 - 2011-09-22 12:56:28 UTC
I <3 the eve forums. Nowhere else would you get this sort of response on a game communities main board.

[b][center]WSpace; Dead space.[/center] [center]Lady Spank for forum mod[/center][/b]

Tippia
Sunshine and Lollipops
#13 - 2011-09-22 13:07:05 UTC
Messoroz wrote:
What all you failed at is providing proper set methods for the arguments in the constructor.
…not part of the spec Blink
CCP Zymurgist
C C P
C C P Alliance
#14 - 2011-09-22 14:33:38 UTC
Moved from General Discussion.

Zymurgist Community Representative CCP NA, EVE Online Contact Us at http://support.eveonline.com/pages/petitions/createpetition.aspx