Is there a shorter way

I have to calculate the price of a sandwich with the selected toppings
Is there a shorter way to write the bereken_teBetalen method without changen code outside the method
public class Topping {
     * Alle toppings zijn opgenomen in toppingWaarden.  Toevoeging van
     * een topping en overeenkomstige prijs geeft meteen een extra keuze
     * op overneekomstige schermen.
     * De prijzen zijn achtereenvolgens :
     *  2.0 voor basissandwich zonder topping
     *  + 0.5 voor kaas
     *  + 0.3 voor ham
     *  + 0.2 voor ananas
    String [] toppingsWaarden = {"kaas","ham","ananas"};
    double[] prijzen = {2.0,0.5,0.3,0.2};
    Map<String, Boolean> toppings;
    Topping(){
        toppings = new HashMap <String , Boolean>();
        for(int i= 0;i<2;i++){
            toppings.put(toppingsWaarden,false); }
public boolean is(String topping) {
return (toppings.get(topping)) ? true:false;
* deze methode retourneert de mogelijke toppings als strings.
public String[] getToppingsWaarden() {
return toppingsWaarden;
public void set(String topping,boolean gekozen){
toppings.put(topping, gekozen);
public double bereken_teBetalen() {
double prijs=prijzen[0];
if(is("kaas")) prijs+=prijzen[1];
if(is("kaas")&&is("ham")) prijs+=prijzen[1]+prijzen[2];
if(is("kaas")&&is("ham")&&is("ananas")) prijs+=prijzen[1]+prijzen[2]+prijzen[3];
if(is("kaas")&&is("ananas")) prijs+=prijzen[1]+prijzen[3];
if(is("ham")) prijs+=prijzen[2];
if(is("ham")&&is("ananas")) prijs+=prijzen[2]+prijzen[3];
if(is("ananas")) prijs+=prijzen[3];
return prijs;
public ImageIcon bepaalIcon(){
String bestand = "sandwich images/brood";
for (String s : toppings.keySet()) {
if(toppings.get(s))
bestand += s;
bestand +=".jpg";
return new ImageIcon(bestand);
* Deze methode genereert de tekst overeenkomstige de gekozen sandwich
* bv. : sandwich ham kaas
public String toString(){
return null;

muckv wrote:
I have to calculate the price of a sandwich with the selected toppings
Is there a shorter way to write the bereken_teBetalen method without changen code outside the method
if(is("kaas"))   prijs+=prijzen[1];
if(is("kaas")&&is("ham")) prijs+=prijzen[1]+prijzen[2];
if(is("kaas")&&is("ham")&&is("ananas")) prijs+=prijzen[1]+prijzen[2]+prijzen[3];
if(is("kaas")&&is("ananas")) prijs+=prijzen[1]+prijzen[3];
if(is("ham"))   prijs+=prijzen[2];
if(is("ham")&&is("ananas"))   prijs+=prijzen[2]+prijzen[3];
if(is("ananas"))   prijs+=prijzen[3];
Definitely take previous advice, however, these two things are more or less equivalent (assuming there are no side-effects):
   if(is("kaas"))   prijs+=prijzen[1];
   if(is("kaas")&&is("ham")) prijs+=prijzen[1]+prijzen[2];
   if(is("kaas")&&is("ham")&&is("ananas")) prijs+=prijzen[1]+prijzen[2]+prijzen[3];and
if ( is( "kaas" ) ) {
   prijs += prijzen[1];
   if( is( "ham" ) ) {
      prijs += prijzen[1] + prijzen[2];
      if ( is( "ananas" ) ) {
         prijs += prijzen[1] + prijzen[2] + prijzen[3];
}But note that in both of the above cases, if you have cheese, ham, and pineapple (sorry I don't know your language, so that's just a guess--but I like Hawaiian pizza!), you will be charged prijzen[1] three times, prijzen[2] twice and prijzen[3] once. I'm guessing what you really intend to do is this:
if ( is( "kaas" ) ) { prijs += prijzen[1]; }
if ( is( "ham" ) ) { prijs += prijzen[2]; }
if ( is( "ananas" ) ) { prijs += prijzen[3]; }And, as has been hinted, if you have a class called Topping (as you do), you really should just include a "price" attribute for the class, and add up the price that way.
Edit: Apparently this is for a sandwich! I'm not sure I would like a Hawaiian sandwich.
Edited by: endasil on 6-Jun-2008 12:48 PM

Similar Messages

  • Entity Framework : A short way to copy one object with it's child to a new object ?

    Hello !
    I'm using entity framework 6.
    Sometimes I need to copy an existing object with all its childs to a new object and to save to database.
    I'm using a standart way by creating a new object , copy one by one it's properties from existing object ( except the ID ) , after I create new object for every child and copy one by one each properties except the ID and Parent id......
    But of course this is a hard way to do especially when the object have a lot's of properties.
    I want to know is there any short way  ( built in) to do this ?
    Thank you !

    Actually , I'm using this extension :
    Imports System.ComponentModel
    Imports System.Collections
    Imports System.Data.Entity.Core.Objects.DataClasses
    Imports System.Runtime.Serialization
    Imports System.IO
    Imports System.Reflection
    Module Extensions
    <System.Runtime.CompilerServices.Extension> _
    Public Function Clone(Of T As EntityObject)(source As T) As T
    Dim ser = New DataContractSerializer(GetType(T))
    Using stream = New MemoryStream()
    ser.WriteObject(stream, source)
    stream.Seek(0, SeekOrigin.Begin)
    Return CType(ser.ReadObject(stream), T)
    End Using
    End Function
    <System.Runtime.CompilerServices.Extension> _
    Public Function ClearEntityReference(source As EntityObject, bCheckHierarchy As Boolean) As EntityObject
    Return source.ClearEntityObject(bCheckHierarchy)
    End Function
    <System.Runtime.CompilerServices.Extension> _
    Private Function ClearEntityObject(Of T As Class)(source As T, bCheckHierarchy As Boolean) As T
    If source Is Nothing Then
    Throw New Exception("Null Object cannot be cloned")
    End If
    Dim tObj As Type = source.[GetType]()
    If tObj.GetProperty("EntityKey") IsNot Nothing Then
    tObj.GetProperty("EntityKey").SetValue(source, Nothing, Nothing)
    End If
    If Not bCheckHierarchy Then
    Return CType(source, T)
    End If
    Dim PropertyList As List(Of PropertyInfo) = (From a In source.[GetType]().GetProperties() Where a.PropertyType.Name.Equals("ENTITYCOLLECTION`1", StringComparison.OrdinalIgnoreCase) Select a).ToList()
    For Each prop As PropertyInfo In PropertyList
    Dim keys As IEnumerable = CType(tObj.GetProperty(prop.Name).GetValue(source, Nothing), IEnumerable)
    For Each key As Object In keys
    Dim childProp = (From a In key.[GetType]().GetProperties() Where a.PropertyType.Name.Equals("EntityReference`1", StringComparison.OrdinalIgnoreCase) Select a).SingleOrDefault()
    childProp.GetValue(key, Nothing).ClearEntityObject(False)
    key.ClearEntityObject(True)
    Next
    Next
    Return CType(source, T)
    End Function
    End Module
    But the problem is that when I try to use like this :
    Dim litm, newitm as MyObject
    For Each litm In itemlist
    newitm = litm.Clone()
    newitm.ClearEntityReference(True)
    context.MyObjects.Add(newitm)
    Next
    context.SaveChanges()
    I get an error :
    Public member 'Clone' on type 'MyObject' not found.

  • Shorter way to write a line

    Hello
    is there a shorter way to write variables.
    for example
    if i had a print line that said dollar + nickels + dimes + quarters + pennies);
    this would add them all up and give me the total. is there a way to make that shorter when im using that total to be added to something else so that i dont have to retype dollsr + nickels + etc...
    who would i rewirte that shorter??
    thanks
    r3wind

    Use
    int sum = 0;
    sum = dollars + nickels + dimes + pennies;
    System.out.println("The total sum is "+sum);
    // if you want to add this to some thing else
    sum += 1000;
    System.out.println("The sum now is "+ sum);

  • Output_link is there any easier (shorter) way??

    Is there any easier (shorter) way to create an simple link as the code below? I am wondering that the code for creating an simple link moved from one line
    <h:command_hyperlink href="login.jsp" label="Login Page"/>
    To 4 lines:
    <h:output_link value="login.jsf">
    <f:verbatim>Login Page</f:verbatim>
    </h:output_link>

    AFAIK, there's not an easier way in the beta. I'll pass this on to the rest of the EG.
    Regards,
    Adam Winer (EG member)

  • I shot a short film with my iPhone via iMovie and I was wondering if there  was any way to finish it on my iPad?

    I shot a short film with my iPhone via iMovie and I was wondering if there  was any way to finish it on my iPad?

    How to move Video into iPad, or transfer project:
    https://discussions.apple.com/thread/3860083?tstart=240
    There is a section in the help manual on transferring projects:
    http://help.apple.com/imovie/iphone/1.3/index.html

  • Safari and Others Hang. Is there a good way to diagnose which process is being a trouble maker?

    I have a peculiar problem that has been developing for some time now.
    Current Symptoms:
      Safari (Any Version 5.0-Current) will load but WebProcess.app Opens to 100%
               on one core of CPU (Non-Responsive) and no web-pages will load.
      VLC.app launches in the same fashion, one process pegs to 100%.
      iMovie.app hangs.  Not crashing, but failing to successfully launch.
      Apple Script saved as an application behaves in the same way.
    Attempted Diagnosis:
          I'm currently running OS 10.7.3 on a Early 2009 Mac Pro.
         I have tried:
      Deleted Preferences, and Saved Application States. Then realized the
    problem can't be in ~/Lib/Prefs. because it also is a problem on a clean user
    profile I created to check. So I also looked in /Sys/Lib/Prefs. with no Success.
      I have run disk permissions more times that I can count. 
                    This comes up with regularity but solves nothing:
      Group differs on “Library/Preferences/com.apple.alf.plist”; should be 80; group is 0.
      Repaired “Library/Preferences/com.apple.alf.plist”
      Permissions differ on “usr/lib/ruby”; should be lrwxr-xr-x ; they are drwxr-xr-x .
      Repaired “usr/lib/ruby”
      Reinstalled 10.7.3 from the Combo Updater from apples website.  No Help.
      I did find launching any affected App from the Unix Exe File in the .app
             bundles (So it launches in terminal)  will open them and allow them to
             runwithout issue (yea! temporary fix)! 
    Finally I booted with -x into Safe Mode.  There the problem vanished.  Hooray
            it's another piece of  software or an extension I have loaded (Could  be any over
            the past 6 months or so)!
    So, I rebooted and tried to launch Safari immediately. It worked!  Only after a
            minute or so, when the GUI and background Apps had finished
            loading, the problem returns.
    What I need help with:
    Is there any good way to tell what application is causing the problem or what
    these four apps have in common?  I have looked at Console Logs, Crash Reports,
    etc. etc. but admittedly am not sure what to look for.  I would be happy to post logs
    or reports or more detailed info, if it would help.
    Otherwise Thank-you to anyone who reads this and has any good ideas short
    of a fresh install. Cheers!

    Hi...
    Reinstalled 10.7.3 from the Combo Updater from apples website.
    The only way to reinstall the Mac OS X or repair the startup disk running v10.7.3 Lion, is to use Lion Recovery The combo update does not do that.
    How much free space on the startup disk? Not enough free space can account for the problems with your apps.
    Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. Make sure there's a minimum of 15% free disk space.
    and no web-pages will load.
    Try using OpenDNS as suggested here >  Safari 5.0.1 or later: Slow or partial webpage loading, or webpage cannot be found
    Use OpenDNS for better speed, more security, includes anti phishing filters, prevents browser redirects, and it's free.
    Open System Preferences / Preferences then select the Network tab. Click the Advanced tab then click the DNS tab.
    Click +
    Enter these addresses exactly as you see them here.
    208.67.222.222
    Click +
    208.67.220.220
    Then click OK.
    edited by:  cs

  • Is there no better way to mount a disk than using Disk Utility?

    When an unmounted disk needs mounting, it's kind of a pain to have to load an app (Disk Utility) to mount that disk. Is there no easier way, direct from the Desktop/Dock/Finder/via a third party plugin?

    After you unmount the external drive, turn the power off.
    When you need it again, turn the power to the external
    drive back on and the drive will mount automatically.
    If you will need to access the unmounted volume again after a
    short time interval, then you should just leave it mounted.
    DP 1.25 MDD & 1GHz 12" PB   Mac OS X (10.4.7)  

  • My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    Hey Posada143, You can still try the rice thing, but do not expect much, as roaminggnome has stated. The rice only works if you do it ASAP and leave the iPod off-- do not attempt use, turn on or charge until it is completely dried out. This is probably academic at this point but remember this for the next time: The drying can take 10 days. You put the uncooked rice and iPod in a sealed bag, change the rice every couple of days. This creates a low humidity environment and draws the moisture out of the iPod, but it takes time. Turn your iPod on to earlier, and you run the risk of shorting out, damaging the components inside. Even if done correctly it can spotty. If you do get the iPod to work (and this may require Resetting, Restoring or attempting to place it in DFU recover mode) the first thing you do is make backups, because you never know how long it will continue to work. As for your pictures, if you can't get your iPod to work, you can try data retrieval companies, however; there is no guaranty it will work and it tends to be very expensive. In the future get in the habit of as making backups, because you just don't know. And invest in and use a water tight case. Hope this helps, Good luck. Cheers.

  • Is there an easy way for a client to update a small part of a muse site?

    I am a Creative Cloud subscriber.
    I've made several small websites in Muse and enjoy using it, more so than Dreamweaver, as I'm not a web expert. I've exported those sites as HTML and published them via my own domain and hosting.
    I've been commissioned to make a website where the client can update a small "latest news" section on the site without my intervention.
    Is there any easy way to do this, short of my client buying a Muse subscription?
    Cheers
    Mark

    Hi Eugene,
    look at this
    Jam Session: Advanced CMS Integration with Business Catalyst
    Online Thursday, February 14 / Register now ›
    In this week's Jam session Christopher Kellett of Musegrid.com and Dani Beaumont will break down the process of integrating dynamic data features from the Adobe Business Catalyst Content Management System (CMS) into a published Muse site. The workflow will include inserting modules into your Muse design, changing site layouts quickly and easily, and customizing the integrated design by editing global CSS style sheets. Familiarity with Muse and Business Catalyst highly recommended.
    Best Regards
    TaikaJim

  • Replacement internal battery... is there an easy way ?

    I need a new internal battery for a MacBook Pro 17" Mid-2009.  The old one doesn't last any more, and has bulged and distorted the base so that the thing now rocks from side to side.
    Given that batteries are a consumable, and 3rd party batteries are of unknown quality, I thought I'd spend the money and buy one from Messr Apple and Sons.
    No such luck.  External batteries are available in the Apple Store.  Internal batteries, not.
    So I consulted the chat people.  When we finally agreed that the External battery was not what I wanted, I was referred to my nearest Genius Bar.  Could they give me a price/availability/timescale ?  No.  I have to make time to visit my nearest Genius Bar to find out what they can do, when they can do it and how much this might cost.
    Frankly, I don't think I need a Genius to replace the battery.
    What's more, I don't have the time to waste schlepping my way to the nearest Genius, and would be more than a little irritated if they could not do the replacement on the spot... all this and I'm expected to either pay whatever the Genius wants for the battery and for fitting it, or just eat the waste of my time and go buy a 3rd party battery and have done with it.
    Is there a better way ?

    Why should I not attempt to install a battery on my own ?
    I have been fixing my own machines since god was in short trousers.  The inside of a MacBook Pro is really not that special.
    If Messrs Apple and Sons were prepared to give me (a) a price, and then (b) do the battery swap at an arranged time, I might be just a little less irritated by the rigmarole.
    But I'm also betting it would take two trips to sort this out... which is more BS than I am capable of sustaining without going postal on their posteriors.
    I'm also really curious about the FUD surrounding 3rd party batteries... I'd be nervous buying anything on *B*y or *m*z*n or such-like from some no-name supplier.  But there appear to be some specialist laptop battery suppliers around, who one would hope select their suppliers carefully.  On the other hand, there also appear to be a number of poorly constructed fronts for no-name suppliers.  IMHO what would be useful is a little more in the way of a reputation mechanism one could have some faith in (and a little less sucking of teeth and shaking of heads at the very idea of a battery which is not-made-for-apple-by-their-current-off-shore-suppliers).

  • Is there an easy way to replace/swap assets?

    I output my short from Avid, ran it through Compressor, and made a DVD in DVD Studio Pro.
    Now I've done some re-cuts and want to create a DVD of the new version, using the DVD Studio Pro file I used for the last DVD. Is there an easy way in DVD Studio Pro to "relink" the new video assets to replace the old ones in the new version? This would save me from rebuilding the main menu button, redesigning navigation, and recreating chapter marks.
    I have found a workaround - Quit DVD Studio Pro, "hide" the old assets in a folder, and then direct DVD Studio Pro to the new assets when it asks where the old assets are located. But I wonder if there is an easier way to do this from inside the program.
    Thanks very much for any advice!
    I am using DVD Studio Pro version 4.2.1

    Eric, thanks for chiming in.
    I assume you mean replace the old ones with the new ones on the Finder level?
    Well, part of my goal is to avoid destroying, re-naming, or moving the old assets.

  • Is there a short-cut for this?

    When I add a photo to my timeline I usually need to make it fill my canvas/frame and the way I have been doing this is by selecting the the image in the timeline which then shows the wireframe and "handles" in the canvas window that I can then drag to size the way I want.
    In order to get the right position, I most often have to go to a 12% zoom in the canvas window to see how it is positioning. And at 12%, the image in the Canvas is pretty small in standard view.
    So my question is there a short-cut/key combination that when I select the image and get the "handles" in the canvas, I can make my image larger or smaller without having to resort to using the handles and dragging.
    Does this make sense?
    Thanks.
    Jonathan

    There are no shortcuts.
    Or-- that is the short cut.
    Hey, you're getting paid by the hour, right?

  • My macbook suddenly shut down, and when rebooted, imovie project was completely gone.  No record of it at all.  Have been working on it for days, and it has always been there.  Any way to restore it?  Thanks.

    My macbook suddenly shut down, and when rebooted, imovie project was completely gone.  No record of it at all.  Have been working on it for days, and it has always been there.  Other projects are still there.  Any way to restore it?  Thanks.

    I figured it out!!!
    Hey guys! Here's what I did that saved my project.
    -SHORT VERSION-
    Use the Finder window on your Mac to copy and paste your old project (the one not showing up in imovie) to a new folder so that iMovie will see it.
    -LONG VERSION-
    CONDITIONS:
    The project has to exist on your hard drive. To see if it's hiding around somewhere go to:
    Home (your name)>Movies>iMovie Library (right click and select Show Package Contents)
    In the iMovie Library folder (the default is usually the date) open it to see if your Project is inside. If it is, you are in luck!
    RESTORING PROJECT:
    Open iMovie
    start a new folder under the iMovie Library (again, the default is usually todays date)
    Close iMovie
    In the finder window (as explained above in the CONDITIONS section) select the files and folders of your project and copy them (in my case these consist of folders called Analysis Files, Original Media, "MYPROJECT", Render Files, Shared Items)
    There should now be a folder with today's date in that Show Package Contents folder.
    Paste a copy of your project;s files into this folder.
    When it is done copying, open up the "Original Media" folder and all of your images and clips should be present.
    reopen iMovie. Your project should show up in the Libraries list.
    *If your full project isn't showing in the iMovie timeline (mine just had empty bubbles where all my clips and audio should be) try dragging and dropping the clips and images from the project's "Original Media" folder into the import section of your project. Once the files were reimported, iMovie recognized them all and put them back in the correct place for me.
    Hope this helps someone!

  • When i drag and drop to my ipod it wants to sync everything, but if i make changes to the syncing options and apply it wants to sync it all to make it work. i have 12000 songs and takes two days to sync everything. is there an easier way to drag and drop

    when i drag and drop to my ipod it wants to sync everything, but if i make changes to the syncing options and apply it wants to sync it all to make it work. i have 12000 songs and takes two days to sync everything. is there an easier way to drag and drop just one album without making settings changes?

    The first ever Sync of 12,000 songs to an empty iPod will take a while, but it shouldn't take two days.
    Once all 12,000 songs have been Synced to the iPod, subsequent changes to just one album will result in a very short Sync time. That Sync will include:
    the change to that one album
    play counts on iPod updated into your iTunes Library
    Smart Playlists updated: some complex Smart Playlists are not always updated by the iPod but have to wait for a Sync with the Library.
    housework - in other words, behind the scenes tasks that we don't need to see.
    Those subsequent Syncs do not sync every single song every time.
    So, stick with Syncing. If the first Sync of all your songs is taking too long, try syncing part of the Library (say one or two genres) the first time, a further part the second time and so on. After all, with a Library that large, manually managing the iPod will be a source of torture.

  • Is there any short cut key for opeaning Properties

    Is there any short cut key for opeaning Properties and can we assign short cut key to defined style

    Hi there
    Hopefully Lilybiri won't mind my offering up an observation here.
    Lilybiri wrote:
    ...If it is CP5: the Properties panel of the selected object is automatically focussed on when you select the object on the stage, could you perhaps explain why you want a shortcut?...
    If this is Captivate 5, keep in mind that the workspace may be configured in a variety of ways. For example, the Properties Panel may be collapsed to icons as shown below:
    Certainly when whatever object gains focus, it's there when I expand the collapsed panel. So my guess is that one possibility is mitpancha is asking if there is a shortcut for expanding a collapsed Properties panel.
    According to the Window menu Shift+Control+D should open it. But that doesn't seem to happen here on my own setup. Not sure why.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcererStone Blog
    Captivate eBooks

Maybe you are looking for