Trying to create a loop that stores x variables of a class I created

I created the class Dice. To create a new Dice with 6 sides, I do
Dice name = new Dice(6); Next, I have the class DiceN which is supposed to create N dices and store them inside an array or ArrayList. The constructor of DiceN´s takes in a number n that the constructor uses to create n dices. This is what I´d like the class DiceN to be like:
import java.util.*;  // to use ArrayList
public class DiceN {
  ArrayList dices = new ArrayList(); // holds all the dices the constructor will construct
  public DiceN( int n ) { // the constructor that creates n dices
    for ( int i = 0; i < n; i++ ) {
      Dice x_i = new Dice(6); // if n = 3, the variables x_0, x_1 and x_2 will be created: 3 dices with 6 sides each
      dices.add(x_i); // each time a dice is created it is stored in the arrayList for further usage
}Obviously, one can´t dynamically create instances of Dice by using the code in the for loop, but how can I create n many dices and store them into the ArrayList, or even better, in an array without knowing beforehand how many dices will be constructed?

Dice x_i = new Dice(6); // if n = 3, the variables x_0, x_1 and x_2 will be created: 3 dices with 6 sides eachOffcourse instances with names like x_0, x_1 and x_2 are not created here. But Different instances are indeed created, each time having same name x_i ( there is no relation between 'i' in x_i and 'i' in for loop, so x_0, x_1, etc won't be created).
Here new Dice(6) will each time create new instances, so it serves the purpose as required by you.
For your better understanding try running below sample code and see value of 'a' is different for each instance because they indeed different instances stored in ArrayList:
import java.util.ArrayList;
public class DiceCheck
     public static void main(String[] args)
          DiceN diceN = new DiceN(3);
          diceN.showDices();
class Dice
     int sides;
     int a=0;
     public Dice(int sides)
     this.sides = sides;
     public int getA()
          return a;
     public void setA(int a)
          this.a = a;
class DiceN
     ArrayList dices = new ArrayList();
     public DiceN(int n)
          for(int i=0;i<n;i++)
               Dice x_i = new Dice(6);
               x_i.setA(i);
               dices.add(x_i);
     public void showDices()
          for(int i=0;i<dices.size();i++)
               Dice x_i = (Dice)dices.get(i);
               System.out.println(x_i.getA());
}

Similar Messages

  • Request - The table that stores various variables (modifiable)

    Hi,
    I am trying to find the standard table that stores various variables in the SAP system and is modifiable. I think it starts with a "T" but I can't be sure.
    Please help.
    Thanks,
    John

    I think you are talking about TVARV
    TVARV is  Table of variables in selection criteria .
    Hope this helps
    Vinodh Balakrishnan

  • TS4002 I'm trying to create a new apple-id but when typing the email adress I want to use I'm told that the particular email adress is not allowed but when searching I can't find same being used. How do I find out where that particular email adress is use

    I'm trying to create a new apple-id but when typing the email adress I want to use I'm told that the particular email adress is not allowed When searching I can't find same being used anywhere. How do I find out where that particular email adress is used so I can delete it there and use it for my new apple-id?

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    Also
    If you have Find My iPhone enabled, you can use Remote Wipe to erase the contents of your device. If you have been using iCloud to back up, you may be able to restore the most recent backup to reset the passcode after the device has been erased.

  • How to create an infinite loop that cannot be cancelled?

    Hi , im new around java and i need a program that keeps on repeating after each each input/uses(generally meant for different user) and cannot either stop using "Cancel" or "x" while stopping only using the "stop" button
    I got a few lines of codes that look like this : String arg = "";
    do{
    JOptionPane.showInputDialog("hi");
    }while ( arg != "y" || arg!= "Y");
    and it cannot be stop with both cancel and"x"(which i wanted)
    but when i used this logic with
    Valid validUserInput = new Valid();
    do {
    userInput = validUserInput.validUserInput(a);
    switch(userInput){
    case 1 : validUserInput.optionOne(b);break;
    case 2 : validUserInput.optionTwo(c);break;
    case 3 : validUserInput.optionThree(d,e);break;
    default : validUserInput.validUserInput(f);
    }while(looping != "" || looping != " ");
    it does not really work(while it will keep looping, it can be easily stop by pressing cancelled or "x")
    So is there any logic or method that can prevent the program from being stop?
    Thankyou!

    elricscript wrote:
    "That is helpful. It gives him a direction where he can focus his research. Namely, 'how to run a program in kiosk mode' rather than 'how to create an infinite loop that cannot be cancelled.'"
    No... He already mentioned he wants to "e.g Interactive kiosk", so saying "properly kiosk it" isn't adding any new information. Rather it's just giving the person a dead point of: you're doing it wrong. Pointing out someone is wrong is not a positive enlightenment. Pointing someone in the right direction is more productive.
    >"That is helpful. It gives him a direction where he can focus his research. Namely, 'how to run a program in kiosk mode' rather than 'how to create an infinite loop that cannot be cancelled.'"
    No... He already mentioned he wants to "e.g Interactive kiosk", so saying "properly kiosk it" isn't adding any new information.
    Yes it is. He asked how to do it using some Swing trickery, and I said it won't work. Which is true. The OP didn't already know that, clearly, hence the question. Now he does. That's pretty much new information if you ask me.
    Rather it's just giving the person a dead point of: you're doing it wrong.Right. He is. However, the problem is now no longer related to Java, and not something I can help him with. You should try that: not answering questions you don't know the answer to. It's actually more helpful than posting misleading, wrong answers.
    Pointing out someone is wrong is not a positive enlightenment. I'm giving basic technical help, not yoga lessons.
    Pointing someone in the right direction is more productive.As already stated, I am as ignorant of how to make a Java application into a kiosk app as the OP is. What value can I add in light of that information? I began by answering a question that was not stated to be about kiosks. Once the question moved outside of my area of knowledge, I stopped trying to answer.
    I notice you're not giving him any help, being more interested in admonishing others as you are.

  • I created an iCloud account for my sons ipod tried to sign into the App Store and it just keeps coming up with unknown error can you help

    I created an iCloud account for my sons ipod tried to sign into the App Store and it just keeps coming up with unknown error can you help

    Skip the iCloud sign in for now.
    Once you reach the home page, go to settings and sign out of FaceTime and Messages.  This should also sign you out of iCloud.
    Go to iCloud in settings and sign in with the correct Apple ID.
    If that does not work
    Skip the iCloud sign in
    Go to Apple ID.apple.com and sign in
    Change your Apple ID to the old one
    Delete iCloud account on your device with the old Apple ID and the same password.
    Go back to the website, change your Apple ID back to the current one. You will receive an email to verify the account. Verify first.
    Sign into iCloud on your device with the correct Apple ID and password

  • Hello, I trying to create a program that would run a household furnace. I can't find a way to set timers for the ignitor,flame sensor and blowers. Any thoughts.

    Hello, I'm trying to create a program that would run a household furnace. I can't find a way to set timers foe the ignitor,flame sensor and blowers. Any thoughts would be greatly appreciated. Thanks, primetime

    In the detailed help for the event structure there is a link to caveats and recommendations for using event structures.  It is a good starting point.
    It is courteous to let the Forum know when your questions are related to a school assignment or homework.  We are glad to help you learn LabVIEW, but do not do your homework for you.
    You have learned the major disadvantage of the sequence structure: It must run to completion before anything else can happen.
    If you are building a state machine (typically a while loop with shift registers enclosing a case structure with one case per state) and having trouble with timing, then think about your requirements. Apparently you have some time delays, but under certain conditions you must terminate a delay/wait and do something else.  One way of doing this is to have a Wait state.  The wait state has a short delay, determined by the minimum time you can delay responding to a changed condition, and a check to see if the required elapsed time has occurred.  If the time has not elapsed, the next state is the Wait state again.  The state machine can repeat any state as often as necessary.  So a 15 second delay could be implemented by going to a Wait state with a one second wait 15 times. Any error or new command will see a response in no more than one second.
    Lynn

  • I'm trying to create an account but it keeps telling me that my age requirement is not right

    I'm trying to create an account but it keeps telling me that my age requirement is not correct

    This forum is for questions about iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store, so unless you're attempting to set up an administrator account in iTunes U, you'll be more likely to get help if you ask in the general iTunes forums.
    Regards.

  • Trying to create a text that is on fire or more like a hot branding iron

    Trying to create a text that is on fire or more like a hot branding iron

    Something like this?
    That was from a project I did a few months ago.  Sounds similar to what you want.  I did that in After Effects.
    Basically all I did was add a glow effect to the text and messed around with the glow parameters.  The black smoke is animated and moves on the actual video and is basically some pre keyed smoke footage that I had.  The smoke was originally gray but black looked cooler.
    I'd say it's pretty close to your hot branding iron thing.

  • Please help me avoid twisting my head off trying to create a video of iphone screenshots that will play on an iphone

    I'm trying to create some job aid videos for a client.
    Some of these are going to be how to do things on their iphones.
    I've used the screencapture facility on my phone to snap a dozen or so screen caps.
    I've moved them to my PC
    I've buit a project (in C8) that is sized 640 x1136 but when I punblish them as video (to you tube) it comes out landscape.
    So I created a version that was 1136 x 640 and rotated all my objects by 90 degrees.
    This works, but if I try working like this my head will screw off.
    There must be an easier way.....
    Can anyone help please.
    Thansk
    Alan

    Pooja
    That will certainly help geting the screen into Captivate.
    But the problem then happens when I try to publish to Video and send it to YouTube.
    When I full screen it it looks like this.
    To fix that I rotated all the objects to -90
    The video looks OK but it means when working on it I have a screen that looks like this
    And I don't want to end up looking like this!

  • I am trying to create a button in flash that will display 4 separate images at the same time when clicked.  I can't get the images to stay on when I take the mouse of the button.  I need the actions script code to make this happen.

    I am trying to create a button in flash that will allow the user to click on the button and 4 separate images show up at the same time.  I can get the images to appear when I click the button but they will not stay on the screen.  I need to know what code I use to make the images stay once the button is clicked, then I need to know exactly where I place that code.  It does not appear to be possible to add the action code to the buttons layer since each time I add a new layer I just get another "up" "over" "down" and "hit" line.
    Thank you in advance
    AP

    It is not clear how you are trying to realize this from your description.  If you are trying to create this within a button symbol it will not work.  Explain your approach and if there is code involved, show what you have so far.

  • Can you calculate multiple text boxes to achieve a total value?  If so how is that done?  I am trying to create a order form where multiple items can be purchased but i would like the values of each item to calculate so I can achieve a total value.

    Can you calculate multiple text boxes to achieve a total value?  If so how is that done?  I am trying to create a order form where multiple items can be purchased but i would like the values of each item to calculate so I can achieve a total value.

    Hi sashby51,
    I've moved your discussion to the PDF Forms forum--the folks who visit this forum regularly should be able to point you in the right direction.
    Best,
    Sara

  • I am creating a form on LiveCycle Designer and I am trying to create a form that has a e-mail submit button.  When the butten is utilized it attaches the form to the e-mail in an plain text .xml format rather than the pdf format.  Is there a quick fix?

    I am creating a form on LiveCycle Designer and I am trying to create a form that has a e-mail submit button.  When the button is utilized it attaches the form to the e-mail in an plain text .xml format rather than the pdf format.  Is there a quick fix?

    Hi,
    You have the choice between xml or pdf, in later versions of designer you can choose with a dropdown on the email button Object palette, the "Submit As";
    In earlier version you had to edit the XML Source and change the format from xml to pdf (or vice-versa);
    Regards
    Bruce

  • Trying to create a service that starts at boot

    People,
    I'm trying to create a service that will start at boot (in single-user mode, actually). I am up and running but I do NOT want to run the service now. I only want to run the service when the machine reboots.
    I've been rummaging around all day trying to figure this out but I'm stuck. I can create a service that runs. I can create an XML file in /var/svc/manifest/site/patch-install.xml that will be read when I boot- because after I boot, I can list the service:
    svcs -a | grep patch
    disabled       18:23:23 svc:/site/patch-install:defaultI have inserted the following in my xml:
    <create_default_instance enabled='true' />and also
    <create_default_instance enabled='false' />but it makes no difference. Anyone have any idea? What is the purpose of create_default_instance? I don't understand; item 9 on http://www.sun.com/bigadmin/content/selfheal/sdev_intro.html seems rather opaque to me.
    Also, what exactly is the purpose of /var/svc/profile/ ? I tried putting some code to enable my xml but it didn't do anything. Just wondering if this might fit into the picture.
    BTW, I do not want the login prompt to appear until my method is complete.
    Thanks.
    -mschwage
    Here fyi is my /var/svc/manifest/site/patch-install.xml file:
    <?xml version="1.0"?>
    <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
    <service_bundle type='manifest' name='Patches:patch-install'>
    <service
            name='site/patch-install'
            type='service'
            version='1'>
            <create_default_instance enabled='false' />
            <single_instance />
            <dependent
                    name='patch-install_single-user'
                    grouping='require_all'
                    restart_on='none'>
                    <service_fmri value='svc:/milestone/single-user' />
            </dependent>
            <exec_method
                    type='method'
                    name='start'
                    exec='/var/tmp/S92delay'
                    timeout_seconds='86400' />
            <exec_method
                    type='method'
                    name='stop'
                    exec=':true'
                    timeout_seconds='0' />
            <property_group name='startd' type='framework'>
                    <propval name='duration' type='astring' value='transient' />
            </property_group>
            <stability value='External' />
            <template>
                    <common_name>
                            <loctext xml:lang='C'>
                            Install patchset upon boot.
                            </loctext>
                    </common_name>
            </template>
    </service>
    </service_bundle>

    Hushpuppy wrote:
    People,
    I'm trying to create a service that will start at boot (in single-user mode, actually). I am up and running but I do NOT want to run the service now. I only want to run the service when the machine reboots.I'd probably create the service now (by importing the manifest manually rather than waiting for the reboot), then set general/enabled in the default instance to be be true with svcprop. That should tell it to start at boot, but not enable it immediately.
    I've been rummaging around all day trying to figure this out but I'm stuck. I can create a service that runs. I can create an XML file in /var/svc/manifest/site/patch-install.xml that will be read when I boot- because after I boot, I can list the service:Yes, that's the default. Or you can load it immediately to create the service now.
    # svccfg import patch-install.xml
    I have inserted the following in my xml:
    <create_default_instance enabled='true' />and also
    <create_default_instance enabled='false' />but it makes no difference. Anyone have any idea? What is the purpose of create_default_instance? I don't understand; item 9 on http://www.sun.com/bigadmin/content/selfheal/sdev_intro.html seems rather opaque to me.There's a difference between a "service" like network/smtp or console-login and an "instance" like network/smtp:sendmail or console-login:default. In most cases, you just want a single "default" instance of your service. The above line sets the default instance 'enabled' property to true or false. When I import your manifest as is, the service comes in as 'disabled'. If I set it to true, it comes in as 'maintenance' (almost certainly because it was enabled, tried to start, and couldn't find the start method on my machine).
    Also, what exactly is the purpose of /var/svc/profile/ ? I tried putting some code to enable my xml but it didn't do anything. Just wondering if this might fit into the picture.'profiles' are loaded exactly once, and they are mainly used to set certain services to enabled or disabled.
    3 of them are loaded if present, platform.xml, generic.xml, and site.xml. The last is not generated by the OS, but left for you to use. But it's usually only useful as a "first boot" type thing. Because if you make changes to it, it will not be reread. This isn't usually a problem because after first boot you're in control of the services. The usual thing is that at first boot the manifests load to create services, then the profiles are loaded to set then enabled or disabled. This isn't possible before that point because there's no service to modify yet.
    BTW, I do not want the login prompt to appear until my method is complete.Any login prompt like a network login, or only the console login prompt? If the latter, then you'll want a dependency so that system-console-login depends on your service. But if your service has a problem at boot time, you'd make it difficult to log in.
    Darren

  • When trying to creat a desktop icon, it does not go to the URL.....instead I get 'script' and not a website......the script has http//etc but I am not directed to the website......I previously had IE 8 (on Vista).....is that the problem...

    Question
    When trying to create a desktop icon, it does not go to the URL.....instead I get 'script' and not a website......the script has http//etc but I am not directed to the website......I previously had IE 8 (on Vista).....is that the problem?I do not have any installed plugins....at least none that I know of.....remember I am a new user......Basically, the desktop icon is not going directly to the Mozilla FF to get me to the web site I need to go to.....FF works when I use the Mozilla FF icon.....just not the icons I create.....THANKS!!! I have also tried reinstalling FF and get the same results.....HELP!!!

    The address beginning with file:/// denotes a saved file (local file). The file may not be present. You can try dragging the site icon of this page on the left edge of the location (Address) bar and release it on the desktop. Please try opening it. If it still shows an error it could be a problem with the system's zone permissions. You can try setting each zone in the Windows Control Panel or IE > '''Internet Options''' > '''Security''' tab to '''Default Level'''.

  • Trying to get into the app store and it asks for my password. The problem is that it is showing an Apple ID I don't use ghosted in. I can't figure out how to use my correct ID.

    Trying to get into the App Store to update some apss. It asks for my password but the problem is that it is showing ghosted an Apple ID I don't use. Can't figure out how to fix it.

    You installed a hacked app, originally from the Mac App Store. It contains the receipt for a different app, downloaded using an account that you don't control. You need to identify and remove the hacked app.
    Important: The app you need to remove is not necessarily the one named in the App Store alert. For example, if the App Store says you need to update "Twitter," the hacked app may be "Angry Birds" or something else entirely. Don't make any assumptions about which app you're looking for. To find it, you have to carry out a systematic search.
    Triple-click anywhere in the line of text below on this page to select it:
    kMDItemAppStoreHasReceipt=1
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    In the Finder, press command-F to open a search window, or select
    File ▹ Find
    from the menu bar. In the search window, select
    Search: This Mac
    from the row of tokens below the toolbar. Below that is a popup menu initially showing Kind. From that menu, select  Other...
    A sheet will drop down. In that sheet, select Raw Query and click OK or press return.
    Now there will be a text box to the right of popup menu. Click in that box and paste (command-V).
    The search window will show all the App Store products you've installed. Compare those search results with the list of your purchases from the App Store. To see the complete list, you may need to unhide hidden purchases. If any apps were download from the App Store using other Apple ID accounts that you control, sign in to the store under each of those ID's and check the purchases.
    At least one of the items listed in the search window is not among your purchases in the App Store. Move each such item to the Trash. You may be prompted for your administrator password. Empty the Trash.
    Log out and log back in. Test.

Maybe you are looking for

  • Java newbie (what's could be wrong with this program?)

    First things first, I just started programming with JAVA recently so please forgive me if it seems stupid. Since I am so relatively new to the language, in order to get a feel for it I started running some simple scripts. I can compile and execute mo

  • Can't find user.js to configure my own session preferences in linux

    I am running Firefox version 17.0.5 ESR on an IGEL UD9 thin terminal and want to know where I need to change the user.js so I can make my own preference modifications. Cheers JASON

  • Shifting colors when opening older version files

    Hello everybody, I'm a begginer with FH and don't know how to work this around, I have several FH files which were saved in FH10. I need to open and export them to SWF. But when I open them with FHMX the colors don't match the originals ones. Any sug

  • Best solution for shared photo album?

    I've haven't dipped much into the Photo ecosystem of iOS (mainly because my original iPad never had a camera, I don't have an iPhone, and on the laptop my workflow doesn't rely on iPhoto).    As such, I'm not sure what the best solutions are for the

  • Traffic light icons in UWL

    Dear Experts, We have a request to show an icon in the workitems depending on the value of an element.The idea is an icon red is the date of that element is overdue, yellow if the date is in a range and green if the date is in another range. As we al