Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: enlarging a box

  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Thanked 0 Times in 0 Posts

    enlarging a box

    I am having problems understanding how to complete this task.

    • Specify by how much larger (multiplier) you would like to enlarge each dimension of the object. For example, makeLarger(2) would multiply the length, width, and height of the box by 2.
    • Specify the specific amount you would like to add to each dimension of the box. For example, makeLarger(1, 3, 5) would add 1 to the length, 3 to the width, and 5 to the height of the box

    my code that i have written in order to make the boxes looks like this:

    public class Box1 {
    	double length;
    	double width;
    	double height;
    	Box1() {
    		length = 10;
    		width = 10;
    		height = 10;
                 //makes a defalt box
    	Box1(double l, double w, double h) {
    		length = l;
    		width = w;
    		height = h;
                 //makes a user created box
    	Box1(double s){
    		length = s;
    		width = s;
    		height = s;
                 //makes a cube
    any tips on how to make a method to peform the objectives in the task above?

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Thanked 20 Times in 19 Posts
    What you're asking is a very basic concept in Java (and in programming in general).

    My suggestion is that you either read up on the book you are reading for your class about construction of Java objects and methods within a class or you start going through the Java tutorial on the subject:


    If you did indeed write that code, then you're on the right track. If you didn't and it was your instructor then I suggest you start from the beginning of the Java tutorial and go through it.

    As for tips on writing a method think of these main things:

    What will the method return?
    What will the method get from the user (the parameters)?
    How will the data change inside the method?
    "To iterate is human, to recurse divine." -L. Peter Deutsch


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts