Results 1 to 5 of 5
  1. #1
    silverspoon34 is offline Member
    Join Date
    Nov 2009
    Posts
    18
    Rep Power
    0

    Default Editing array data

    Hi new to the forums so Hi to everyone, I hope someone out there can point me in right direction.

    I have a programme creating object orienated items in an array all the questions are asked and then sent to a seperate class but how do i edit it as a whole entry code is below what i want to be able to do for instance is changed all the details but for a user to select the array to change. i have attached part of main program code for normal adding this is when the arrays are empty and also code for the class that object is sent to.

    Java Code:
     if(choice.equals("1"))
           {
           //get book details
           System.out.print("Enter the Taxi Number. ");
           TaxiNo = input.next();
           System.out.print("Enter the Taxi Registration(without spaces) ");
           TaxiReg = input.next();
           System.out.print("Enter the amount of seats available. ");
           TaxiSeats = input.next();
           System.out.print("Is this taxi in service(Y/N) ");
           TaxiServ = input.next();
           System.out.print("Enter the Taxi Location. ");
           TaxiLoco = input.next();
           
           //creat a new object called taxi 1 based on the taxi class
           taxis[taxisInRank] = new Taxi(TaxiNo, TaxiReg, TaxiSeats, TaxiServ, TaxiLoco);
           taxisInRank++;
           System.out.println("Taxi object created");
           System.out.println();
        }
    and the Taxi class code

    Java Code:
    //Taxi class
    
    class Taxi
    {
    private String No;
    private String Reg;
    private String Seats;
    private String Serv;
    private String Loco;
    
    
    //constructor
    Taxi (String n, String r, String s, String ser, String l)
    {
        No = n;
        Reg = r;
        Seats = s;
        Serv = ser;
        Loco = l;
    }
    
    //method to get title and date
    String getNo()
    {
        return No;
    }
    
    String getReg()
    {
        return Reg;
    }
    
    String getSeats()
    {
        return Seats;
    }
    
    String getServ()
    {
        return Serv;
    }
    
    String getLoco()
    {
        return Loco;
    }
    }
    what i am looking to do is if data has been entered which will be in object array 0 then i want to edit the data there as a whole again not just part like TaxiNo

    The user will need to select what taxi will be edited so the selection from user needs to become the array-1

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    10

    Default

    Why don't you create the appropriate "setters" in your Taxi class and then do the user selection in the class that actually holds the array.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    13

    Default

    Java Code:
    Taxi t = taxis[0];
    t.callMethod();
    // or directly
    taxis[0].callMethod();

  4. #4
    silverspoon34 is offline Member
    Join Date
    Nov 2009
    Posts
    18
    Rep Power
    0

    Default re: editing array data

    Ok you lost me not familiar with that method so totally lost. is there a tutorial or someway of seeing how this done?

  5. #5
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    10

Similar Threads

  1. Editing Array Problem
    By jaybeeb in forum New To Java
    Replies: 1
    Last Post: 12-15-2008, 05:15 AM
  2. Help, Editing Items in an array.
    By jaybeeb in forum New To Java
    Replies: 2
    Last Post: 12-09-2008, 09:28 PM
  3. Data array to file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-16-2008, 10:42 AM
  4. add data into an array
    By mispeed in forum New To Java
    Replies: 9
    Last Post: 11-08-2007, 03:53 AM
  5. Add data to an array
    By adlb1300 in forum New To Java
    Replies: 8
    Last Post: 11-05-2007, 02:01 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
  •