NEED immediate help with enumerated data types JAVA

  • Comp Sci
  • Thread starter kirkulator
  • Start date
  • Tags
    Data Java
In summary, the conversation discusses an issue with an enumerated data type created for a UsedCars class. The person is trying to create an object in their TestUsedCars class using the PaintColor enum, but is experiencing difficulty with it. They mention not knowing much about using enumerated types and struggling to figure out how to use it. They also mention that they have tried inputting values like RED, but it does not work.
  • #1
kirkulator
33
0
okay so i have my program basically done, i just have one problem and it has to do with an enumerate data type i created

public enum PaintColor {RED, BLACK, WHITE, BLUE, GREEN, OTHER};

in my class that is UsedCars
im tracking attributes of these objects [used cars]
now...on my TestUsedCars class, I am trying to create the object

but no matter what i type in for paint color it doesn't work:

UsedCars basicCar = new UsedCars("honda", "9d9d9d9d0", 1999, 120000, x , 99.0);

'x' is the paintcolor
by the way, the other values are data fields:
carmake, vin number, year manufactured, odometer mileage, paintcolor, car condition rating

i tried putting in RED like i should be able to...or so i thought but it won't work.

thanks so much guys, i literally know nothing about using enumerated types. they just instructed me to do so and gave me one line of code on how to define the enum...so I am struggling figuring out how to do other things with it.

amanda
edit: by the way its beginning JAVA programming, sorry i didnt specify.
 
Physics news on Phys.org
  • #2
kirkulator said:
okay so i have my program basically done, i just have one problem and it has to do with an enumerate data type i created

public enum PaintColor {RED, BLACK, WHITE, BLUE, GREEN, OTHER};

in my class that is UsedCars
im tracking attributes of these objects [used cars]
now...on my TestUsedCars class, I am trying to create the object

but no matter what i type in for paint color it doesn't work:

UsedCars basicCar = new UsedCars("honda", "9d9d9d9d0", 1999, 120000, x , 99.0);

'x' is the paintcolor
You should be able to put in RED or BLACK or other value of your enumerated type. When you say "it doesn't work," it would be helpful for you to tell us why it doesn't work. Also, without seeing your code, it's hard to understand what the difficulty is.

Seeing your code would help, as would the text of any compiler error that is generated.
kirkulator said:
by the way, the other values are data fields:
carmake, vin number, year manufactured, odometer mileage, paintcolor, car condition rating

i tried putting in RED like i should be able to...or so i thought but it won't work.

thanks so much guys, i literally know nothing about using enumerated types. they just instructed me to do so and gave me one line of code on how to define the enum...so I am struggling figuring out how to do other things with it.

amanda
edit: by the way its beginning JAVA programming, sorry i didnt specify.
 

1. What are enumerated data types in Java?

Enumerated data types in Java are a type of data structure that allows you to define a set of named constants. These constants can be used to represent a specific set of values, making it easier to manage and reference them in your code.

2. How do I declare an enumerated data type in Java?

To declare an enumerated data type in Java, you use the enum keyword followed by the name of your enumerated type and a set of curly braces. Within the curly braces, you define your named constants, separated by commas.

3. How do I use an enumerated data type in my code?

To use an enumerated data type in your code, you simply reference the name of the enumerated type followed by a dot and the name of the named constant you want to use. For example, if you have an enumerated type called Color with constants RED, GREEN, and BLUE, you can use them as Color.RED, Color.GREEN, and Color.BLUE.

4. Can I assign values to my named constants in an enumerated data type?

Yes, you can assign values to your named constants in an enumerated data type. You can either explicitly assign a value to each constant, or you can let Java automatically assign values starting from 0.

5. Are enumerated data types useful in Java?

Yes, enumerated data types are very useful in Java. They provide a convenient way to represent a set of related values, making your code easier to read and maintain. They also help prevent errors by limiting the possible values that can be assigned to a variable of that type.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top