Clearing, Reset, Removing Array Int.

I'm having a problem with a small class exersize. So far I am able to find the max, min, and average of the grades. As well as have them being entered. My teacher recently wanted us to add a try/catch methods so in case a user enters a negative grade it will catch it.
Ok...so that works. But now when the user enters new grades, and then decides to select the average, it averages some of the grades from the previous entries. Then the max, min cannot be found either.
This program is based on a switch method with cases. Here is the first case. where the grades are entered and the try and catch method is use.
I know, or at least I think I know that I need to clear or reset the array so that new entries can be entered successfully. I looked all over the net. I saw methods such as these:
gradebook.clear()
gradebook.remove()
removeAll()I played around with them for a bit to see what I can get out of it, but nothing is working. These methods are not recognized. Any suggestions guys/gals?
If I cant find a solution I will have the user select case 5 and exit the program and start it over. No biggy.
Thanks !
Mike
public class GradeBookSolution2
  public static void main(String[] args)
    Scanner keyboard = new Scanner(System.in);
    int[] gradebook = new int[11];
    int grade = 0;
    int choice = 0;     
    while(choice != 5)
         Menu();
         choice = keyboard.nextInt();
         switch(choice)
            case 1:
            System.out.println("Please enter 10 class grades followed by any number.");
            try
                for (int i = 0; i < 11; i++)
                     gradebook[i] = grade;                          grade = keyboard.nextInt();
                     if(grade < 0)                     
                          throw new IOException("Exception: YOU CANNOT HAVE A NEGATIVE GRADE");                    
          catch(IOException e)           
        removeAll(); //  <-- This is where and when I want to clear the array?
       System.out.println(e.getMessage());
       //System.out.println("Please exit the program and start over");
break;

The methods you are trying to use are part of the Collections API. arrays do not have these methods you would need to use a Collection like an array that would have these methods... like an ArrayList for example.

Similar Messages

  • How to clear two dimension array and content in JTextArea

    hi all....
    i have a problem to clear the counter in JTextArea..currently i design a program to store all the student details in two dimensian array...when i click "RESET"button..it will only reset the textarea..but can not clear the actual content inside the array..and when i click "Print Button" again..it's supposed nothing to display..but it displayed the thing which i previously entered......
    so i think i need to clear the array...i use append to insert the text...,for this i also can not reset...
    which the code is shown below :
    txtArea.append(msg1);
    the coding for reset area as below :
    txtArea.setText("")
    Anyone can help me?????
    thks...

    How are you trying to reset the array?, you can just creat a new array.
    Noah

  • Resetting / Removing Old URLs From Address Bar When Manually Typing In URLs

    How do you Reset / Remove Old URLs From Address Bar When Manually Typing In URLs. You know, when you start to tpye in www. and about 2000 URLs visted in your life, and past life, appear in a list. It's annoying as all heck, and since it's in alphabetical order it's always throwing in the first one in the list... 1800flowers in my case. Isn't there a way to reset this or something? Or better, to turn it off? I've already tried emptying cache and clearing history. I also removed the .plist files as well. What would happen if I did a reinstall of Safari?

    Hello Jonny Apple Seed
    The way to clear the address bar is to reset Safari, under Safari menu,
    this will also clear,
    "Resetting Safari clears the history, empties the cache, clears the Downloads window, and removes all cookies. It also removes any saved user names and passwords or other AutoFill data and clears Google search entries.
    In addition, any open windows are closed and a new window opens. The new window has a new history for the Back and Forward buttons and the SnapBack buttons". From Safari Help
    A reinstalled Safari will just come to be the same, after a while. Not worth it in my opinion. The address bar will not be completely empty.
    Hth some.
    Eme: )

  • How do I clear (reset) keyframe points in Final Cut Pro?

    I know there is a quick and single click to clear (reset to none) all keyframe points in the viewer window (motion tab).
    I just can't figure it out. I have to right click each and every keyframe point and click delete.
    But there is a way to wipe out all keyframe point with one click.
    Where and how?
    Thank You
    Dan

    Thank you, guys: but I finally found it! Tried for a half hour and read all the help manual stuff first.
    'Help' never mentioned it.
    In motion click the 'basic motion' button to clear (delete) all keyframe points.
    Dan

  • Document 60000030482 cannot be reversed due to clearing reset

    Hello Freinds,
    Has anybody faced this error during FP09. Document 60000030482 cannot be reversed due to clearing reset
    There are some documents which are stuck in clarification list. Please can anyone help me to rectify this error.
    Regards,
    Charvi

    Hello Christiane
    Thanks a lot  for your reply. yes even i read that error log. It says
    "Instead of posting a reversal of the reversal, you have to recreate theoriginal clearing, that is, post a new equivalent for the original
    clearing document."
    Does this mean that i need to post a new payment document or try to
    adjust with the old document.But if i have to do how will i be ableto
    achieve this as the old document is alrady reset and a new document has
    been posted which is not a payment document.
    This error we have faced for the first time. Please guide us how to
    achieve this so that in future we can handle these cases.
    Regards,
    Charvi

  • Clearing history removes passwords

    clearing history removes passwords

    it clears my Facebook log in and password and my banking info when i clear my history in safari it has just started doing this after the last update. these are the only pages that it removes the data from.

  • Someone in Australia was using my email address and when I changed email names to reinstall Itunes it only gives me states from Australia.  Is there some cache on my system that should be cleared or removed?

    Someone in Australia was using my email address and when I changed email names to reinstall Itunes it only gives me states from Australia.  Is there some cache on my system that should be cleared or removed?

    Good luck.    I have been trying to report to Apple Support about a Bogus Email I received today, which said I had made a purchase. Naturally, I was to cancel this bogus purchase by giving out personal details etc to them. 
    The real question is: how did they get my email as someone who had purchased from Itunes?. I cannot believe that ti si coincidence.
    HAVE the Australian Apple IDs [where users have supplied their email addresses] been compromised?
      My report about Spam was the same as reported in 2010, when the reply was: Apple knows all about this.  What has been done about that spam from this address:
    http://www.thepeakdistrictholidaycottage.co.uk/blog/wp-admin/au/apple//index.htm l?securitycenterlogin&hc=1&hm=au%601d72f%2Bj2b2vi%3C265securitycenterlogin&hc=1& hm=au%601d72f%2Bj2b2vi%3C265securitycenterlogin&hc=1&hm=au%601d72f%2Bj2b2vi%3C26 5

  • When i plug in my iPad2, iPhoto comes on not iTunes.  I see iPad in system profiler under USB.  I have reset, removed and re-downloaded iTunes.  When I download iTunes it works until the next time i plug in the iPad2 and then the same thing all over.

    When i plug in my iPad2, iPhoto comes on not iTunes.  I see iPad in system profiler under USB.  I have reset, removed and re-downloaded iTunes.  When I download iTunes it works until the next time i plug in the iPad2 and then the same thing all over.

    Go through this support doc:
    OS: Device not recognised in iTunes
    Windows: http://support.apple.com/kb/TS1538

  • How do i clear a byte array?

    Hi. I'm reading a different chunk of data each time and therefore need to clear the byte array before I go to the next chunk. I've seen
    other ways through a buffer but that is too complicated for me to understand. Can u please tell me if there is a simple method in the API to clear it?
    Thank you!!

    well i thought it was, but i'm using the matcher class to read the data and storing it in a byte array of size 512 and it seems that when i convert it into a string, the previous data is still there if i read something less than 512
    Edited by: angel32013 on Sep 16, 2008 1:08 PM

  • Hi. Bought recently iphone5 from singapore. but the one who sold us the phone has set restriction. now i cannot download any apps from my itunes. I dont know the restriction code so i think i need to reset my phone. does resetting remove the unlock?

    Hi. Bought recently iphone5 from singapore. but the one who sold us the phone has set restriction. now i cannot download any apps from my itunes. I dont know the restriction code so i think i need to reset my phone. does resetting remove the unlock?

    You need to restore it with iTunes or wipe it from the phone itself... Settings > General > Reset > Erase All Content and Settings.  Either of these will create a factory fresh phone, thus removing the restrictions.  Note that ALL user data will be wiped.

  • Does clearing cache remove saved passwords and login?

    Does clearing cache remove saved passwords and login?
    Apparently my FF is slow as a bastard child because of my cache. However, I have loads of user/passwords saved and DO NOT wish to seem them go buh-bye.
    What says you?

    See:
    * [[Backing up your information]]
    * http://kb.mozillazine.org/Profile_backup
    * http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox
    * http://kb.mozillazine.org/Password_Manager#Backing_up_and_restoring_passwords
    * Password Exporter: https://addons.mozilla.org/firefox/addon/2848
    Keeping a large History or a problem with an extension is a more likely cause for a slow response then a problem with the cache.
    See [[Troubleshooting extensions and themes]]

  • Resetting an array

    Hi all.
    I have created a game with my trusted AS3 CIB series! Its a simple game that when the user collects or drops 10 pieces of fruit the game ends. And displays if you won or lost. (Code is below)
    I have created a button (play_btn) that displays when the game finishes. What i am trying to achieve is when you press the button, the game starts again. I have created a listener and a function "startAgain" that resets the fruitLost and fruitCollected variable that i think i should do. But what i am having problems with is resetting the fruitsOnStage array and executing the for loop to create ten items of the fruitsOnStage array. I know the .splice command removes them from the array but what is the easiest way to add them back. Think i'm on the right lines but have no idea how to achieve this!!!
    Any help is greatly appreciated
    Cheers
    import flash.display.MovieClip;
    import flash.events.Event;
    var fruitArray:Array=new Array(Apple,Banana,Strawberry,Orange,Pear);
    var enemy:Array=new Array(blob);
    var fruitsOnStage:Array = new Array();
    play_btn.visible=false;
    var fruitLost:int=0;
    var fruitCollected:int=0;
    function startAgain(e:Event):void
    fruitLost=0;
    fruitCollected=0;
    trace("Hello again");
    stage.addEventListener(Event.ENTER_FRAME, startGame);
    for (var i:int = 0; i <10; i++) {
    var pickFruit=fruitArray[int(Math.random()*fruitArray.length)];
    var fruit:MovieClip = new pickFruit();
    addChild(fruit);
    fruit.x=Math.random()*stage.stageWidth;
    fruit.y=Math.random()*-500;
    fruit.speed=Math.random()*15+5;
    fruitsOnStage.push(fruit);
    stage.addEventListener(Event.ENTER_FRAME, startGame);
    function startGame(e:Event):void
    for (var i:int= 0; i <20; i++) {
    var currentFruit:MovieClip=fruitsOnStage[i];
    currentFruit.y+=currentFruit.speed;
    if (currentFruit.y>stage.stageHeight-currentFruit.height) {
    currentFruit.y=0-currentFruit.width;
    fruitLost++;
    field1_txt.text="You lost "+fruitLost+" pieces of fruit you loser";
    if (currentFruit.hitTestObject(basket_mc)) {
    fruitCollected++;
    removeChild(currentFruit);
    field2_txt.text="You collected "+fruitCollected+" Bravo";
    fruitsOnStage.splice(i,1);
    if (fruitsOnStage.length<=0) {
    field1_txt.text="You won!!!";
    play_btn.visible=true;
    stage.removeEventListener(Event.ENTER_FRAME, startGame);
    play_btn.addEventListener(MouseEvent.CLICK, startAgain);
    if (fruitLost>=10) {
    field1_txt.text="You lost, MUPPET";
    play_btn.visible=true;
    play_btn.addEventListener(MouseEvent.CLICK, startAgain);
    stage.removeEventListener(Event.ENTER_FRAME, startGame);
    basket_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragg);
    function startDragg(e:Event):void
    basket_mc.startDrag();
    basket_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragg);
    function stopDragg(e:Event):void
    basket_mc.stopDrag();

    Another thing - you don't remove previous fruits from stage. This code does it in removeAll() function:
    import flash.display.MovieClip;
    import flash.events.Event;
    var fruitArray:Array = new Array(Apple, Banana, Strawberry, Orange, Pear);
    var enemy:Array = new Array(blob);
    var fruitsOnStage:Array = new Array();
    play_btn.visible = false;
    var fruitLost:int = 0;
    var fruitCollected:int = 0;
    basket_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragg);
    basket_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragg);
    init();
    function init(e:Event = null):void {
         // reset array
         removeAll();
         fruitLost = 0;
         fruitCollected = 0;
         var pickFruit:Class;
         var fruit:MovieClip;
         for (var i:int = 0; i < 10; i++) {
              pickFruit = fruitArray[int(Math.random() * fruitArray.length)];
              fruit = new pickFruit();
              addChild(fruit);
              fruit.x = Math.random() * stage.stageWidth;
              fruit.y = Math.random() * -500;
              fruit.speed = Math.random() * 15 + 5;
              fruitsOnStage.push(fruit);
         stage.addEventListener(Event.ENTER_FRAME, startGame);
    function removeAll():void {
         for each(var mc:MovieClip in fruitsOnStage) {
              removeChild(mc);
              mc = null;
         fruitsOnStage = [];
    function startGame(e:Event):void {
         var currentFruit:MovieClip;
         for (var i:int = 0; i < fruitsOnStage.length; i++) {
              currentFruit = fruitsOnStage[i];
              currentFruit.y += currentFruit.speed;
              if (currentFruit.y > stage.stageHeight - currentFruit.height) {
                   currentFruit.y = 0 - currentFruit.height;
                   fruitLost++;
                   field1_txt.text = "You lost " + fruitLost + " pieces of fruit you loser";
              if (currentFruit.hitTestObject(basket_mc)) {
                   fruitCollected++;
                   removeChild(currentFruit);
                   field2_txt.text = "You collected " + fruitCollected + " Bravo";
                   fruitsOnStage.splice(i, 1);
              if (fruitsOnStage.length == 0) {
                   field1_txt.text="You won!!!";
                   play_btn.visible = true;
                   stage.removeEventListener(Event.ENTER_FRAME, startGame);
                   play_btn.addEventListener(MouseEvent.CLICK, init);
              if (fruitLost >= 10) {
                   field1_txt.text="You lost, MUPPET";
                   play_btn.visible = true;
                   play_btn.addEventListener(MouseEvent.CLICK, init);
                   stage.removeEventListener(Event.ENTER_FRAME, startGame);
    function startDragg(e:Event):void {
         basket_mc.startDrag();
    function stopDragg(e:Event):void {
         basket_mc.stopDrag();

  • How to clear/reset "Installed Software" in Software Center?

    Hello! 
    I've done a big mistake with my application objects! 
    I did have two applications in SCCM 2012 with the same MSI-installation package. The reason for this is because i would like to have one that is deployed as Required (with primary device) and one that is deployed as Available for those without primary device. 
    Then I decided to only keep the available deployment, so i deleted the required appilcation entierly from SCCM. 
    Not so wise because now all the required installations is stucked in Software Center, at the "Installed Software"-tab. And there is noway to remove it.
    So my question is, is there someway to reset or clear the information from software center? Or any other sulotion to my problem? :) 
    Best regards,
    Johan Lång

    It seems like it has removed the entries from the software client automatically now. But I still got problem with the main source of the problem. That I cant push out updates via software center.
    Let me explain the main problem. 
    I had app1 as a MSI, and two application objects (AO). One AO as required and one as available, but the same MSI. 
    After a while I got an integration-application between app1 and another program, as a MSI so i decided to put that as a dependency to app1, but also pushed it out to all users as a required deployment, because it would not install it otherwise, if not the user
    did an uninstall and then a fresh install of app1.
    And for a couple of weeks ago I got my eyes on "automatically update any superseeded applications" while deploying. So i decided to use that with one AO instead of two (required/available). In the same time an update came to app1, lets call it
    app1.1. 
    This was a perfect time to try my new discover and disabled app1 and superseeded it with app1.1 with a available deployment, with a dependency of the integration-application. 
    But the clients could not be updated automatically and when the user tried to update it manually via application catalog it get stucked at the last step "evaluate" before it jumps over to Software Center. And nothing else happen. Until it crasches
    and warn about "it could not be evaluated" in the application catalog. Sometimes it pops up anyway in software center but it wont continue to install, and if you try to manually start the installation it get stucked at the status "Waiting"
    and nothing happens. 
    If I login with another user I can start the installation manually and it works fine.
    If I uninstall the sccm-client and install it back again, the "installed software" will be cleared and I can start the installations manually, so it pops up under "installed software" again. Without any problems. 
    It also worked to install if i removed the dependency of the integration-application.
    So my guess is that something is getting corrupted in the user profile, but I cant find any files regarding sccm in there exept the log file for software center. 
    I hope you understand abit of what i try to explain :) Sorry for bad grammar!
    Regards,
    Johan

  • Clearing a fileglobal array of strings

    I have a fileglobal 2 dimensional array of strings. How does one clear it each time the sequence is called, use a for loop? It used to not be a problem but now it seems to have old data in it all the time.
    thanx,
    jvh
    Solved!
    Go to Solution.

    I don't know if there's a native TS method to empty/reset a 2D array, but much of our code (going back to TS 1.0!) simply uses the "TestStand - Set Property Value (2D String Array).vi" and a sequence context ref to reset a FileGlobals.
    It has worked for us for 10+years...
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Removing array elements

    Hello,
    I am working with an array of...let's say...cars which are assigned id #'s starting at one and adding one each time a new car is assigned.
    Now I want to remove a car from this array but I dont want to leave that array space empty...I need to shift all other array elements one place to the left, assigning new id#'s and spaces to each.
    Ideas?
    Thanks.

    public static void removeCar()
              int current = 0;
              String au = JOptionPane.showInputDialog("Please enter the model of the car to be removed:");
              String ti = JOptionPane.showInputDialog("Please enter the color of the car to be removed:");
              String year = JOptionPane.showInputDialog("Please enter the year of the car  be removed: ");
              int ye = Integer.parseInt(year);
              if (numOfCars == 0)
                   JOptionPane.showMessageDialog(null, "The lot is empty!");
              else
                   if (! remove(current))
                        carlot[current] = carlot[current - 1];
                        JOptionPane.showMessageDialog(null, "Car successfully removed from the lot.");
                   else
                        JOptionPane.showMessageDialog(null, "Car was not found in the lot.");
         }Hmmm...still not doing the trick

Maybe you are looking for

  • Coppying lib (350GB) to an external drive failed

    Since my iMac is becomming full, while my lib grows (350GB) i thought to move the lib to an extrenal drive. This failed twice on diferrent drives,1tb. Story: My lib contains everything (+ masters). First I bought a WD MyBook essential (Mac journaled)

  • Project Systems - Report on WBS and Settlement recievers

    Need help in searching for any PS report wherein I can get list of WBS elements along with the settlement receivers defined in the settlement rule. Or else how can we get such a report.

  • Hard drive suddenly slow

    Hello, My internal hard drive got super slow today, I don't think I have done something what could cause this. I've tested with hdparm -tT /dev/sdb, and the result was at about 100kb/s for cache and disk read, however, for my second hard drive it was

  • Financial Reports and Prompts

    I want to prompt a user for a Month; however, I don't want to show only the Month's data on the report...I want to the Month chose, the Previous Month's data, QTD of that Month and YTD of that Month. What is the best way to accomodate for this? Can I

  • Dear Apple: love Aperture 3, but . . .

    For any professional/semi-pro/amateur photogs out there who just downloaded Aperture 3 and want to love it. I'm a semi-pro photog who's been using Aperture since the beginning. Am very impressed by the layout, the massive improvements(this is like a