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.

Page 2 of 2 FirstFirst 12
Results 26 to 43 of 43

Thread: Workshop 6

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    Try doing it one step at a time to print a box with dimensions width and height,
    Going back to post#10:

    Write a loop that loops height number of times.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    Ok

    --- Update ---

    What should I say in if statement for height?

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    Now put the code for the loop in a main() method and put the main() method in a class. Compile it and execute it.
    Fix any errors. Post the full code here.
    When that's done, we'll move to the next step.

    What should I say in if statement for height?
    There isn't an if statement. The for loop controls the number of times the loop will execute.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    for (int j= 3; j <= height; j++) {
    			}
    			if (i%width) == 3)
                  System.out.print("#####");

    or

    for(int j = 1; j < height; j++){
    			}
    				if(height = 1){
    					System.out.print("#");
    					}
    				else (height = 5);{
    					System.out.print("#");
    					}
    				else
    					System.out.print(" ");
    					}

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    Please reread the instructions. You are to write a small class with a main() method and a loop that loops height times.
    The program is going to be written one small, simple step at a time.


    If you'd rather do the assignment on your own, let me know and I'll leave.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    All i need is example of loops controls

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    For testing you should write a simple program as described above to learn the techniques of writing loops and using if statements to control what is printed.
    When you have learned how to write the code to do that, you will have an easier time working on your assignment.

    Your choice on how to proceed:
    Try writing this simple program to learn how to do some programming
    or waiting until someone comes along to write the code for you.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    You can do that? write the code for someone esle?

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    Ok. Good luck on your project.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    no I like to learn myself and use your help

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    Start by writing the code that has been suggested in posts #26, #28 & #30, compile it, fix any errors, execute it, fix any errors and post the working version here.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    ok

  13. #38
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    import java.util.Scanner;
     
    /*
     *  Stacktrace.in
     *  You have a exception , we have a solution
     */
    public class DrawRectange {
     
    	public static void main(String[] args) {
     
    		Rectange rectangle = new Rectange(-1,11);
    		rectangle.draw();
    		Rectange rectangle2 = new Rectange(4,5);
     
    		rectangle2.draw();
     
     
     
     
    public class Rectange {
     
    	private int heigth;
    	private int width;
    	public Rectange(int heigth, int width) {
    		super();
    		this.heigth = heigth;
    		this.width = width;
    	}
     
    	public void draw(){
     
    		if(heigth<0 || heigth >10){
     
    			heigth =3;
    		}
     
    		if(width<0 || width >10){
     
    			width =3;
    		}
     
    		for(int i=1;i<=heigth;i++)
    		{
    		for(int j=1;j<=width;j++)
    		{
    		if((i==1 || i==heigth) || (j==1 || j==width))
    		System.out.print("#");
    		else
    		System.out.print(" ");
    		}
    		System.out.println();
    		}


    --- Update ---

    with a error:
     
     ----jGRASP exec: javac -g Rectange.java
     
    Rectange.java:7: error: class DrawRectange is public, should be declared in a file named DrawRectange.java
    public class DrawRectange {
           ^
    1 error
     
     ----jGRASP wedge2: exit code for process is 1.
     ----jGRASP: operation complete.

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    DrawRectange is public, should be declared in a file named DrawRectange.java
    A class declared as public must be in a file with the filename the same as the classname.
    There can not be two public classes defined in the same file.

    Either move the definition of DrawRectangle to a file named: DrawRectange.java
    or remove the public modifier from the class definition.


    This is an interesting comment in the code:
    /*
     *  Stacktrace.in
     *  You have a exception , we have a solution
     */
    If you don't understand my answer, don't ignore it, ask a question.

  15. #40
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Workshop 6

    move just public, not public Rectangle?

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Workshop 6

    There can only be ONE class that is public in a .java file and the classname and filename must match,

    BTW whoever wrote the code does not know how to spell Rectangle.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #42
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Workshop 6

    It makes me wonder just who in fact did write his code.

  18. #43
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Norm View Post
    BTW whoever wrote the code does not know how to spell Rectangle.
    Or "height"

Page 2 of 2 FirstFirst 12