1,105,625 Community Members

Java homework help

Member Avatar
SergeantJoKer
Newbie Poster
2 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey everyone. I could use some serious help with a Java method that I have to construct for my CMIS class. Basically, I have to develop a static method that has two arrays in it, one a String array that has values of colors; the other, a Color array that has the proper names for the colors. I have to take a user inputted String and compare it the the Color array and when a match is found, return the RGB integer values of the color as a 3 value int array. I have placed my code below for what I have. I believe that everything is correct except for the if statement that compares the String to the Color object. All help is greatly appreciated. Thanks!

import java.awt.Color;

/**
 *
 * @author johnkershaw
 */
public class homework7 {

    /**
     * @param args the command line arguments
     */
   public static void main(String[] args) {
        // TODO code application logic here
    

    public static int[] getColors(String stringColor) {

        Color[] standardColors = new Color[] {
            Color.BLACK, Color.BLUE, Color.CYAN,
        Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY,
        Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE,
        Color.YELLOW};
        
        

        String[] inputColors = {"BLACK", "BLUE", "CYAN", "DARK_GRAY", "GRAY",
        "GREEN", "LIGHT_GRAY", "MAGENTA", "ORANGE", "PINK", "RED", "WHITE",
        "YELLOW"};
        int[] components = new int[3];
        //Color color = new Color();
        for (int i = 0; i < standardColors.length; i++) {
            if (stringColor.equals(standardColors[i].toString()))
            
            //if (Color.stringColor.equals(standardColors[i]))

                
                //standardColors[i] = new Color();



                 int r = standardColors[i].getRed();
                 int g = standardColors[i].getGreen();
                 int b = standardColors[i].getBlue();


                 components[0] = r;
                 components[1] = g;
                 components[2] = b;
        }

                 
                 return components;
                 
                 
        }
            
    }
Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: