HELP --- Modifying a instance of a specific element

Joined
Jan 18, 2009
Messages
2
Reaction score
0
I have an array list holding booking information : customer number, date of booking, guests number and table number. I need to find a way how to edit an instance of a specific element from the array list. That is for example if I have the following bookings in the array list:

Customer Number........Date of Booking.........Guests Number........Table Number
..........002...................02/05/2009..........................4........................6
..........008...................10/05/2009..........................2........................4
..........011...................17/05/2009..........................3........................2

Now let's say I need to change the date of customer 008. How can I do that?

This is what I have managed to do up till now.

import java.io.*;
class NextBooking implements Serializable{

private String cust_num;
private String table_num;
private String date;
private int guests;


//constructor
public NextBooking(String cust_numb, String dateb, String tableb, int guestsb){
cust_num = cust_numb;
date = dateb;
table_num = tableb;
guests = guestsb;

}



public void setCust_Num(String cn){
cust_num = cn;
}

public String getCust_Num(){
return cust_num;
}

public void setTable_Num(String tn){
table_num = tn;
}

public String getTable_Num(){
return table_num;
}



public void setGuests(int g){
guests = g;
}

public int getGuests(){
return guests;
}



public void setDate(String d){
date = d;
}

public String getDate(){
return date;
}

public boolean equals( Object other){
return (getCust_Num().equals( ((NextBooking)other).getCust_Num()));

}

public boolean equals2( Object other){
return (getTable_Num().equals( ((NextBooking)other).getTable_Num()));
}

}




//modifying a booking
public static void modifyBooking(ArrayList<NextBooking>nextListIn){

int pos, spot3= -1;
boolean found = true;
int i;
int comparison2;

Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("\n");

System.out.println("Enter Customer number to be modified or E to exit");
String tempnum = scanner.next();

comparison2 = tempnum.compareTo("E");

do
{
found = true;

spot3 = nextListIn.indexOf(new NextBooking(tempnum,null,null, 0));
if ((spot3 < 0) & (comparison2 != 0))
{
System.out.println("Customer with cust no. "+tempnum+ " does not exist ");

System.out.println("Enter customer number to be modified: ");
tempnum = scanner.next();
comparison2 = tempnum.compareTo("E");
found = false;
}

} while (found != true);

//display item to be modified
for (i=spot3; i < (spot3 + 1); i++) {
System.out.print(nextListIn.get(i).getCust_Num());
System.out.print(" ");
System.out.print(nextListIn.get(i).getDate());
System.out.print(" ");
System.out.print(nextListIn.get(i).getTable_Num());
System.out.print(" ");
System.out.println(nextListIn.get(i).getGuests());
}

System.out.println("What would you like to modify");
System.out.println("1.Date");
System.out.println("2.Guests");
int choice = scanner.nextInt();


}
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top