Enumerated types help

Hi guys. I am working on a project that requires using an enumerated type Coins to make an application that allows a user to enter an amount of change between 1 and 99 cents and then calculates the fewest coins required for that amount. The possible coins are quarters, dimes, nickels and pennies. The enumerated data type, named Coins should have a coin color, size and denomination associated with each coin. I am probably going about this in an unorthodox way, but my enumerated type Coins isn't working properly.
If you can see what is going on in my code, I would appreciate any insight you can provide.
import java.awt.*;
class ChangeWindow extends GraphicsWindow
     private static final int WINDOW_WIDTH = 500;
     private static final int WINDOW_HEIGHT = 300;
     //Establishes the Change Window
     public ChangeWindow()
          super("Change", WINDOW_WIDTH, WINDOW_HEIGHT);
     //Create the enumerated type Coin
     public enum Coin
          QUARTER,
          DIME,
          NICKEL,
          PENNY
     //Sets the change amount
     public void setChange(int change, Graphics graphics)
          int quarters, dimes, nickels, pennies;
          int toText = change;
          //Determine how many quarters
          if (change >= 75)
               quarters = 3;
               change -= 75;
          if (change >= 50)
               quarters = 2;
               change -= 50;
          if (change >= 25)
               quarters = 1;
               change -= 25;
          //End quarter determination
          //Determine how many dimes
          if (change >= 20)
               dimes = 2;
               change -= 20;
          if (change >= 10)
               dimes = 1;
               change -= 10;
          //End dime determination
          //Determine if there is a  nickel
          if (change >= 5)
               nickels = 1;
               change -= 5;
          //End nickel determination
          //Determine if there are pennies
          if (change != 0)
               pennies = change;
          //End penny determination
          for (Coin coin: Coin.values())
            if (coin == QUARTER)
               //Paint Quarters
               int quarterY = 25;
               for (int i = 1; i <= quarters; i++)
                    paintComponent(graphics, QUARTER, quarterY);
                    quarterY -= 5;
            if (coin == DIME)
               //Paint Dimes
               int dimeY = 25;
               for (int i = 1; i <= dimes; i++)
                    paintComponent(graphics, DIME, dimeY);
                    dimeY -= 5;
            if (coin == DIME)
               //Paint Nickel
               for (int i = 1; i <= quarters; i++)
                    paintComponent(graphics, QUARTER, 25);
            if (coin == DIME)
               //Paint Pennies
               int pennyY = 25;
               for (int i = 1; i <= quarters; i++)
                    paintComponent(graphics, PENNY, pennyY);
                    pennyY -= 5;
     //Paints the individual coins
     private void paintComponent(Graphics graphics, Coin coin, int y)
      switch (coin)
         case QUARTER:
            graphics.setColor(Color.GRAY);
            graphics.fillOval(100, y, 30, 30);
            graphics.setColor(Color.BLACK);
            graphics.drawOval(100, y, 30, 30);
            //graphics.drawString(denom, x, y - 15);
            break;
         case DIME:
            graphics.setColor(Color.GRAY);
            graphics.fillOval(200, y, 15, 15);
            graphics.setColor(Color.BLACK);
            graphics.drawOval(200, y, 15, 15);
            //graphics.drawString(denom, x, y - 7);
            break;
         case NICKEL:
            graphics.setColor(Color.darkGray);
            graphics.fillOval(300, y, 25, 25);
            graphics.setColor(Color.BLACK);
            graphics.drawOval(300, y, 25, 25);
            //graphics.drawString(denom, x, y - 12);
            break;
         case PENNY:
            graphics.setColor(Color.ORANGE);
            graphics.fillOval(400, y, 20, 20);
            graphics.setColor(Color.BLACK);
            graphics.drawOval(400, y, 20, 20);
            //graphics.drawString(denom, x, y - 10);
            break;
}oh and if you think my Change Window class has anything to do with it, let me know and I'll post it. Thanks!

negativ_zero wrote:
I see, that would make it easier, however I haven't found examples of using an enum like that. Most examples are over my head, or do not go beyond what I have. Any suggestions? Yes, search the forums. I know that I and many others have posted many examples of using enum like this. A search I most definitely recommend is on the terms -- enum "paul.miner" -- the guy's an enum genius.
Also, I think I am using the enum type incorrectly, because I compile, it pops up with multiple errors saying "cannot find symbol variable QUARTER" (same for dimes, nickels, and pennies). Any pointers here as well?What if you use Coin.QUARTER and the same for the others?

Similar Messages

  • Switch statement with enumerated types

    Hello,
    I'm currently having problems (error in eclipse) using enums in a
    switch block. Eclipse says:
    "The enum constant Constants.AnalysisType.<each case> reference cannot be qualified in a case label.
    for each of the cases that I try to use the enumerated type. My code
    looks something like this:
    switch (analysisType) {
    case Constants.AnalysisType.NONE:
        break;
    case Constants.AnalysisType.MVGAVG:
        break;
    }(With a number of cases omitted).
    where analysisType is the enumerated type defined in
    a file called Constants.java.
    The class where the error is occuring is located at:
    package myprog.ui.ViewPanelTab; and the enumerated type is declared at:
    package myprog.utility.Constants;I have the required import statements in the ViewPanelTab class.
    I have tried
    public, private, public static, private static as modifiers on the enumeration.
    Any ideas as to why eclipse won't let me do this.
    Thanks for any help
    Devon

    Why is it that the entire switch and all of its cases have the same locality ?By "locality" do you mean "scope" (i.e. the inability to declare two variables with the same name)? I find it rather irritating that I can't write switch (foo)
        case bar:
            int quux = ...
            break;
        case baz:
            int quux = ...
            break;
    }My guess as to the reason for the decision to disallow this is that otherwise removing a break statement could create a compiler error where there previously was none, and that this would be confusing. It is possible to create a fresh scope, though, by using braces:switch (foo)
        case bar:
            int quux = ...
            break;
        case baz:
            int quux = ...
            break;
    }

  • Custom Enumeration Type and Dropdown in Web Dynpro Java

    Hi Everyone!
    I have developed a custom enumeration type named com.agile.pmg.politicrh.customtypes.status.
    I can see correclty the dropdown with the enumeration in Service Browser with all values I have put, but I need to be able to see these values in web dynpro too. But if I create a attribute of type com.agile.pmg.politicrh.customtypes.status in web dynpro and map it to a dropdown, it doesnt show anything. The enumeration is empty.
    Does anyone know what is the problem?
    Bests Regards!
    Luiza

    Hi,
    Check out this link, might be of help
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/504540a4-fd0d-2a10-7c8e-c88289cf6457|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/504540a4-fd0d-2a10-7c8e-c88289cf6457]
    Regards,
    Ashutosh

  • Search Hierarchy for All Enumerated Types

    I have inherited a large hierarchy of code (about 1200 VI's) and am in the process of modifying it.  Unfortunately the previous developers who have worked on the code either did not know about Type Definitions or chose not to use them for the challenge.  I have updated an enumerated type and after poking around have found that there are many others like it peppered throughout the hierarchy that also need updating.  Their names are similar but not necessarily the same, close enough that if I could search over all enumerated types in the hierarchy I chould most likely pick out the ones I need and dare I say replace them all with a single type defined enumeration.  The problem is that I dont know how to search a hierarchy for all enumerated types, I see an option to search for all front panel terminals but the search quits after finding 2000 (not to mention that this enumeration will exist as control, constant or indicator).  Anyone have any ideas?
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.

    Will S. wrote:
    To help you with this, you can programmatically search your VIs to find the number of Enums you have in each. That might at least help you keep track of your changes. You could even make all of them blink so they are easy to find. For details on how to do this, see the following thread:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=359515&requireLogin=False
    That will help you find them on the FP but not the block diagram.
    For the BD this should work.
    Just select the enum constant for the numeric palette.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Problems with enumerated type and DataSocket

    I am publishing an enumerated type variable using DataSocket write and I am having problems subscribing to this with other clients on the network. I can get the program to work ok if I replace the enumerated type with a straight numeric or a Text Ring for example. Is there anything special I should be looking out for when using enumerated types in this type of application.
    Thanks Kelly

    Updating to the latest version of LabVIEw (6.0.2) should correct this problem:
    http://digital.ni.com/softlib.nsf/websearch/F983BDA17B8F401B862569EC005A11C2
    Also, I would suggest updating to the latest version DataSocket:
    http://digital.ni.com/softlib.nsf/web%2Fall%20software?OpenView&Start=1&Count=500&Expand=6#6
    Chris_Mitchell
    Product Development Engineer
    Certified LabVIEW Architect

  • How do I make a Type Def an Enumerated type?

    Bare with me as this is my very first time using a Type Def
    I tried following the tutorial at http://zone.ni.com/devzone/cda/tut/p/id/5318
    The first one worked alright that was the Master Mode, but that was starting with a previously created control.
    My first attempt at creating a new control did not go so well, see my Sys1 control.
    How do I make the control an enumerated type so it names the cases for me when creating a new control? 
    Message Edited by RTSLVU on 04-21-2009 09:55 AM
    Attachments:
    Sys1.ctl ‏5 KB

    No one mentioned in this thread yet so I add...
    That if you do a right-click replace then naviagte to a enum, the new enum will retain all of values and you don't have to re-enter them.
    An extention of this idea is useful when creating an enum with a 100 values or more. Write code to populate a ring control with the required strings then after, dod the replac with thing.
    Sure has saved me a lot of work.
    Ben 
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • When i open FF start the google is so small I cant read what i type HELP!

    When i open FF start page the google block is so small I cant read what i type HELP! how do I make this larger?????

    The text editor is the text area that you use on the webmail (Yahoo, Hotmail) website to create a new mail.
    You can compare that with the ''Post new message'' text area that you use to create a new post on this forum.
    Just above the text area that you use to enter the message text there is usually a button bar with buttons that allows some text formatting like Bold and Italic and can also include a button to make a clickable hyperlink.
    Check the tooltip of each button by hovering with the mouse over each button.
    Make Link - https://addons.mozilla.org/firefox/addon/142

  • Enumerated Types Exposed in Teststand Not Working Quite Right

    Hi All,
    I have a LabWindows/CVI driver where one of the APIs is an enumerated type. I followed some of the posts where it instructed me to create the enumerated data type in *.h file, add it to the *.c API, create a FP and add the new type to the API, configure the target settings to "add type library resource to DLL" and build.
    I see the enumerated data types, but the description of the new type is garbage. See the attached JPG. I see "__MIDL__MIDL_itf_IALdi1_0000_0001" for the description of the enumerated type.
    I have looked all over the place for a setting, etc. but can't figure it out. Does anyone else have or had the same problem? And a solution.
    Thanks
    Minesh
    Attachments:
    Types.jpg ‏113 KB

    Hi All Again,
    I found an example from NI, cvi_enumerated_values.zip. If I include the DLL that was prebuilt, everything is fine, no Enumeration name mangling. But if I rebuild with LabWindows/CVI 8.5 or 2010 and then use the corresponding DLL, I get the description naming mangling again. So, it seems to be a build or environment issue. Still trying to track the issue down.
    Thanks
    Minesh
    Attachments:
    cvi_enumerated_values.zip ‏70 KB

  • Java Vector to Oracle type; help?

    I've seen only a few postings on this topic, none of which were answered. So I am thinking perhaps a detailed explanation is required? Or is it just too simple to be beyond boring? I need professional help in any event.
    I have an applet users employ to create a table of values. The data model for the table is, ultimately, a Vector, each element of which is itself a Vector with the following fields (all of which are Strings): symbol, label, description, colour, numpar, parent, parsing, objectid. So, I have a Vector of any length comprised of Vectors of length 8.
    On pressing the "SAVE" button I wish the Vector of Vectors to be sent to my Oracle database. To receive the data I created these types in Oracle:
    TYPE LegendItem IS OBJECT(symbol VARCHAR2(50),
    label VARCHAR2(50),
    descrip VARCHAR2(255),
    colour VARCHAR2(20),
    numpar VARCHAR2(10),
    parent VARCHAR2(10),
    parsing VARCHAR2(625),
    objectid VARCHAR2(10));
    TYPE AppletVector IS TABLE OF LegendItem INDEX BY BINARY_INTEGER;
    The stored procedure that takes the data and uses it to update (about 25) tables in the schema is defined as
    PROCEDURE loadLegend (legendata IN AppletVector,
                   schemeid IN INTEGER,
                   sourceid IN INTEGER,
                   message OUT VARCHAR2)
    (Message is returned as "success" if there are no exceptions, or the exception parameters if they exist.)
    I am trying
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    Connection conx_out = DriverManager.getConnection ("jdbc:oracle:thin:@myserveraddress","username", "password");
    CallableStatement feedOra = conx_out.prepareCall("{ call newLegendData.loadLegend(?,?,?,?) }");
    ArrayDescriptor arrDesc = ArrayDescriptor.createDescriptor("AppletVector", conx_out);
    feedOra.setArray(1, new ARRAY(arrDesc, conx_out, legendModel.getDataVector().toArray()));
    feedOra.setString(2, MakeLegend.mapScheme);
    feedOra.setString(3, MakeLegend.mapSource);
    feedOra.registerOutParameter(4, Types.VARCHAR);
    feedOra.execute();which returns
    setArray(int,java.sql.Array) in java.sql.PreparedStatement cannot be applied to (int,oracle.sql.ARRAY)
    feedOra.setArray(1, new ARRAY(arrDesc, conx_out, legendModel.getDataVector().toArray()));
    ^
    cannot resolve symbol
    symbol : method setString (int,int)
    location: interface java.sql.CallableStatement
                   feedOra.setString(2, MakeLegend.mapScheme);
    ^
    cannot resolve symbol
    symbol : method setString (int,int)
    location: interface java.sql.CallableStatement
                   feedOra.setString(3, MakeLegend.mapSource);
    Is this the way to approach the problem? Should I use a different method? How do I make java.sql.Array == oracle.sql.ARRAY?
    Your suggestions are gratefully received.

    Not a problem, the code will below is the basics
    // the vector of vectors you are going to write.
    Vector aVectorOfVectors;
    // create a ByteArrayOutputStream so you can get the data to create an inout stream
    ByteArrayOutputStream aBaos=new ByteArrayOutputStream();
    // make an objectOutputStream to write your searlizable to.
    ObjectOutputStream anOut = new ObjectOutputStream(aBaos);
    // write your vector of vectors
    anOut.writeObject(anObject);
    // get the byte array from the ByteArrayOutputStream
    byte[]aByteArray = aBaos.toByteArray();
    // create the input stream from the byte array
    ByteArrayInputStream aBais = new ByteArrayInputStream(aByteArray);
    // set this as the binary stream for your column.
    insertPreparedStatement.setBinaryStream(aColumn,  aBais, aByteArray.length);when reading the data you basically do the reverse and cast the result
    ObjectInputStream anInputStream = new ObjectInputStream( theResultSet.getBinaryStream(aColumn));
    Vector aVectorOfVectors = (Vector) anInputStream.readObject();

  • Mime type help required

    with following code
    response.setContentType("application/vnd.ms-excel");
    response.addHeader("Content-Disposition"," filename=OpportunityReport.xls");
    dialog shows download dialog with three buttons
    Open, Save, Cancel
    i want to show only
    Save and Cancel
    how to adjust mime type?

    That would have helped, I supposed :o)
    However, I've resolved the issue.

  • Nat Type help

    Hello
    Im currently having issues with the Home hub 2.0a with the pc game COD:Ghosts.
    It seems no matter what portforwarding i do my NAT type stays strict. I have even turned off both windows firewall and the hubs firewall and it has had no effect at all on my NAT type.
    Anyone able to help me? im not that advanced with pcs.
    Thanks
       Mike
    Solved!
    Go to Solution.

    This link may help.
    NAT Problems on games consoles and computers
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • Open NAT Type help ( CISCO WRV210 )

    Hello, can anyone help me open my NAT Type? it says my NAT Types : 2 and that it is Moderate,i really really really want to open it , I Tried going to the Small Business webpage and I Couldn't find anything that's why I came back here, could anynone help me?
    My main priority is to open NAT on PS3, Doesn't matter for PC but only PS3, I Tried putting my PS3 and into DMZ With and without UPnP Enable and nothing changed, could anyone please help me?

    tell me how i can post the same thing there and i will give you some Kudo

  • Type help is not taking text

    Hi All,
    I have a page where i have selected a region, under that the type is Help Text. But whatever i am putting in source is not displaying. Any suggestion what could be the reason.
    Regards

    Hey!
    app.selection[0].textWrapPreferences.textWrapMode = TextWrapModes.CONTOUR;
    TextWrapModes.BOUNDING_BOX_TEXT_WRAP
    Wraps text around the object's bounding box.
    1651729523 = 'bsds'
    TextWrapModes.CONTOUR
    Wraps text around the object following the specified contour options.
    1835233134 = 'mcon'
    TextWrapModes.JUMP_OBJECT_TEXT_WRAP
    Forces text to jump above or below the object, so that no text appears on  the object's right or left.
    1650552420 = 'band'
    TextWrapModes.NEXT_COLUMN_TEXT_WRAP
    Forces text to jump to the next available column.
    1853384306 = 'nxfr'
    TextWrapModes.NONE
    No text wrap.
    1852796517 = 'none'
    tomaxxi

  • File type help

    Hi All
    I was just wondering if anyone could tell me or point me in the direction of a list of file types that illustrator can open.
    I am the CAD manager here and have been asked to find a better file type than PDF to send to the advertising agency we use.
    Any help would be hugely appriciated.
    Kristian

    File>Open the drop down for file types as such:

  • C3 touch and type HELP with mms and email

    I have a C3-01 touch and type my provider is AT & T I need any help to get my email settings and internet settings AT & T have been NO help since i did NOT buy my phone threw them!!! At first I had trouble with receiving pic messages and send pic messaging so i sent a question threw nokia and someone had the settings i followed the steps and now i can receive and send pic messages and AT & Twas trying to tell me I wouldn't be able to since i didn't buy my phone threw them they were of NO help so now i am asking anyone that can help again i need the steps to set my phone so i can get my email and internet any one with info let me know THANK YOU!!!   Iove this phone i just can't get any support from AT & T

    herzlos:
    What firmwire do you currently have?
    Turn off your phone and then turn on your phone. Usually resetting the phone temporarily fixes the problem
    My Nokia C3-01 Software details:
    V 05.60
    06-10-10
    RM-640
    (c) Nokia
    Found this by: Menu>Settings>Phone>Phone updates>Curr. sw details

Maybe you are looking for

  • Mail messages won't load in Mail 4.5

    After a seeming successful installation of Snow Leopard, my Mac Mail also seemed to update properly (4.5). All my incoming items are listed. However, after double clicking on any e-mail in the inbox, a window opens up with the title of the e-mail, bu

  • Hyper-V can't create a network switch in Windows 8 enterprise evaluation

    Hello I have a problem with creating a new virtual network switch in windows 8.  it's the error: [Window Title] Virtual Switch Manager for HYPER-VISOR [Main Instruction] Error applying Virtual Switch Properties changes [Content] Failed while creating

  • Online Essbase backup

    Hi All, Can anyone tell me the how do i do the online essbase backup. IF yes how and can i take backup of database while calculations are executing.... Regards, Mink

  • Refreshing problems for an online dice

    here's the problem http://www.geocities.com/nsmela/java/onlinedice.html notice how you can't roll afterwards? how can i change this?

  • How to get transation(mm01 or va01 etc) in alv

    how to get transation(mm01 or va01 etc) in alv using hot spots