Results 1 to 8 of 8
  1. #1
    King of the seas poseidon's Avatar
    Join Date
    Dec 2011
    Location
    Somewhere only we know
    Posts
    474
    Points
    810
         User Info     Contact     Gamer ID
    Join Date
    Dec 2011
    Location
    Somewhere only we know
    Posts
    474
    Points
    810
    Gamer IDs

    Gamertag: wheretohide Steam ID: riverboy879

    Contact info:

    Youtube Channel: https://www.youtube.com/wheretohide

    Default [TUT] How to create a rectangle that knows its length in java

    Code:
    public class Rectangle 
    {
        private double myLength;
        private double myWidth;
        
        public Rectangle(double length, double width)
        {
            myLength = length;
            myWidth = width;
        }
        /* 
         * p = 2*length + 2*width
         */
        public double perimeter()  
        {
            double toRet = 0;
            toRet = 2*getLength() + 2*getWidth();
            return toRet;
        }
        
        public static void main(String [] args)
        {
            Rectangle rec = new Rectangle(7, 2);
            Rectangle rec2 = rec.scale(2.0);
            double per = rec.perimeter();
            double area = rec.area();
            double per2 = rec2.perimeter();
            double area2 = rec2.area();
            String toPrint = rec.toString();
            System.out.print(toPrint + "\n");
            System.out.print(rec.getLength() + "\t\t" + rec.getWidth() + "");
            System.out.print("\t\t" + per + "\t\t" + area + "\t\t" + "1.0\n");
            System.out.print(rec2.getLength() + "\t\t" + rec2.getWidth() + "");
            System.out.print("\t\t" + per2 + "\t\t" + area2 + "\t\t" + "2.0");
        }
        
        /* 
         * Make a Scale method that will increase the size 
         * of the rectangle by a scale factor 's.'
         * For example, a rectangle twice as large as ours
         * would have side lengths of 14 and 4... and as a 
         * result would have a perimeter of 36.
         */
    
        public Rectangle scale(double s)
        {
            return new Rectangle(this.getLength() * s,s*this.getWidth());
        }
        
        /* 
         * Take out the first three lines of code in the main that 
         * use System.out.print.  Put them in the toString method.  
         * Take out the parentheses and use the += concatonation
         * operator like we did in the SimpleInterest Program.
         * 
         * The toString method returns a String.
         * It formats your output.
         */
        
        /* 'this' is a keyword.  It stands for a placeholder
         * In the main, we will make a call to toString()
         * by 'saying' rec.toString. When we do, this will
         * be set to rec on the fly.  "On the fly" is run-time.
         */
        
        public String toString()
        {
            /**
            String toRet = "";
            toRet += "The perimeter of a rectangle ";
            toRet += "with a length of " + this.myLength;
            toRet += " and a width of " + this.myWidth + " is ";
            return toRet;
            */
            /* the backslash is the escape character. 
             * \t = tab
             * \n = new line
             * \\ = backslash
             */
            return "Length\t\tWidth\t\tPerimeter\tArea\t\tScaleFactor";
        }
        
        /* 
         * Make an area method.  See the perimeter method as a model.
         * 
         * Area = length * width
         */
        
        public double area()
        {
            return  getLength() * getWidth();
        }
        
        /* 
         * MyLength and myWidth can be accessed by the main method only because 
         * it is in the Rectangle class.  If we moved the main to a new class, 
         * perhaps ShapeTester, then myLength and myWidth would not be
         * recognized because the fields are private, and therefore not
         * visible to client classes.  LOOK @ PARROT for an example.
         * 
         * Write the accessor methods for the Rectangle class
         */
        public double getLength()
        {
            return myLength;
        }
        public double getWidth()
        {
            return myWidth;
        }
        
        public boolean hasCommonDimension(Rectangle r1, Rectangle r2)
        {
            
            double len1 = r1.getLength();
            double len2 = r2.getLength();
            double wid1 = r1.getWidth();
            double wid2 = r2.getWidth();
            
            // == is a question.  It's length 1 equal to length2 
            //&& this is java's logical 'AND'
            //|| this is java's logical 'OR'
            //
            /**
            if(len1 == len2)
                return true;
            if(wid1 == wid2)
                return true;
            if (wid1 == len2)
                return true;   //With this commented out it doesn't know it.
            if (wid2 == len1)
                return true;
            return false; //default
            */
            /**
            if (len1 == len1 || wid1 == wid2 || wid2 == len2 || wid2 == len1)
            return true;
            return false;
            */
            /*
            if (len1 == len1 || wid1 == wid2 || wid2 == len2 || wid2 == len1)
                return true;
            else
                return false;
                */
            return len1 == len1 || wid1 == wid2 || wid2 == len2 || wid2 == len1;
                
            /*
            boolean toRet = false;
            if(len1 == len2)
                toRet=true;
            else if(wid1 == wid2)
                 toRet =true;
            else if(wid1 == len2)
                toRet = true;   //With this commented out it doesn't know it.
            else if(wid2 == len1)
                toRet = true;
            return toRet; //default
            //compound statement
            */
            /*
            boolean toRet = false;
            if(len1 == len2)
                return  true;
            else if(wid1 == wid2)
                return true;
            else if(wid1 == len2)
                return true;   
            else if(wid2 == len1)
                return true;
            else
                return toRet;
                */
            
                
        }
        
    }

    0 Not allowed! Not allowed!
    Last edited by MatthewH; 09-20-2013 at 02:31 PM.
    Quote Originally Posted by Coldfire202 View Post
    Yes, yes I do. No one can beat my ass kissery skills
    ^thanks tenza^
    [img][/img]

  2. #2
    I agree. MatthewH's Avatar
    Join Date
    Jul 2011
    Location
    North Carolina
    Posts
    3,481
    Points
    15,810
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    North Carolina
    Posts
    3,481
    Points
    15,810

    Default

    Added code tags + added "Java" prefix. There ya go. I'll test code later.

    -2 Not allowed! Not allowed!


  3. #3
    Jungler Strike's Avatar
    Join Date
    Apr 2011
    Location
    Gotham
    Posts
    6,318
    Points
    9,417
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    Gotham
    Posts
    6,318
    Points
    9,417
    Gamer IDs

    PSN ID: xSTR11K3Rx Steam ID: xSTRiiK3Rx

    Contact info:

    Youtube Channel: http://www.youtube.com/xSTRiiK3Rx/

    Default

    Quote Originally Posted by Coldfire202 View Post
    Added code tags + added "Java" prefix. There ya go. I'll test code later.
    I wouldnt be editing peoples content already if i was you. Try reading up moderation guidelines.

    2 Not allowed! Not allowed!

    ^Ty goober^
    Quote Originally Posted by xX_BiGFooTT_Xx View Post
    compensate my cock faggot

  4. #4

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default

    It's not your job to edit people's stuff, or test their code.

    OT: Comments in the code aren't the best way to teach.

    0 Not allowed! Not allowed!
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  5. #5
    Wii Code Creator
    T.U.F.F. PUPPY
    T.B.W's Avatar

    Badge

    Join Date
    Dec 2012
    Location
    Barcelona Spain
    Posts
    4,212
    Points
    6,669
         User Info     Contact     Gamer ID
    Join Date
    Dec 2012
    Location
    Barcelona Spain
    Posts
    4,212
    Points
    6,669

    Default

    poseidon you're still a skid lol

    0 Not allowed! Not allowed!

  6. #6
    Bad Company
    RED 58's Avatar

    Badge

    Join Date
    Jan 2012
    Location
    Goober's Coder CP
    Posts
    6,918
    Points
    9,658
         User Info     Contact     Gamer ID
    Join Date
    Jan 2012
    Location
    Goober's Coder CP
    Posts
    6,918
    Points
    9,658

    Default

    Quote Originally Posted by Strike View Post
    I wouldnt be editing peoples content already if i was you. Try reading up moderation guidelines.
    Btw, do you have any idea where those are? I'm having trouble finding them.

    0 Not allowed! Not allowed!



    Quote Originally Posted by Iced View Post
    Red 58 = Swoot (Reincarnated)
    Quote Originally Posted by GOOBER View Post
    Terr0r you need a Gecko. Lets go to the Pet store and buy one
    Quote Originally Posted by ABlackGuy View Post
    He may not have a soul but he still has a brain. Unlike Russ who has neither.

  7. #7
    Jungler Strike's Avatar
    Join Date
    Apr 2011
    Location
    Gotham
    Posts
    6,318
    Points
    9,417
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    Gotham
    Posts
    6,318
    Points
    9,417
    Gamer IDs

    PSN ID: xSTR11K3Rx Steam ID: xSTRiiK3Rx

    Contact info:

    Youtube Channel: http://www.youtube.com/xSTRiiK3Rx/

    Default

    Quote Originally Posted by RED 58 View Post
    Btw, do you have any idea where those are? I'm having trouble finding them.
    http://www.codeleakers.com/showthrea...ations-READ-ME!

    0 Not allowed! Not allowed!

    ^Ty goober^
    Quote Originally Posted by xX_BiGFooTT_Xx View Post
    compensate my cock faggot

  8. #8
    ~ Hyrule's Savior ~
    link's Avatar
    Join Date
    Jun 2011
    Posts
    3,825
    Points
    2,802
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Posts
    3,825
    Points
    2,802

    Contact info:

    Youtube Channel: http://www.YouTube.Com/ReTrOSlink

    Default

    Quote Originally Posted by T.B.W View Post
    poseidon you're still a skid lol
    If we all were wiitards one time in our life, we are all skids

    0 Not allowed! Not allowed!
    #gamedevelopment


Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 08:31 PM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.