Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: not sure if my code is right, if it is not sure how to code Test box.

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default not sure if my code is right, if it is not sure how to code Test box.

    first, this is my homework or project for class. I don't ask anyone to do it for me, I just want help, not sure I really understand what I'm doing.

    I have to make a class, Box, that accepts 3 ints for length, width and height. 3 constructors for 1, 2 or 3 ints. if 1 output a line with length x was created, if 2 a rectangle with lengths and width y created, etc. I was just wondering if I did this right, I'm stuck trying to write BoxTest to check that it works, but here is what I have so far.
    Thank you

    //Unit 5
    //IT258
    //Christian Silva
    //I attest that this is my work

    //This is the beginning of the Box class
    public class Box
    {
    private int length;
    private int width;
    private int height;

    public static void Box(int x)
    {
    int length = x;
    int width = 0;
    int height = 0;
    System.out.print("Line created");
    }
    public static void Box(int x, int y)
    {
    int length = x;
    int width = y;
    int height = 0;
    System.out.print("Rectangle created");
    }
    public static void Box(int x, int y, int z)
    {
    int length = x;
    int width = y;
    int height = z;
    System.out.print("Box created");
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: not sure if my code is right, if it is not sure how to code Test box.

    When posting code, please use the highlight tags to preserve formatting.

    Does this compile? Can you call its methods? Do the methods print out what you expect them to?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: not sure if my code is right, if it is not sure how to code Test box.

    it does compile, I'm not sure because I'm really confused with java and i don't think I even need those println statements. this class defines box and the test box i need to write creates 3 instances, 1 for each constructor

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: not sure if my code is right, if it is not sure how to code Test box.

    I don't see any constructors. You have 3 static functions with a return type of void called Box, but no constructors.

    Recommended reading: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM
  2. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  3. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  4. [SOLVED] How do I run test code in different file under a project
    By lostbit in forum Java Theory & Questions
    Replies: 1
    Last Post: September 28th, 2011, 11:31 AM
  5. Studying for a test, can't figure out my code won't work
    By coolidge in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2011, 01:12 PM