NEED immediate help with enumerated data types JAVA

  • Context: Comp Sci 
  • Thread starter Thread starter kirkulator
  • Start date Start date
  • Tags Tags
    Data Java
Click For Summary
SUMMARY

The discussion centers on the use of enumerated data types in Java, specifically the enum PaintColor defined as {RED, BLACK, WHITE, BLUE, GREEN, OTHER}. The user, Amanda, is encountering issues when attempting to instantiate a UsedCars object with a paint color, where the variable 'x' is intended to represent the PaintColor. Despite using valid enum values like RED, the object creation fails. The conversation highlights the importance of providing additional context, such as compiler errors, to diagnose issues effectively.

PREREQUISITES
  • Understanding of Java enumerated types (enums)
  • Basic knowledge of Java class constructors
  • Familiarity with object-oriented programming concepts
  • Ability to interpret compiler error messages
NEXT STEPS
  • Review Java documentation on enumerated types and their usage
  • Learn about Java class constructors and how to pass enum values
  • Investigate common Java compiler errors and debugging techniques
  • Explore best practices for defining and using enums in Java applications
USEFUL FOR

Beginning Java programmers, software developers learning object-oriented programming, and anyone seeking to understand the implementation of enumerated types in Java.

kirkulator
Messages
32
Reaction score
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
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.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K