Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attempting to create array for Color Class - invalid integer inputs

 
Shawn Grasso
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to define a color by inputting multiple Red, Green, and Blue values from three arrays - although I can't seem to do so. I understand that this type of code may not be possible in the manner that i've written it... how can i accomplish this?

Here's the code:



I'm new to Java so any help would be much appreciate - thanks!
 
Stevens Miller
Bartender
Posts: 1302
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at line 14 and describe to us in plain language what you think it does. When you do, it would help if you would address each of these questions:

  • How many Color object instances does Line 14 create?
  • Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")?
  • Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)?
  • What error message do you get when you try to compile this (or from your IDE), and what do you think it means?
  •  
    Shawn Grasso
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Look at line 13*? and describe to us in plain language what you think it does. When you do, it would help if you would address each of these questions:

    How many Color object instances does Line 13 create? 3
    Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")? I mean to put multiple R,G,B values under one color in order to combine those values from each of the above arrays. Listing each color combination out wouldn't be a sound way of doing so.
    Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)? Thank-you, skipped over 3.
    What error message do you get when you try to compile this (or from your IDE), and what do you think it means? No suitable Constructor found.



     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 50245
    79
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Using parallel arrays is a very dubious practice; it is very error‑prone because the arrays might get out of phase with each other.
    Have you read through the documentation about constructors for that class? You cannot pass an array.
    You mentioned creating an array for Color, but you haven’t created any such array.
     
    Stevens Miller
    Bartender
    Posts: 1302
    24
    C++ Java Netbeans IDE Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Shawn Grasso wrote:How many Color object instances does Line 14 create? 3

    A constructor returns a reference to one object: the one it just constructed. You may need to study up on the basics of the new keyword and constructors before going further.

    Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")? I mean to put multiple R,G,B values under one color in order to combine those values from each of the above arrays. Listing each color combination out wouldn't be a sound way of doing so.

    If you are trying to mix those colors into a single color, then you need to do that before creating the one Color object that will hold their combined value. Or, you will need to create as many Color objects as you have colors in your arrays (and, btw, I agree with Campbell that parallel arrays are dangerous, as you've already experienced), then combine them into a single Color object. (I think that's not what you're trying to do, however.)

    Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)? Thank-you, skipped over 3.

    No problem. See Campbell's comment, though.

    What error message do you get when you try to compile this (or from your IDE), and what do you think it means? No suitable Constructor found.

    And that's what your problem is. You are passing arrays to the Color constructor. There is no Color constructor that accepts arrays.

    Now, you did answer my suggested questions, but you haven't yet described what it is you are trying to do. Do that, and maybe we can help.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic