Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Deleting Array Records

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    6
    My Mood
    Where
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Deleting Array Records

    Hi, I have a problem that when you delete an array record between some numbers the rest will be deleted.

    For Example

    I'm only going to delete booknum[6] -- then the booknum[7] booknum[8] booknum[9] and so on.. will be deleted

    Any solution how to adjust booknum[7] into booknum[6], booknum[8] into booknum[7] and so on


    System.out.print("Please Enter the Book Number you want to Destroy: ");
    a6=Integer.parseInt(br.readLine());

    if(booknum[a6] != null && booknum[a6] != ""){
    if(bookstatus[a6].equals("Available")){
    System.out.println("Book "+ bookname[a6] + " is Eliminated");
    booknum[a6]=null;
    bookname[a6]=null;
    bookdesc[a6]=null;
    bookstatus[a6]=null;


    Here is the snippet code
     
     
    	do{
    	System.out.println("----");
    	System.out.println("Deleting Books to the Record");
     
     
    	c6=0;
    	System.out.println("Please Choose a Book Below");							
    	System.out.println("Book Number // Book Name // Book Description");
     
    	if(booknum[1] == null)
    {
    	System.out.println("Empty Record");
    	c6++;
    }
            else
    {
    	for (int i6 = 0; i6 < booknum.length; i6++){
    	 if(booknum[i6] != null && booknum[i6] != "")
      {
    		if(bookstatus[i6].equals("Available"))
            {
    		System.out.println(booknum[i6]+" \t\t "+bookname[i6]+" \t\t "+bookdesc[i6]);
    									c6++;
    									}
    									}
    }
     
    		if(c6==0){
    		System.out.println("No Books are Currently Available for Deleting");
    		}else{
    		System.out.print("Please Enter the Book Number you want to Destroy: ");
    		a6=Integer.parseInt(br.readLine());
     
    		if(booknum[a6] != null && booknum[a6] != ""){
    		if(bookstatus[a6].equals("Available")){
    		System.out.println("Book "+ bookname[a6] + " is Eliminated");	
    							booknum[a6]=null;
    								bookname[a6]=null;
    								bookdesc[a6]=null;
    								bookstatus[a6]=null;
    							}
    							}else{
    							System.out.println("Book is not yet available");
    							}
    							}

    Thanks in advance for any help
    Last edited by rainexel; September 26th, 2011 at 11:04 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,323
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: Deleting Array Records

    Why don't you just use an ArrayList? If this is for homework, all I can really say is to run this through a debugger (or at the very least, add some print statements) to get a better idea of what the code is actually doing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    rainexel (September 26th, 2011)

  4. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    6
    My Mood
    Where
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Deleting Array Records

    no it's not a homework, I'm just looking for a help who does have a proper solution and can fix the code for me
    tried some stuff but yet still doesn't work

    By the way I'm using Jcreator. Thanks for the suggestion anyway

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,323
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: Deleting Array Records

    Sounds like a job for an ArrayList.

    Other than that, I'd recommend you split this up- write a method that takes an array and an index as arguments and deletes that index. Then you can post that as an SSCCE if you get stuck.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 2
    Last Post: July 15th, 2011, 02:39 AM
  2. Deleting record from database HELP! :(
    By shando1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 1st, 2011, 11:36 PM
  3. renaming/deleting file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 15
    Last Post: January 14th, 2011, 11:18 PM
  4. Drag & drop MVC: deleting an object
    By Alice in forum Object Oriented Programming
    Replies: 0
    Last Post: December 9th, 2010, 10:09 PM
  5. [SOLVED] Can someone verify if this code for deleting a BST works?
    By scottb80 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 2nd, 2010, 10:19 AM