Question

Another way to write this code package Enum; public enum ColorEnum {       WHITE(0xffffff),   ...

Another way to write this code

package Enum;

public enum ColorEnum {
  
   WHITE(0xffffff),
   BLACK(0x000000),
   BLUE(0x0000ff),
   RED(0xff0000),
   GRAY(0x7a7a7a),
   AQUA(0x00ffff),
   GOLD(0xffd700),
   INDIGO(0x4b0082);
  
   public final int color;
  
   ColorEnum(int color){
       this.color = color;
   }
  
   public int colorValue(){
       return color;
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
package Enum;
public enum ColorEnum {
  //We can convert all hex values to decimal 
  WHITE(16777215),
  BLACK(0),
  BLUE(256),
  RED(16711680),
  GRAY(8026746),
  AQUA(65535),
  GOLD(16766720),
  INDIGO(4915330);

  public final int color;

  ColorEnum(int color){
    this.color = color;
  }

  public int colorValue(){
    return color;
  }
}

Add a comment
Know the answer?
Add Answer to:
Another way to write this code package Enum; public enum ColorEnum {       WHITE(0xffffff),   ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  •     class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN,...

        class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN, RED};        Circle(int = 0, int = 0, double = 0.0, Color = UNDEFINED);        void setX(int);        void setY(int);        void setRadius(double);        void setColor(Color);        int getX() const;        int getY() const;        double getRadius() const;        Color getColor() const;           private:        int x;        int y;   ...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • Write an interactive C++ program that asks a user to input the color code of a...

    Write an interactive C++ program that asks a user to input the color code of a resistor and determines its value and tolerance Tell the user how to input the color rings “Instructions” Tell the user to input the colors one after the other After the program receives the information it will display the resistance and tolerance Output an error message if the user enters an invalid color code (no garbage values should be displayed), and ask for another input...

  • Using the following Java Class.... public class MicroWave { // Represent possible microwave heat selections private...

    Using the following Java Class.... public class MicroWave { // Represent possible microwave heat selections private final int LOW = 1; private final int MEDIUM = 2; private final int HIGH = 3;    // specifies the microwave heat selection(default is MEDIUM) private int heatSelection;    // specifies whether the microwave is on private boolean on;    private String color;    public MicroWave(int heatSelection, boolean on, String color) { this.heatSelection = heatSelection; this.on = on; this.color = color; }   ...

  • [Java] PLEASE FIX MY CODE I think I'm thinking in wrong way. I'm not sure what...

    [Java] PLEASE FIX MY CODE I think I'm thinking in wrong way. I'm not sure what is wrong with my code. Here'e the problem: Write a class SemiCircle that represents the northern half of a circle in 2D space. A SemiCircle has center coordinates and a radius. Define a constructor: public SemiCircle(int centerX, int centerY, int theRadius) Implement the following methods: public boolean contains(int otherX, int otherY) returns true if the point given by the coordinates is inside the SemiCircle....

  • Can the folllowing be done in Java, can code for all classes and code for the...

    Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...

  • Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(),...

    Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(), then implement them, so far in my version i tentatively made them, but I don't know ho to implement them so i posted the original code before i made my version of the three methods listed above. Need help fast, this is ridiculous. Implement just one requirement at a time. For example, try implementing the case where after the user clicks 2 squares, both...

  • C Language Write the code that dynamically allocates an array of struct objects based on a...

    C Language Write the code that dynamically allocates an array of struct objects based on a size entered through the command line arguments, You will use the following struct and enum. typedef enum Color { RED, GREEN, BLUE } Color; typedef struct MyStruct { int value; Color color; } MyStruct; Write the code to do the following: a. Check for one additional command line argument. Only proceed to the rest of the program if it exists and that the value...

  • JAVA Hello I have built two enum classes . Pics attached. How can I create a...

    JAVA Hello I have built two enum classes . Pics attached. How can I create a list of cards from these classes .. shuffle them.. and draw 7 cards at a time ArrayList<Card> Cards; را اراده ج دا ما ها هم اليها و دے ، می داد که ما ده Files 4 package unocardgame; Projects public enum CardType { ZERO ("Zero", 0), ONE ("One", l), TWO("Two",2), THREE ("Three", 3), FOUR("Four", 4), FIVE ("Five",5), SIX("Five",5), SEVEN("Five",5), EIGHT("Five",5), NINE ("Five",5), SKIP("SKIP",0), REVERSE...

  • The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public...

    The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; protected GeometricObject() { dateCreated = new java.util.Date(); } protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT