Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default A simple parameter

    Hello,

    I am just looking for a little bit of help with one of my homework assignments. I am hung-up on how to create a parameter that will make a printlin statement repeat itself. I have to make a the neck of the robot, shown below, two lines tall by using a parameter and setting it to two. I am not exactly sure how to accomplish this with just a parameter. I have only been able to make the neck one line tall.

    Neck: | |

    What I have now:

    public class DoubleSum {


    // Program for the above Robot 1. Changing the parameters
    // will result in similar but different robots. Longer or shorter
    // neck, body and legs. Wider body.
    public static void main(String[] args) {
    head();
    neck(2);}
    public static void head(){
    System.out.println(".-------.");
    System.out.println("| o o |");
    System.out.println("| < |");
    System.out.println("| --- |");
    System.out.println("'-------'");

    }
    public static void neck(Object height){
    System.out.println(" | | ");
    }
    }


    To see the problem you can go to the link below.
    Program 3, COS 160

    Hope someone out there can help me! Thanks in advance!

    ~Steve

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: A simple parameter

    Quote Originally Posted by stephen.kenney@maine.edu View Post
    I am just looking for a little bit of help with one of my homework assignments. I am hung-up on how to create a parameter that will make a printlin statement repeat itself. I have to make a the neck of the robot, shown below, two lines tall by using a parameter and setting it to two. I am not exactly sure how to accomplish this with just a parameter.
    Use a loop? Like this:
    Java Code:
    for (int i= 0; i < paramValue; i++)
       // draw a neck fragment here ...
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    lenois is offline Member
    Join Date
    Feb 2012
    Posts
    59
    Rep Power
    0

    Default Re: A simple parameter

    Java Code:
    public class DoubleSum {
    
    
    	// Program for the above Robot 1. Changing the parameters
    	// will result in similar but different robots. Longer or shorter
    	// neck, body and legs. Wider body.
    	public static void main(String[] args) {
    		head();
    		neck(2);}
    	public static void head(){
    		System.out.println(".-------.");
    		System.out.println("| o o |");
    		System.out.println("| < |");
    		System.out.println("| --- |");
    		System.out.println("'-------'");
    
    	}
    	public static void neck(Object height){
    		System.out.println(" | | ");
    	}
    }
    use a loop with the int around it.

    also use the code brackets, and indent please

    here is a good tutorial for loops

    also when you have a method, you need to declare the pass type at the method

    Java Code:
    public static void main (String[]args)
    {	
    	int value= 42;
    	
    	fattyBoomBoom(value);
    }
    public static void fattyBoomBoom(int value)
    {
    	System.out.println(value);
    }

  4. #4
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: A simple parameter

    Big thanks to both of you that replied to my post. It helped out a lot!

Similar Threads

  1. Parameter help/question
    By CuppaCoffee in forum New To Java
    Replies: 6
    Last Post: 01-07-2012, 03:36 PM
  2. Output parameter
    By xdzgor in forum JDBC
    Replies: 4
    Last Post: 11-19-2010, 08:03 AM
  3. how to pass parameter from one jsp to another jsp
    By kader_sit in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-10-2010, 02:04 PM
  4. passing a parameter
    By aarthi2learn in forum AWT / Swing
    Replies: 4
    Last Post: 12-22-2008, 05:46 AM
  5. Can a method take itself as parameter?
    By bukake in forum New To Java
    Replies: 10
    Last Post: 09-06-2008, 09:26 PM

Posting Permissions

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