Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question related to Emumeration

 
Liam Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having issue with the following code. I need to return the description from enumeration to the customerType.toString. Yet, when I declare the variable in the main app, then I will get error when I use cta.setDiscount(CustomerType);

Am I missing something here? Here's my code.

Main App


Enumeration code

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is not an Enumeration, but an enumerated type. Enumeration is an old legacy interface which you ought not to use in new code.
What you are doing is getting confused about what you can use for the switch‑case statement. You ought to be using the members of that enum, bvut you have managed to write it taking Strings. Change the set discount method parameter to take the customer type enum as an argument, and it should work better.
Various things could be tidied up:-
  • I don’t like the name of the set discount method. Maybe setDiscountFromCustomerType???
  • You are calling the getDiscount method twice, but only using its return value once.
  •  
    Winston Gutkowski
    Bartender
    Pie
    Posts: 10243
    58
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liam Smith wrote:I am having issue with the following code. I need to return the description from enumeration...

    1. Be careful when using the term "enumeration" to Java programmers - especially with a capital 'E' - because there is already a legacy class called Enumeration, and it's NOT the same as an enum.

    2. Seems to me that you could put your discounts in your enum, viz:and save yourself a pile of problems.

    HIH

    Winston
     
    Winston Gutkowski
    Bartender
    Pie
    Posts: 10243
    58
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liam Smith wrote:I am having issue with the following code...

    One other non-Java thing:
    ALL your customer types get discounts, so isn't it a bit of a misnomer? Why not just set your prices lower?

    Either that, or break up "RETAIL" into something like "NORMAL" (0%) and "PREFERRED" (10%).

    Winston
     
    Campbell Ritchie
    Sheriff
    Posts: 48652
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote: . . . Why not just set your prices lower? . . .
     
    Liam Smith
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:
    Liam Smith wrote:I am having issue with the following code. I need to return the description from enumeration...

    1. Be careful when using the term "enumeration" to Java programmers - especially with a capital 'E' - because there is already a legacy class called Enumeration, and it's NOT the same as an enum.

    2. Seems to me that you could put your discounts in your enum, viz:and save yourself a pile of problems.

    HIH

    Winston


    Thank you for clearing up difference between enum and Enumeration.

    I would put discount in the enum, but unfortunately text call for method to be used in the main method not in enum.
     
    Liam Smith
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:Welcome to the Ranch

    That is not an Enumeration, but an enumerated type. Enumeration is an old legacy interface which you ought not to use in new code.
    What you are doing is getting confused about what you can use for the switch‑case statement. You ought to be using the members of that enum, bvut you have managed to write it taking Strings. Change the set discount method parameter to take the customer type enum as an argument, and it should work better.
    Various things could be tidied up:-
  • I don’t like the name of the set discount method. Maybe setDiscountFromCustomerType???
  • You are calling the getDiscount method twice, but only using its return value once.


  • Thank you for a warm welcome! Ok, good to know about Enumeration and enumerated type.

    I have tried to change set discount method parameter, and I am not sure how? I am getting errors.

    Thank you for other suggestions, I have applied the changes and as soon I figure out how to make set discount method to take enum, I will re-posted the code.
     
    Winston Gutkowski
    Bartender
    Pie
    Posts: 10243
    58
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:
    Winston Gutkowski wrote: . . . Why not just set your prices lower? . . .

    Cynic. Mind you, I was made privy (a while ago and, I'm sure, by mistake) to the list of "discounts" available, even to proles like me, at places like Curry's.

    Basically, it works like this:
    If you moan about the price, the floor 'sales lackey' has about 5% discretion to try and get a sale if they want. For anything between about 5-15%, a "manager" has to be called (just so you know you're really getting a good deal).
    After that, you'll need to produce proof that you can still get it cheaper elsewhere - and watch out for "added extras" (like delivery charges, or non-requested insurance or extended guarantees) on your bill.
    I recently discovered (only once I got home unfortunately) that a local appliance store had charged me 8 Euros "service" for taking a freezer I'd bought out to my car (all of 20 yards), because I'd blagged a good price out of them. I couldn't be fagged to go back and complain because the one I got was 70 Euros cheaper than I could've got elsewhere (which, I suspect, is what they gamble on).

    It seems like everything works on the "car sale" paradigm these days <sigh>.

    Winston
     
    Campbell Ritchie
    Sheriff
    Posts: 48652
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    About 25 years ago somebody bought a microwave at Currys’ … and took it back because there were missing segments on the LED display.
    Then I bought a microwave at Currys’ and took it back a few days later because there were missing segments on the LED display. Yes, it was the same microwave. They were falling over themselves to give me a new microwave and discounts.
    I still have that second microwave, and it still works.
     
    Liam Smith
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am still struggling on this issue. Is there any link or information where I can look up more about how to call enum as argument in method?

    Thanks!
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liam Smith wrote:I am still struggling on this issue. Is there any link or information where I can look up more about how to call enum as argument in method?

    Thanks!


    You can certainly google for something like java enum tutorial. If you want help here though, you'll need to provide more details about what you tried and what problems you're having with it.
     
    Campbell Ritchie
    Sheriff
    Posts: 48652
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Once we start chatting about prices and microwaves, you have had it. The thread has gone for a Burton. But this is probably the tutorial Jeff V mentioned. If you go to the index page ad look for “branching statements”, you will probably find about the switch-case statement.

    Actually, you won’t find it there. Try here.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic