Results 1 to 2 of 2
  1. #1
    jaybeeb is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default Editing Array Problem

    Having an issue with editing details in an array. Basically what my program does is
    1. Adds a Building
    2. Edits a building
    3. Displays a building

    I had Add and Display set up and working fine but now since I have put edit in. I have been having problems. when I was trying to edit I had to initialise my array up beside my variables for it to work and since doing that everytime I add a new Building it just adds that building and then duplicates that one everytime I try and add another. Cant figure out what I am doing wrong - it does edit like this also but the problem it creates needs to be fixed.

    Java Code:
    public class MainRates 
    {
    	
    	public static void Menu()
    	{
    		Scanner input=new Scanner(System.in);
    		
    		int option1;
    		int option2;
    		
    		
    		Industrial indBuild[] = new Industrial[ 5 ];
    		Office offBuild[] = new Office[ 5 ];
    		Residential resBuild[] = new Residential[ 5 ];
    		int counter = 0;
    		int counter1 = 0;
    		int counter2 = 0;
    		
    		int EditReg;
    		String EditOwner;
    		String EditAddress;
    		int EditPhoneNo;
    		double EditSqrMet;
    		String EditIndType;
    		
    		Industrial ind1 = new Industrial("","",0,0.0,""); //where my array is now inititialised
    		
    		
    		
    		
    		
    		
    		{
    		
    			do{
    				System.out.println("\n----------MAIN MENU----------");
    				System.out.println("1. Industrial");
    				System.out.println("2. Office");
    				System.out.println("3. Residential");
    				System.out.println("4. View All Buildings");
    				System.out.println("5. Quit");
    				System.out.println("Enter Option Number: ");
    				
    				option1 = input.nextInt();
    		
    				switch(option1)
    				{
    					case 1:
    					{
    						System.out.println("\n-------INDUSTRIAL MENU-------");
    						System.out.println("1. Add Building");
    						System.out.println("2. Display Buildings");
    						System.out.println("3. Edit Building Details");
    						System.out.println("4. Main Menu");
    						System.out.println("Enter Option Number: ");
    						
    						
    						option2 = input.nextInt();
    						switch(option2)
    						{
    							case 1://add
    							{
    								System.out.println("\n---ADD INDUSTRIAL BUILDING---");
    								//Industrial ind1 = new Industrial("","",0,0.0,"");  where I had my array initialised before I put in my edit
    								System.out.println("Enter Owner: ");
    								ind1.setowner(input.next());
    								System.out.println("Enter Address: ");
    								ind1.setaddress(input.next());
    								System.out.println("Enter Phone Number: ");
    								ind1.setphoneNumber(input.nextInt());
    								System.out.println("Enter Square Metres: ");
    								ind1.setsquareMetres(input.nextDouble());
    								System.out.println("Enter Industry Type: ");
    								ind1.setindustryType(input.next());
    								
    								ind1.setcalculateRate();
    								System.out.println(ind1);
    								
    								counter = counter + 1;
    								indBuild[counter] = ind1;
    								
    								for ( int i = 0; i < indBuild.length; i++ )
    								{
    									
    								}
    								break;
    							}
    							
    							case 2: //display
    							{
    								for ( int i =0; i < indBuild.length; i++)
    								{
    									System.out.println(indBuild[i]);
    								}
    								break;
    							}
    							
    							case 3: //edit
    							{
    								
    							System.out.println( "Please enter the registration number you wish to edit" );
    							EditReg = input.nextInt();
    							System.out.println("Please update name");
    	                        EditOwner = input.next();
    	                        System.out.println("Please update address");
    	                        EditAddress = input.next();
    							System.out.println("Please update phone number");
    	                        EditPhoneNo = input.nextInt();
    		 	            	System.out.println("Please update building size in square metres");
    	                        EditSqrMet = input.nextDouble();
    		 					System.out.println("Please update industry type(light/heavy)");
    	                        EditIndType = input.next();
    							System.out.println("Building Edited");
    
    
    	                        ind1.setregistrationNo(EditReg);
    							ind1.setowner(EditOwner);
    							ind1.setaddress(EditAddress);
    							ind1.setphoneNumber(EditPhoneNo);
    							ind1.setsquareMetres(EditSqrMet);
    							ind1.setindustryType(EditIndType);
    		                           
    		                           
    
    		                    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What array are you talking about? Better to provide more details about your question.

    One thing is that your code is incomplete and I don't think anyone can read your code completely to answer.

Similar Threads

  1. Photo Editing
    By stekun in forum Advanced Java
    Replies: 3
    Last Post: 02-23-2010, 06:11 AM
  2. Help, Editing Items in an array.
    By jaybeeb in forum New To Java
    Replies: 2
    Last Post: 12-09-2008, 10:28 PM
  3. Editing & Testing Java on Mac
    By TheRocket in forum New To Java
    Replies: 7
    Last Post: 11-22-2008, 02:56 PM
  4. JTable editing with Mouse
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 0
    Last Post: 10-11-2008, 09:34 AM
  5. Editing video frames in JMF
    By russ2620 in forum Networking
    Replies: 0
    Last Post: 05-31-2008, 12:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •