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: java length color help

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

    Angry java length color help

    I have gotten started on this program but am getting no where fast. Its due june 28. Can someone help me with it please.


    2. Create a class named Line.
    3. Add an integer field to the Line class named length.
    4. Add a String field to the Line class named color.
    5. Add a mutator for length.
    6. Add a mutator for color.
    7. Add an accessor for length.
    8. Add an accessor for color.
    9. Create a default constructor that sets the fields to length of zero and color of “black”.
    10. Create a constructor that sets the fields using parameters. Make sure the length cannot be set to a value less than zero or greater than 20. The color should only be allowed to be set to red, blue, green, or black. Any attempt to set disallowed values results in setting 0 for length and black for color.
    11. Create a method called drawLine() which prints the color and the line using the proper number of asterisks with a for loop and System.out.print(). Make sure to print a newline afterward.
    For example if the lines length is six and the color is red, drawLine() should print the following
    Red: ******
    12. Create a Main class with a main method.
    13. Create a line named line1 using the default constructor.
    14. Prompt the user for a length. Keep prompting until the user enters a number in the range of 1-20.
    15. Prompt the user for a color. Keep prompting until either red, blue, green, or black are entered.
    16. Create a line named line2 passing the values you just received in the previous to steps to the parameter constructor of the line Class.
    17. Draw line1 using the drawLine() method.
    18. Draw line2 using the drawLine() method.

    I know how to start a main class and class line. My problem is I do not know where to go from there. I have tried several different things but all I get red marks. I just need to know what command I should use for this program and how to get started. If you could help me with that I feel confident I could get the rest.
    Last edited by goinsms; June 26th, 2012 at 08:11 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java length color help

    What have you done? Where are you stuck? Posting a copy/paste of a homework assignment implies you wish someone to do it for you. Show you've made an effort and ask a specific question as to where you are stuck and the responses to your post will be much more productive.

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

    Default Re: java length color help

    Believe me I have spent time and effort on this problem. I know how to start a main class and class line. My problem is I do not know where to go from there. I have tried several different things but all I get red marks. I just need to know what command I should use for this program and how to get started. If you could help me with that I feel confident I could get the rest.

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

    Default Re: java length color help

    Make a list of the steps the program must do for the assignment(the assignment you posted has a good list) and then try to do them one at a time. When you have problems, post a description of the step you are working on, the code and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Why does the Color class have two variables for each color?
    By Melawe in forum Java Theory & Questions
    Replies: 5
    Last Post: May 10th, 2012, 04:21 PM
  2. Maximum length of a string
    By ranjithfs1 in forum Java Theory & Questions
    Replies: 3
    Last Post: March 6th, 2012, 09:47 AM
  3. Length of Java source files?
    By ishtar in forum Java Theory & Questions
    Replies: 4
    Last Post: October 13th, 2011, 09:20 AM
  4. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM
  5. max length of an array?
    By qsbladey in forum Collections and Generics
    Replies: 4
    Last Post: April 3rd, 2011, 11:17 AM